KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > primitives > adapters > AbstractIntListList


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

17 package org.apache.commons.collections.primitives.adapters;
18
19 import java.util.Collection JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.ListIterator JavaDoc;
23
24 import org.apache.commons.collections.primitives.IntCollection;
25 import org.apache.commons.collections.primitives.IntList;
26
27 /**
28  * @since Commons Primitives 1.0
29  * @version $Revision: 480462 $ $Date: 2006-11-29 00:15:00 -0800 (Wed, 29 Nov 2006) $
30  * @author Rodney Waldhoff
31  */

32 abstract class AbstractIntListList extends AbstractIntCollectionCollection implements List JavaDoc {
33     
34     public void add(int index, Object JavaDoc element) {
35         getIntList().add(index,((Number JavaDoc)element).intValue());
36     }
37
38     public boolean addAll(int index, Collection JavaDoc c) {
39         return getIntList().addAll(index,CollectionIntCollection.wrap(c));
40     }
41
42     public Object JavaDoc get(int index) {
43         return new Integer JavaDoc(getIntList().get(index));
44     }
45
46     public int indexOf(Object JavaDoc element) {
47         return getIntList().indexOf(((Number JavaDoc)element).intValue());
48     }
49
50     public int lastIndexOf(Object JavaDoc element) {
51         return getIntList().lastIndexOf(((Number JavaDoc)element).intValue());
52     }
53
54     /**
55      * {@link IntListIteratorListIterator#wrap wraps} the
56      * {@link org.apache.commons.collections.primitives.IntListIterator IntListIterator}
57      * returned by my underlying
58      * {@link IntList IntList},
59      * if any.
60      */

61     public ListIterator JavaDoc listIterator() {
62         return IntListIteratorListIterator.wrap(getIntList().listIterator());
63     }
64
65     /**
66      * {@link IntListIteratorListIterator#wrap wraps} the
67      * {@link org.apache.commons.collections.primitives.IntListIterator IntListIterator}
68      * returned by my underlying
69      * {@link IntList IntList},
70      * if any.
71      */

72     public ListIterator JavaDoc listIterator(int index) {
73         return IntListIteratorListIterator.wrap(getIntList().listIterator(index));
74     }
75
76     public Object JavaDoc remove(int index) {
77         return new Integer JavaDoc(getIntList().removeElementAt(index));
78     }
79
80     public Object JavaDoc set(int index, Object JavaDoc element) {
81         return new Integer JavaDoc(getIntList().set(index, ((Number JavaDoc)element).intValue() ));
82     }
83
84     public List JavaDoc subList(int fromIndex, int toIndex) {
85         return IntListList.wrap(getIntList().subList(fromIndex,toIndex));
86     }
87
88     public boolean equals(Object JavaDoc obj) {
89         if(obj instanceof List JavaDoc) {
90             List JavaDoc that = (List JavaDoc)obj;
91             if(this == that) {
92                 return true;
93             } else if(this.size() != that.size()) {
94                 return false;
95             } else {
96                 Iterator JavaDoc thisiter = iterator();
97                 Iterator JavaDoc thatiter = that.iterator();
98                 while(thisiter.hasNext()) {
99                     Object JavaDoc thiselt = thisiter.next();
100                     Object JavaDoc thatelt = thatiter.next();
101                     if(null == thiselt ? null != thatelt : !(thiselt.equals(thatelt))) {
102                         return false;
103                     }
104                 }
105                 return true;
106             }
107         } else {
108             return false;
109         }
110     }
111
112     public int hashCode() {
113         return getIntList().hashCode();
114     }
115     
116     protected final IntCollection getIntCollection() {
117         return getIntList();
118     }
119     
120     protected abstract IntList getIntList();
121         
122
123 }
124
Popular Tags