From ec0cc4348cf71d872b796d0733fb64fc576ef5df Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 16 Jul 2013 00:45:09 +0200 Subject: Renamed ImmutableList to LombokImmutableList, to reduce our ImmutableList coming up in autocomplete dialogs when guava's was intended. --- src/utils/lombok/core/ImmutableList.java | 188 ------------------------- src/utils/lombok/core/JavaIdentifiers.java | 2 +- src/utils/lombok/core/LombokImmutableList.java | 188 +++++++++++++++++++++++++ 3 files changed, 189 insertions(+), 189 deletions(-) delete mode 100644 src/utils/lombok/core/ImmutableList.java create mode 100644 src/utils/lombok/core/LombokImmutableList.java (limited to 'src/utils/lombok') diff --git a/src/utils/lombok/core/ImmutableList.java b/src/utils/lombok/core/ImmutableList.java deleted file mode 100644 index 8b478dbc..00000000 --- a/src/utils/lombok/core/ImmutableList.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (C) 2013 The Project Lombok Authors. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package lombok.core; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -public final class ImmutableList implements Iterable { - private Object[] content; - private static final ImmutableList EMPTY = new ImmutableList(new Object[0]); - - @SuppressWarnings("unchecked") - public static ImmutableList of() { - return (ImmutableList) EMPTY; - } - - public static ImmutableList of(T a) { - return new ImmutableList(new Object[] {a}); - } - - public static ImmutableList of(T a, T b) { - return new ImmutableList(new Object[] {a, b}); - } - - public static ImmutableList of(T a, T b, T c) { - return new ImmutableList(new Object[] {a, b, c}); - } - - public static ImmutableList of(T a, T b, T c, T d) { - return new ImmutableList(new Object[] {a, b, c, d}); - } - - public static ImmutableList of(T a, T b, T c, T d, T e) { - return new ImmutableList(new Object[] {a, b, c, d, e}); - } - - public static ImmutableList of(T a, T b, T c, T d, T e, T f, T... g) { - Object[] rest = g == null ? new Object[] {null} : g; - Object[] val = new Object[rest.length + 6]; - System.arraycopy(rest, 0, val, 6, rest.length); - val[0] = a; - val[1] = b; - val[2] = c; - val[3] = d; - val[4] = e; - val[5] = f; - return new ImmutableList(val); - } - - public static ImmutableList copyOf(Collection list) { - return new ImmutableList(list.toArray()); - } - - public static ImmutableList copyOf(Iterable iterable) { - List list = new ArrayList(); - for (T o : iterable) list.add(o); - return copyOf(list); - } - - private ImmutableList(Object[] content) { - this.content = content; - } - - public ImmutableList replaceElementAt(int idx, T newValue) { - Object[] newContent = content.clone(); - newContent[idx] = newValue; - return new ImmutableList(newContent); - } - - public ImmutableList append(T newValue) { - int len = content.length; - Object[] newContent = new Object[len + 1]; - System.arraycopy(content, 0, newContent, 0, len); - newContent[len] = newValue; - return new ImmutableList(newContent); - } - - public ImmutableList prepend(T newValue) { - int len = content.length; - Object[] newContent = new Object[len + 1]; - System.arraycopy(content, 0, newContent, 1, len); - newContent[0] = newValue; - return new ImmutableList(newContent); - } - - public int indexOf(T val) { - int len = content.length; - if (val == null) { - for (int i = 0; i < len; i++) if (content[i] == null) return i; - return -1; - } - - for (int i = 0; i < len; i++) if (val.equals(content[i])) return i; - return -1; - } - - public ImmutableList removeElement(T val) { - int idx = indexOf(val); - return idx == -1 ? this : removeElementAt(idx); - } - - public ImmutableList removeElementAt(int idx) { - int len = content.length; - Object[] newContent = new Object[len - 1]; - if (idx > 0) System.arraycopy(content, 0, newContent, 0, idx); - if (idx < len - 1) System.arraycopy(content, idx + 1, newContent, idx, len - idx - 1); - return new ImmutableList(newContent); - } - - public boolean isEmpty() { - return content.length == 0; - } - - public int size() { - return content.length; - } - - @SuppressWarnings("unchecked") - public T get(int idx) { - return (T) content[idx]; - } - - public boolean contains(T in) { - if (in == null) { - for (Object e : content) if (e == null) return true; - return false; - } - - for (Object e : content) if (in.equals(e)) return true; - return false; - } - - public Iterator iterator() { - return new Iterator() { - private int idx = 0; - @Override public boolean hasNext() { - return idx < content.length; - } - - @SuppressWarnings("unchecked") - @Override public T next() { - if (idx < content.length) return (T) content[idx++]; - throw new NoSuchElementException(); - } - - @Override public void remove() { - throw new UnsupportedOperationException("List is immutable"); - } - }; - } - - @Override public String toString() { - return Arrays.toString(content); - } - - @Override public boolean equals(Object obj) { - if (!(obj instanceof ImmutableList)) return false; - if (obj == this) return true; - return Arrays.equals(content, ((ImmutableList) obj).content); - } - - @Override public int hashCode() { - return Arrays.hashCode(content); - } -} diff --git a/src/utils/lombok/core/JavaIdentifiers.java b/src/utils/lombok/core/JavaIdentifiers.java index dfec8815..cbe90eed 100644 --- a/src/utils/lombok/core/JavaIdentifiers.java +++ b/src/utils/lombok/core/JavaIdentifiers.java @@ -27,7 +27,7 @@ package lombok.core; public class JavaIdentifiers { private JavaIdentifiers() {} - private static final ImmutableList KEYWORDS = ImmutableList.of( + private static final LombokImmutableList KEYWORDS = LombokImmutableList.of( "public", "private", "protected", "default", "switch", "case", "for", "do", "goto", "const", "strictfp", "while", "if", "else", diff --git a/src/utils/lombok/core/LombokImmutableList.java b/src/utils/lombok/core/LombokImmutableList.java new file mode 100644 index 00000000..e0e1136c --- /dev/null +++ b/src/utils/lombok/core/LombokImmutableList.java @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2013 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +public final class LombokImmutableList implements Iterable { + private Object[] content; + private static final LombokImmutableList EMPTY = new LombokImmutableList(new Object[0]); + + @SuppressWarnings("unchecked") + public static LombokImmutableList of() { + return (LombokImmutableList) EMPTY; + } + + public static LombokImmutableList of(T a) { + return new LombokImmutableList(new Object[] {a}); + } + + public static LombokImmutableList of(T a, T b) { + return new LombokImmutableList(new Object[] {a, b}); + } + + public static LombokImmutableList of(T a, T b, T c) { + return new LombokImmutableList(new Object[] {a, b, c}); + } + + public static LombokImmutableList of(T a, T b, T c, T d) { + return new LombokImmutableList(new Object[] {a, b, c, d}); + } + + public static LombokImmutableList of(T a, T b, T c, T d, T e) { + return new LombokImmutableList(new Object[] {a, b, c, d, e}); + } + + public static LombokImmutableList of(T a, T b, T c, T d, T e, T f, T... g) { + Object[] rest = g == null ? new Object[] {null} : g; + Object[] val = new Object[rest.length + 6]; + System.arraycopy(rest, 0, val, 6, rest.length); + val[0] = a; + val[1] = b; + val[2] = c; + val[3] = d; + val[4] = e; + val[5] = f; + return new LombokImmutableList(val); + } + + public static LombokImmutableList copyOf(Collection list) { + return new LombokImmutableList(list.toArray()); + } + + public static LombokImmutableList copyOf(Iterable iterable) { + List list = new ArrayList(); + for (T o : iterable) list.add(o); + return copyOf(list); + } + + private LombokImmutableList(Object[] content) { + this.content = content; + } + + public LombokImmutableList replaceElementAt(int idx, T newValue) { + Object[] newContent = content.clone(); + newContent[idx] = newValue; + return new LombokImmutableList(newContent); + } + + public LombokImmutableList append(T newValue) { + int len = content.length; + Object[] newContent = new Object[len + 1]; + System.arraycopy(content, 0, newContent, 0, len); + newContent[len] = newValue; + return new LombokImmutableList(newContent); + } + + public LombokImmutableList prepend(T newValue) { + int len = content.length; + Object[] newContent = new Object[len + 1]; + System.arraycopy(content, 0, newContent, 1, len); + newContent[0] = newValue; + return new LombokImmutableList(newContent); + } + + public int indexOf(T val) { + int len = content.length; + if (val == null) { + for (int i = 0; i < len; i++) if (content[i] == null) return i; + return -1; + } + + for (int i = 0; i < len; i++) if (val.equals(content[i])) return i; + return -1; + } + + public LombokImmutableList removeElement(T val) { + int idx = indexOf(val); + return idx == -1 ? this : removeElementAt(idx); + } + + public LombokImmutableList removeElementAt(int idx) { + int len = content.length; + Object[] newContent = new Object[len - 1]; + if (idx > 0) System.arraycopy(content, 0, newContent, 0, idx); + if (idx < len - 1) System.arraycopy(content, idx + 1, newContent, idx, len - idx - 1); + return new LombokImmutableList(newContent); + } + + public boolean isEmpty() { + return content.length == 0; + } + + public int size() { + return content.length; + } + + @SuppressWarnings("unchecked") + public T get(int idx) { + return (T) content[idx]; + } + + public boolean contains(T in) { + if (in == null) { + for (Object e : content) if (e == null) return true; + return false; + } + + for (Object e : content) if (in.equals(e)) return true; + return false; + } + + public Iterator iterator() { + return new Iterator() { + private int idx = 0; + @Override public boolean hasNext() { + return idx < content.length; + } + + @SuppressWarnings("unchecked") + @Override public T next() { + if (idx < content.length) return (T) content[idx++]; + throw new NoSuchElementException(); + } + + @Override public void remove() { + throw new UnsupportedOperationException("List is immutable"); + } + }; + } + + @Override public String toString() { + return Arrays.toString(content); + } + + @Override public boolean equals(Object obj) { + if (!(obj instanceof LombokImmutableList)) return false; + if (obj == this) return true; + return Arrays.equals(content, ((LombokImmutableList) obj).content); + } + + @Override public int hashCode() { + return Arrays.hashCode(content); + } +} -- cgit