public boolean addAll(Collection collection) { return addAll(size, collection); }
public E set(int i, E o) { if (!updated) copyArray(); E old = elements[i]; elements[i] = o; return old; }
public boolean add(E o) { if (size == elements.length) { increaseSize(elements.length * 2); } elements[size++] = o; return true; }
public void testFastList1() { FastList list = new FastList(3); list.add("One"); list.add("Two"); list.add("Three"); list.add("Five"); list.add(1, "Four"); String[] zz1 = {"One", "Four", "Two", "Three", "Five"}; int i = 0; for (Object o : list) { if (!zz1[i++].equals(o)) throw new AssertionError("problem with list!"); } list.remove(2); String[] zz2 = {"One", "Four", "Three", "Five"}; i = 0; for (Object o : list) { if (!zz2[i++].equals(o)) throw new AssertionError("problem with list!"); } }
public boolean contains(Object o) { return indexOf(o) != -1; }
public Object[] toArray() { return toArray(new Object[size]); }
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof List)) return false; ListIterator e1 = listIterator(); ListIterator e2 = ((List) o).listIterator(); while (e1.hasNext() && e2.hasNext()) { Object o1 = e1.next(); Object o2 = e2.next(); if (!(o1 == null ? o2 == null : o1.equals(o2))) return false; } return !(e1.hasNext() || e2.hasNext()); }
public boolean addAll(int i, Collection<? extends E> collection) { int offset = collection.size(); ensureCapacity(offset + size); if (i != 0) { // copy forward all elements that the insertion is occuring before for (int c = i; c != (i + offset); c++) { elements[c + offset + 1] = elements[c]; } } int c = size == 0 ? -1 : 0; for (E o : collection) { elements[offset + c++] = o; } size += offset; return true; }
public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) { Object[] template = new Object[values.length]; for (int i = 0; i < values.length; i++) { template[i] = values[i].getValue(ctx, elCtx, variableFactory); } return new FastList(template); }
public void testAddAllFastList() throws Exception { FastList fl1 = new FastList(1); fl1.add("value1"); fl1.add("value2"); assertEquals(2, fl1.size()); FastList fl2 = new FastList(1); fl2.add("value3"); fl2.add("value4"); // the addAll results in a list of 2 instead of 4 that was expected fl1.addAll(fl2); assertEquals(4, fl1.size()); }
public boolean contains(Object o) { return indexOf(o) != -1; }
public Object[] toArray() { return toArray(new Object[size]); }
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof List)) return false; ListIterator e1 = listIterator(); ListIterator e2 = ((List) o).listIterator(); while (e1.hasNext() && e2.hasNext()) { Object o1 = e1.next(); Object o2 = e2.next(); if (!(o1 == null ? o2 == null : o1.equals(o2))) return false; } return !(e1.hasNext() || e2.hasNext()); }
public boolean addAll(int i, Collection<? extends E> collection) { int offset = collection.size(); ensureCapacity(offset + size); if (i != 0) { // copy forward all elements that the insertion is occuring before for (int c = i; c != (i + offset); c++) { elements[c + offset + 1] = elements[c]; } } int c = size == 0 ? -1 : 0; for (E o : collection) { elements[offset + c++] = o; } size += offset; return true; }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver("$"); ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory)); List list; if (constraintEx != null) { Object x = dataEx.getValue(ctx, thisValue, factory); if (!(x instanceof Collection)) throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName())); list = new FastList(((Collection) x).size()); for (Object o : (Collection) x) { itemR.value = o; if ((Boolean) constraintEx.getValue(ctx, thisValue, itemFactory)) { list.add(subEx.getValue(o, thisValue, itemFactory)); } } } else { Object x = dataEx.getValue(ctx, thisValue, factory); if (!(x instanceof Collection)) throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName())); list = new FastList(((Collection) x).size()); for (Object o : (Collection) x) { list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory)); } } return list; }
public static void testJavaList() { FastList list; for (int i = 0; i < COUNT; i++) { list = new FastList(10); list.add("Foo244"); list.add("Bar"); list.add("Foo244"); list.add("Bar"); list.add("Foo244"); list.add("Bar"); list.add("Foo244"); list.add("Bar"); list.add("Foo244"); list.add("Bar"); assert "Foo244".equals(list.get(0)) && "Bar".equals(list.get(1)) && list.size() == 10; } } }
public void add(int i, E o) { if (size == elements.length) { increaseSize(elements.length * 2); } for (int c = size; c != i; c--) { elements[c] = elements[c - 1]; } elements[i] = o; size++; }
public boolean addAll(Collection collection) { return addAll(size, collection); }