KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > buffer > TransformedBuffer


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.buffer;
17
18 import org.apache.commons.collections.Buffer;
19 import org.apache.commons.collections.Transformer;
20 import org.apache.commons.collections.collection.TransformedCollection;
21
22 /**
23  * Decorates another <code>Buffer</code> to transform objects that are added.
24  * <p>
25  * The add methods are affected by this class.
26  * Thus objects must be removed or searched for using their transformed form.
27  * For example, if the transformation converts Strings to Integers, you must
28  * use the Integer form to remove objects.
29  * <p>
30  * This class is Serializable from Commons Collections 3.1.
31  *
32  * @since Commons Collections 3.0
33  * @version $Revision: 1.6 $ $Date: 2004/06/03 22:02:13 $
34  *
35  * @author Stephen Colebourne
36  */

37 public class TransformedBuffer extends TransformedCollection implements Buffer {
38
39     /** Serialization version */
40     private static final long serialVersionUID = -7901091318986132033L;
41
42     /**
43      * Factory method to create a transforming buffer.
44      * <p>
45      * If there are any elements already in the buffer being decorated, they
46      * are NOT transformed.
47      *
48      * @param buffer the buffer to decorate, must not be null
49      * @param transformer the transformer to use for conversion, must not be null
50      * @return a new transformed Buffer
51      * @throws IllegalArgumentException if buffer or transformer is null
52      */

53     public static Buffer decorate(Buffer buffer, Transformer transformer) {
54         return new TransformedBuffer(buffer, transformer);
55     }
56     
57     //-----------------------------------------------------------------------
58
/**
59      * Constructor that wraps (not copies).
60      * <p>
61      * If there are any elements already in the buffer being decorated, they
62      * are NOT transformed.
63      *
64      * @param buffer the buffer to decorate, must not be null
65      * @param transformer the transformer to use for conversion, must not be null
66      * @throws IllegalArgumentException if buffer or transformer is null
67      */

68     protected TransformedBuffer(Buffer buffer, Transformer transformer) {
69         super(buffer, transformer);
70     }
71
72     /**
73      * Gets the decorated buffer.
74      *
75      * @return the decorated buffer
76      */

77     protected Buffer getBuffer() {
78         return (Buffer) collection;
79     }
80
81     //-----------------------------------------------------------------------
82
public Object JavaDoc get() {
83         return getBuffer().get();
84     }
85
86     public Object JavaDoc remove() {
87         return getBuffer().remove();
88     }
89
90 }
91
Popular Tags