Returns the index of first occurrence of value in the queue, or -1 if no such value exists. @param identity If true, == comparison will be used. If false, .equals() comparison will be used. @return An index of first occurrence of value in queue or -1 if no such value exists
(T value, boolean identity)
| 183 | * @param identity If true, == comparison will be used. If false, .equals() comparison will be used. |
| 184 | * @return An index of first occurrence of value in queue or -1 if no such value exists */ |
| 185 | public int indexOf (T value, boolean identity) { |
| 186 | if (size == 0) return -1; |
| 187 | T[] values = this.values; |
| 188 | final int head = this.head, tail = this.tail; |
| 189 | if (identity || value == null) { |
| 190 | if (head < tail) { |
| 191 | for (int i = head; i < tail; i++) |
| 192 | if (values[i] == value) return i - head; |
| 193 | } else { |
| 194 | for (int i = head, n = values.length; i < n; i++) |
| 195 | if (values[i] == value) return i - head; |
| 196 | for (int i = 0; i < tail; i++) |
| 197 | if (values[i] == value) return i + values.length - head; |
| 198 | } |
| 199 | } else { |
| 200 | if (head < tail) { |
| 201 | for (int i = head; i < tail; i++) |
| 202 | if (value.equals(values[i])) return i - head; |
| 203 | } else { |
| 204 | for (int i = head, n = values.length; i < n; i++) |
| 205 | if (value.equals(values[i])) return i - head; |
| 206 | for (int i = 0; i < tail; i++) |
| 207 | if (value.equals(values[i])) return i + values.length - head; |
| 208 | } |
| 209 | } |
| 210 | return -1; |
| 211 | } |
| 212 | |
| 213 | /** Removes the first instance of the specified value in the queue. |
| 214 | * @param identity If true, == comparison will be used. If false, .equals() comparison will be used. |