package io.undertow.util;
import java.util.AbstractCollection;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
public final class extends AbstractCollection<String> implements Deque<String>, List<String>, RandomAccess {
private static final String[] = new String[0];
final HttpString ;
byte ;
Object ;
(final HttpString key) {
this.key = key;
}
public HttpString () {
return key;
}
public int () {
return size;
}
public boolean () {
return size == 0;
}
public void () {
final byte size = this.size;
if (size == 0) return;
clearInternal();
}
private void () {
final Object value = this.value;
if (value instanceof String[]) {
final String[] strings = (String[]) value;
final int len = strings.length;
Arrays.fill(strings, 0, len, null);
} else {
this.value = null;
}
this.size = 0;
}
private int (int idx) {
assert idx >= 0;
assert idx < size;
final int len = ((String[]) value).length;
if (idx > len) {
idx -= len;
}
return idx;
}
public ListIterator<String> () {
return iterator(0, true);
}
public ListIterator<String> (final int index) {
return iterator(index, true);
}
public Iterator<String> () {
return iterator(0, true);
}
public Iterator<String> () {
return iterator(0, false);
}
private ListIterator<String> (final int start, final boolean forwards) {
return new ListIterator<String>() {
int = start;
int = -1;
public boolean () {
return idx < size;
}
public boolean () {
return idx > 0;
}
public String () {
try {
final String next;
if (forwards) {
int idx = this.idx;
next = get(idx);
returned = idx;
this.idx = idx + 1;
return next;
} else {
int idx = this.idx - 1;
next = get(idx);
this.idx = returned = idx;
}
return next;
} catch (IndexOutOfBoundsException e) {
throw new NoSuchElementException();
}
}
public int () {
return idx;
}
public String () {
try {
final String prev;
if (forwards) {
int idx = this.idx - 1;
prev = get(idx);
this.idx = returned = idx;
} else {
int idx = this.idx;
prev = get(idx);
returned = idx;
this.idx = idx + 1;
return prev;
}
return prev;
} catch (IndexOutOfBoundsException e) {
throw new NoSuchElementException();
}
}
public int () {
return idx - 1;
}
public void () {
if (returned == -1) {
throw new IllegalStateException();
}
HeaderValues.this.remove(returned);
returned = -1;
}
public void (final String headerValue) {
if (returned == -1) {
throw new IllegalStateException();
}
HeaderValues.this.set(returned, headerValue);
}
public void (final String headerValue) {
if (returned == -1) {
throw new IllegalStateException();
}
final int idx = this.idx;
HeaderValues.this.add(idx, headerValue);
this.idx = idx + 1;
returned = -1;
}
};
}
public boolean (final String headerValue) {
int size = this.size;
if (headerValue == null || size == Byte.MAX_VALUE) return false;
final Object value = this.value;
if (value instanceof String[]) {
final String[] strings = (String[]) value;
final int len = strings.length;
if (size == len) {
final String[] newStrings = new String[len + 2];
System.arraycopy(strings, 0, newStrings, 1, len);
newStrings[0] = headerValue;
this.value = newStrings;
} else {
System.arraycopy(strings, 0, strings, 1, strings.length - 1);
strings[0] = headerValue;
}
this.size = (byte) (size + 1);
} else {
if (size == 0) {
this.value = headerValue;
this.size = (byte) 1;
} else {
this.value = new String[] { headerValue, (String) value, null, null };
this.size = (byte) 2;
}
}
return true;
}
public boolean (final String headerValue) {
int size = this.size;
if (headerValue == null || size == Byte.MAX_VALUE) return false;
final Object value = this.value;
if (value instanceof String[]) {
offerLastMultiValue(headerValue, size, (String[]) value);
} else {
if (size == 0) {
this.value = headerValue;
this.size = (byte) 1;
} else {
this.value = new String[] { (String) value, headerValue, null, null };
this.size = (byte) 2;
}
}
return true;
}
private void (String headerValue, int size, String[] value) {
final String[] strings = value;
final int len = strings.length;
if (size == len) {
final String[] newStrings = new String[len + 2];
System.arraycopy(strings, 0, newStrings, 0, len);
newStrings[len] = headerValue;
this.value = newStrings;
} else {
strings[size] = headerValue;
}
this.size = (byte) (size + 1);
}
private boolean (int idx, final String headerValue) {
int size = this.size;
if (idx < 0 || idx > size || size == Byte.MAX_VALUE || headerValue == null) return false;
if (idx == 0) return offerFirst(headerValue);
if (idx == size) return offerLast(headerValue);
assert size >= 2;
final Object value = this.value;
assert value instanceof String[];
final String[] strings = (String[]) value;
final int len = strings.length;
if (size == len) {
final int newLen = len + 2;
final String[] newStrings = new String[newLen];
System.arraycopy(value, 0, newStrings, 0, idx);
System.arraycopy(value, idx, newStrings, idx + 1, len - idx);
newStrings[idx] = headerValue;
this.value = newStrings;
} else{
System.arraycopy(value, idx, value, idx + 1, len - idx);
strings[idx] = headerValue;
}
this.size = (byte) (size + 1);
return true;
}
public String () {
final byte size = this.size;
if (size == 0) return null;
final Object value = this.value;
if (value instanceof String) {
this.size = 0;
this.value = null;
return (String) value;
} else {
final String[] strings = (String[]) value;
String ret = strings[0];
System.arraycopy(strings, 1, strings, 0, strings.length - 1);
this.size = (byte) (size - 1);
return ret;
}
}
public String () {
final byte size = this.size;
if (size == 0) return null;
final Object value = this.value;
if (value instanceof String) {
this.size = 0;
this.value = null;
return (String) value;
} else {
final String[] strings = (String[]) value;
int idx = (this.size = (byte) (size - 1));
final int len = strings.length;
if (idx > len) idx -= len;
try {
return strings[idx];
} finally {
strings[idx] = null;
}
}
}
public String (int idx) {
final int size = this.size;
if (idx < 0 || idx >= size) throw new IndexOutOfBoundsException();
if (idx == 0) return removeFirst();
if (idx == size - 1) return removeLast();
assert size > 2;
final String[] value = (String[]) this.value;
final int len = value.length;
String ret = value[idx];
System.arraycopy(value, idx + 1, value, idx, len - idx - 1);
value[len - 1] = null;
this.size = (byte) (size - 1);
return ret;
}
public String (int idx) {
if (idx > size) {
throw new IndexOutOfBoundsException();
}
Object value = this.value;
assert value != null;
if (value instanceof String) {
assert size == 1;
return (String) value;
}
final String[] a = (String[]) value;
return a[index(idx)];
}
public int (final Object o) {
if (o == null || size == 0) return -1;
if (value instanceof String[]) {
final String[] list = (String[]) value;
final int len = list.length;
for (int i = 0; i < size; i ++) {
if ((i > len ? list[i - len] : list[i]).equals(o)) {
return i;
}
}
} else if (o.equals(value)) {
return 0;
}
return -1;
}
public int (final Object o) {
if (o == null || size == 0) return -1;
if (value instanceof String[]) {
final String[] list = (String[]) value;
final int len = list.length;
int idx;
for (int i = size - 1; i >= 0; i --) {
idx = i;
if ((idx > len ? list[idx - len] : list[idx]).equals(o)) {
return i;
}
}
} else if (o.equals(value)) {
return 0;
}
return -1;
}
public String (final int index, final String element) {
if (element == null) throw new IllegalArgumentException();
final byte size = this.size;
if (index < 0 || index >= size) throw new IndexOutOfBoundsException();
final Object value = this.value;
if (size == 1 && value instanceof String) try {
return (String) value;
} finally {
this.value = element;
} else {
final String[] list = (String[]) value;
final int i = index(index);
try {
return list[i];
} finally {
list[i] = element;
}
}
}
public boolean (int index, final Collection<? extends String> c) {
final int size = this.size;
if (index < 0 || index > size) throw new IndexOutOfBoundsException();
final Iterator<? extends String> iterator = c.iterator();
boolean result = false;
while (iterator.hasNext()) {
result |= offer(index, iterator.next());
}
return result;
}
public List<String> (final int fromIndex, final int toIndex) {
if (fromIndex < 0 || toIndex > size || fromIndex > toIndex) throw new IndexOutOfBoundsException();
final int len = toIndex - fromIndex;
final String[] strings = new String[len];
for (int i = 0; i < len; i ++) {
strings[i] = get(i + fromIndex);
}
return Arrays.asList(strings);
}
public String[] () {
int size = this.size;
if (size == 0) {
return NO_STRINGS;
}
final Object v = this.value;
if (v instanceof String) return new String[] { (String) v };
final String[] list = (String[]) v;
final int len = list.length;
final int copyEnd = size;
if (copyEnd < len) {
return Arrays.copyOfRange(list, 0, copyEnd);
} else {
String[] ret = Arrays.copyOfRange(list, 0, copyEnd);
System.arraycopy(list, 0, ret, len, copyEnd - len);
return ret;
}
}
public <T> T[] (final T[] a) {
int size = this.size;
if (size == 0) return a;
final int inLen = a.length;
final Object[] target = inLen < size ? Arrays.copyOfRange(a, inLen, inLen + size) : a;
final Object v = this.value;
if (v instanceof String) {
target[0] = v;
} else {
System.arraycopy(v, 0, target, 0, size);
}
return (T[]) target;
}
public void (final String s) {
if (s == null) return;
if (! offerFirst(s)) throw new IllegalStateException();
}
public void (final String s) {
if (s == null) return;
if (! offerLast(s)) throw new IllegalStateException();
}
public void (final int index, final String s) {
if (s == null) return;
if (! offer(index, s)) throw new IllegalStateException();
}
public boolean (final Object o) {
return indexOf(o) != -1;
}
public String () {
return size == 0 ? null : get(0);
}
public String () {
return size == 0 ? null : get(size - 1);
}
public boolean (final Object o) {
int i = indexOf(o);
return i != -1 && remove(i) != null;
}
public boolean (final Object o) {
int i = lastIndexOf(o);
return i != -1 && remove(i) != null;
}
public boolean (final String s) {
addLast(s);
return true;
}
public void (final String s) {
addFirst(s);
}
public String () {
return removeFirst();
}
public boolean (final String s) {
return offerLast(s);
}
public String () {
return pollFirst();
}
public String () {
return peekFirst();
}
public String () {
return removeFirst();
}
public String () {
final String s = pollFirst();
if (s == null) {
throw new NoSuchElementException();
}
return s;
}
public String () {
final String s = pollLast();
if (s == null) {
throw new NoSuchElementException();
}
return s;
}
public String () {
final String s = peekFirst();
if (s == null) {
throw new NoSuchElementException();
}
return s;
}
public String () {
final String s = peekLast();
if (s == null) {
throw new NoSuchElementException();
}
return s;
}
public String () {
return getFirst();
}
public boolean (Object obj) {
return removeFirstOccurrence(obj);
}
public boolean (final Collection<? extends String> c) {
for (String s : c) {
add(s);
}
return !c.isEmpty();
}
}