author | joehw |
Wed, 18 Oct 2017 13:25:49 -0700 | |
changeset 47359 | e1a6c0168741 |
parent 47216 | 71c04702a3d5 |
child 48409 | 5ab69533994b |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
44797
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
3 |
* @LastModified: Oct 2017 |
12005 | 4 |
*/ |
5 |
/* |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
12005 | 12 |
* |
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
* |
|
15 |
* Unless required by applicable law or agreed to in writing, software |
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
* See the License for the specific language governing permissions and |
|
19 |
* limitations under the License. |
|
20 |
*/ |
|
21 |
||
22 |
package com.sun.org.apache.xerces.internal.impl.xs.util; |
|
23 |
||
24 |
import com.sun.org.apache.xerces.internal.xs.ShortList; |
|
25 |
import com.sun.org.apache.xerces.internal.xs.XSException; |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
26 |
import java.util.AbstractList; |
12005 | 27 |
|
28 |
/** |
|
29 |
* Containts a list of Object's. |
|
30 |
* |
|
31 |
* @xerces.internal |
|
32 |
* |
|
33 |
* @author Sandy Gao, IBM |
|
34 |
* |
|
35 |
*/ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
36 |
public final class ShortListImpl extends AbstractList<Short> implements ShortList { |
12005 | 37 |
|
38 |
/** |
|
39 |
* An immutable empty list. |
|
40 |
*/ |
|
41 |
public static final ShortListImpl EMPTY_LIST = new ShortListImpl(new short[0], 0); |
|
42 |
||
43 |
// The array to hold all data |
|
44 |
private final short[] fArray; |
|
45 |
// Number of elements in this list |
|
46 |
private final int fLength; |
|
47 |
||
48 |
/** |
|
49 |
* Construct an XSObjectList implementation |
|
50 |
* |
|
51 |
* @param array the data array |
|
52 |
* @param length the number of elements |
|
53 |
*/ |
|
54 |
public ShortListImpl(short[] array, int length) { |
|
55 |
fArray = array; |
|
56 |
fLength = length; |
|
57 |
} |
|
58 |
||
59 |
/** |
|
60 |
* The number of <code>Objects</code> in the list. The range of valid |
|
61 |
* child node indices is 0 to <code>length-1</code> inclusive. |
|
62 |
*/ |
|
63 |
public int getLength() { |
|
64 |
return fLength; |
|
65 |
} |
|
66 |
||
67 |
/** |
|
68 |
* Checks if the <code>unsigned short</code> <code>item</code> is a |
|
69 |
* member of this list. |
|
70 |
* @param item <code>unsigned short</code> whose presence in this list |
|
71 |
* is to be tested. |
|
72 |
* @return True if this list contains the <code>unsigned short</code> |
|
73 |
* <code>item</code>. |
|
74 |
*/ |
|
75 |
public boolean contains(short item) { |
|
76 |
for (int i = 0; i < fLength; i++) { |
|
77 |
if (fArray[i] == item) { |
|
78 |
return true; |
|
79 |
} |
|
80 |
} |
|
81 |
return false; |
|
82 |
} |
|
83 |
||
84 |
public short item(int index) throws XSException { |
|
85 |
if (index < 0 || index >= fLength) { |
|
86 |
throw new XSException(XSException.INDEX_SIZE_ERR, null); |
|
87 |
} |
|
88 |
return fArray[index]; |
|
89 |
} |
|
90 |
||
91 |
public boolean equals(Object obj) { |
|
92 |
if (obj == null || !(obj instanceof ShortList)) { |
|
93 |
return false; |
|
94 |
} |
|
95 |
ShortList rhs = (ShortList)obj; |
|
96 |
||
97 |
if (fLength != rhs.getLength()) { |
|
98 |
return false; |
|
99 |
} |
|
100 |
for (int i = 0;i < fLength; ++i) { |
|
101 |
if (fArray[i] != rhs.item(i)) { |
|
102 |
return false; |
|
103 |
} |
|
104 |
} |
|
105 |
return true; |
|
106 |
} |
|
107 |
||
108 |
/* |
|
109 |
* List methods |
|
110 |
*/ |
|
111 |
||
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
112 |
public Short get(int index) { |
12005 | 113 |
if (index >= 0 && index < fLength) { |
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
44797
diff
changeset
|
114 |
return fArray[index]; |
12005 | 115 |
} |
116 |
throw new IndexOutOfBoundsException("Index: " + index); |
|
117 |
} |
|
118 |
||
119 |
public int size() { |
|
120 |
return getLength(); |
|
121 |
} |
|
122 |
||
123 |
} // class ShortListImpl |