KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > adapter > SortedSetToLongSortedSetAdapter


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2003 Søren Bak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package bak.pcj.adapter;
20
21 import bak.pcj.LongIterator;
22 import bak.pcj.set.LongSortedSet;
23 import bak.pcj.set.AbstractLongSet;
24 import bak.pcj.adapter.IteratorToLongIteratorAdapter;
25
26 import java.util.SortedSet JavaDoc;
27
28 /**
29  * This class represents adaptions of Java Collections Framework
30  * sets to primitive sets of long values.
31  * The adapter is implemented as a wrapper around the set.
32  * Thus, changes to the underlying set are reflected by this
33  * set and vice versa.
34  *
35  * <p>
36  * Adapters from JCF collections to primitive collections will
37  * fail if the JCF collection contains <tt>null</tt> values or
38  * values of the wrong class. However, adapters are not fast
39  * failing in the case that the underlying collection should
40  * contain illegal values. To implement fast failure would require
41  * every operation to check every element of the underlying
42  * collection before doing anything. Instead validation methods
43  * are provided. They can be called using the assertion facility
44  * in the client code:
45  * <pre>
46  * SortedSetToLongSortedSetAdapter s;
47  * ...
48  * <b>assert</b> s.validate();
49  * </pre>
50  * or by letting the adapter throw an exception on illegal values:
51  * <pre>
52  * SortedSetToLongSortedSetAdapter s;
53  * ...
54  * s.evalidate(); // Throws an exception on illegal values
55  * </pre>
56  * Either way, validation must be invoked directly by the client
57  * code.
58  *
59  * @author S&oslash;ren Bak
60  * @version 1.0 20-08-2003 23:16
61  * @since 1.2
62  */

63 public class SortedSetToLongSortedSetAdapter extends SetToLongSetAdapter implements LongSortedSet {
64
65     /**
66      * Creates a new adaption to a set of long
67      * values.
68      *
69      * @param set
70      * the underlying set. This set must
71      * consist of values of class
72      * {@link Long Long}. Otherwise a
73      * {@link ClassCastException ClassCastException}
74      * will be thrown by some methods.
75      *
76      * @throws NullPointerException
77      * if <tt>set</tt> is <tt>null</tt>.
78      */

79     public SortedSetToLongSortedSetAdapter(SortedSet set) {
80         super(set);
81     }
82
83     /**
84      * Creates a new adaption to a set of long
85      * values. The set to adapt is optionally validated.
86      *
87      * @param set
88      * the underlying set. This set must
89      * consist of values of class
90      * {@link Long Long}. Otherwise a
91      * {@link ClassCastException ClassCastException}
92      * will be thrown by some methods.
93      *
94      * @param validate
95      * indicates whether <tt>set</tt> should
96      * be checked for illegal values.
97      *
98      * @throws NullPointerException
99      * if <tt>set</tt> is <tt>null</tt>.
100      *
101      * @throws IllegalStateException
102      * if <tt>validate</tt> is <tt>true</tt> and
103      * <tt>set</tt> contains a <tt>null</tt> value
104      * or a value that is not of class
105      * {@link Long Long}.
106      */

107     public SortedSetToLongSortedSetAdapter(SortedSet set, boolean validate) {
108         super(set, validate);
109     }
110
111     public long first()
112     { return ((Long JavaDoc)(((SortedSet)set).first())).longValue(); }
113
114     public LongSortedSet headSet(long to)
115     { return new SortedSetToLongSortedSetAdapter(((SortedSet)set).headSet(new Long JavaDoc(to))); }
116
117     public long last()
118     { return ((Long JavaDoc)(((SortedSet)set).last())).longValue(); }
119
120     public LongSortedSet subSet(long from, long to)
121     { return new SortedSetToLongSortedSetAdapter(((SortedSet)set).subSet(new Long JavaDoc(from), new Long JavaDoc(to))); }
122
123     public LongSortedSet tailSet(long from)
124     { return new SortedSetToLongSortedSetAdapter(((SortedSet)set).tailSet(new Long JavaDoc(from))); }
125
126 }
Popular Tags