Java Code Examples for java.util.Collection#getClass()
The following examples show how to use
java.util.Collection#getClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyOnWriteArrayList.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Appends all of the elements in the specified collection to the end * of this list, in the order that they are returned by the specified * collection's iterator. * * @param c collection containing elements to be added to this list * @return {@code true} if this list changed as a result of the call * @throws NullPointerException if the specified collection is null * @see #add(Object) */ public boolean addAll(Collection<? extends E> c) { Object[] cs = (c.getClass() == CopyOnWriteArrayList.class) ? ((CopyOnWriteArrayList<?>)c).getArray() : c.toArray(); if (cs.length == 0) return false; final ReentrantLock lock = this.lock; lock.lock(); try { Object[] elements = getArray(); int len = elements.length; if (len == 0 && cs.getClass() == Object[].class) setArray(cs); else { Object[] newElements = Arrays.copyOf(elements, len + cs.length); System.arraycopy(cs, 0, newElements, len, cs.length); setArray(newElements); } return true; } finally { lock.unlock(); } }
Example 2
Source File: CopyOnWriteArrayList.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Appends all of the elements in the specified collection to the end * of this list, in the order that they are returned by the specified * collection's iterator. * * @param c collection containing elements to be added to this list * @return {@code true} if this list changed as a result of the call * @throws NullPointerException if the specified collection is null * @see #add(Object) */ public boolean addAll(Collection<? extends E> c) { Object[] cs = (c.getClass() == CopyOnWriteArrayList.class) ? ((CopyOnWriteArrayList<?>)c).getArray() : c.toArray(); if (cs.length == 0) return false; final ReentrantLock lock = this.lock; lock.lock(); try { Object[] elements = getArray(); int len = elements.length; if (len == 0 && cs.getClass() == Object[].class) setArray(cs); else { Object[] newElements = Arrays.copyOf(elements, len + cs.length); System.arraycopy(cs, 0, newElements, len, cs.length); setArray(newElements); } return true; } finally { lock.unlock(); } }
Example 3
Source File: CopyOnWriteArrayList.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Appends all of the elements in the specified collection to the end * of this list, in the order that they are returned by the specified * collection's iterator. * * @param c collection containing elements to be added to this list * @return {@code true} if this list changed as a result of the call * @throws NullPointerException if the specified collection is null * @see #add(Object) */ public boolean addAll(Collection<? extends E> c) { Object[] cs = (c.getClass() == CopyOnWriteArrayList.class) ? ((CopyOnWriteArrayList<?>)c).getArray() : c.toArray(); if (cs.length == 0) return false; final ReentrantLock lock = this.lock; lock.lock(); try { Object[] elements = getArray(); int len = elements.length; if (len == 0 && cs.getClass() == Object[].class) setArray(cs); else { Object[] newElements = Arrays.copyOf(elements, len + cs.length); System.arraycopy(cs, 0, newElements, len, cs.length); setArray(newElements); } return true; } finally { lock.unlock(); } }
Example 4
Source File: CollectionInequality.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
@Override public String testInequality(Collection<?> s1, Collection<?> s2, InequalityTester t, String location) { if (s1.size() != s2.size()) { return "@CI=" + location + ": Inequality in Set Size: " + s1 + " " + s2; } if (s1.equals(s2)) { return null; } Collection<Object> l1 = new ArrayList<>(s1); Collection<Object> l2 = new ArrayList<>(s2); l1.removeAll(l2); if (l1.isEmpty()) { return null; } l2.removeAll(new ArrayList<Object>(s1)); return "@CI=" + location + ": " + s1.getClass() + " Inequality between: " + l1 + " " + l2; }
Example 5
Source File: CopyOnWriteArrayList.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Appends all of the elements in the specified collection to the end * of this list, in the order that they are returned by the specified * collection's iterator. * * @param c collection containing elements to be added to this list * @return {@code true} if this list changed as a result of the call * @throws NullPointerException if the specified collection is null * @see #add(Object) */ public boolean addAll(Collection<? extends E> c) { Object[] cs = (c.getClass() == CopyOnWriteArrayList.class) ? ((CopyOnWriteArrayList<?>)c).getArray() : c.toArray(); if (cs.length == 0) return false; final ReentrantLock lock = this.lock; lock.lock(); try { Object[] elements = getArray(); int len = elements.length; if (len == 0 && cs.getClass() == Object[].class) setArray(cs); else { Object[] newElements = Arrays.copyOf(elements, len + cs.length); System.arraycopy(cs, 0, newElements, len, cs.length); setArray(newElements); } return true; } finally { lock.unlock(); } }
Example 6
Source File: Wrappers.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "collections") public static void testAllDefaultMethodsOverridden(Collection c) throws NoSuchMethodException { Class cls = c.getClass(); for (Method m: defaultMethods) { Method m2 = cls.getMethod(m.getName(), m.getParameterTypes()); // default had been override assertFalse(m2.isDefault(), cls.getCanonicalName()); } }
Example 7
Source File: Wrappers.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "collections") public static void testAllDefaultMethodsOverridden(Collection c) throws NoSuchMethodException { Class cls = c.getClass(); for (Method m: defaultMethods) { Method m2 = cls.getMethod(m.getName(), m.getParameterTypes()); // default had been override assertFalse(m2.isDefault(), cls.getCanonicalName()); } }
Example 8
Source File: Wrappers.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "collections") public static void testAllDefaultMethodsOverridden(Collection c) throws NoSuchMethodException { Class cls = c.getClass(); for (Method m: defaultMethods) { Method m2 = cls.getMethod(m.getName(), m.getParameterTypes()); // default had been override assertFalse(m2.isDefault(), cls.getCanonicalName()); } }
Example 9
Source File: Wrappers.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "collections") public static void testAllDefaultMethodsOverridden(Collection c) throws NoSuchMethodException { Class cls = c.getClass(); for (Method m: defaultMethods) { Method m2 = cls.getMethod(m.getName(), m.getParameterTypes()); // default had been override assertFalse(m2.isDefault(), cls.getCanonicalName()); } }
Example 10
Source File: Wrappers.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "collections") public static void testAllDefaultMethodsOverridden(Collection c) throws NoSuchMethodException { Class cls = c.getClass(); for (Method m: defaultMethods) { Method m2 = cls.getMethod(m.getName(), m.getParameterTypes()); // default had been override assertFalse(m2.isDefault(), cls.getCanonicalName()); } }
Example 11
Source File: CopyOnWriteArrayList.java From Java8CN with Apache License 2.0 | 5 votes |
/** * Creates a list containing the elements of the specified * collection, in the order they are returned by the collection's * iterator. * * @param c the collection of initially held elements * @throws NullPointerException if the specified collection is null */ public CopyOnWriteArrayList(Collection<? extends E> c) { Object[] elements; if (c.getClass() == CopyOnWriteArrayList.class) elements = ((CopyOnWriteArrayList<?>)c).getArray(); else { elements = c.toArray(); // c.toArray might (incorrectly) not return Object[] (see 6260652) if (elements.getClass() != Object[].class) elements = Arrays.copyOf(elements, elements.length, Object[].class); } setArray(elements); }
Example 12
Source File: CopyOnWriteArraySet.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a set containing all of the elements of the specified * collection. * * @param c the collection of elements to initially contain * @throws NullPointerException if the specified collection is null */ public CopyOnWriteArraySet(Collection<? extends E> c) { if (c.getClass() == CopyOnWriteArraySet.class) { @SuppressWarnings("unchecked") CopyOnWriteArraySet<E> cc = (CopyOnWriteArraySet<E>)c; al = new CopyOnWriteArrayList<E>(cc.al); } else { al = new CopyOnWriteArrayList<E>(); al.addAllAbsent(c); } }
Example 13
Source File: JsonUtil.java From telekom-workflow-engine with MIT License | 5 votes |
public static String serializeCollection( Collection<?> object, boolean serializeType, boolean serializeElementType ){ if( object == null ){ return null; } Class<?> type = object.getClass(); return gson.toJson( convertCollection( object, type, serializeType, serializeElementType ) ); }
Example 14
Source File: CopyOnWriteArraySet.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Creates a set containing all of the elements of the specified * collection. * * @param c the collection of elements to initially contain * @throws NullPointerException if the specified collection is null */ public CopyOnWriteArraySet(Collection<? extends E> c) { if (c.getClass() == CopyOnWriteArraySet.class) { @SuppressWarnings("unchecked") CopyOnWriteArraySet<E> cc = (CopyOnWriteArraySet<E>)c; al = new CopyOnWriteArrayList<E>(cc.al); } else { al = new CopyOnWriteArrayList<E>(); al.addAllAbsent(c); } }
Example 15
Source File: CopyOnWriteArrayList.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Creates a list containing the elements of the specified * collection, in the order they are returned by the collection's * iterator. * * @param c the collection of initially held elements * @throws NullPointerException if the specified collection is null */ public CopyOnWriteArrayList(Collection<? extends E> c) { Object[] elements; if (c.getClass() == CopyOnWriteArrayList.class) elements = ((CopyOnWriteArrayList<?>)c).getArray(); else { elements = c.toArray(); // c.toArray might (incorrectly) not return Object[] (see 6260652) if (elements.getClass() != Object[].class) elements = Arrays.copyOf(elements, elements.length, Object[].class); } setArray(elements); }
Example 16
Source File: CopyOnWriteArraySet.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Creates a set containing all of the elements of the specified * collection. * * @param c the collection of elements to initially contain * @throws NullPointerException if the specified collection is null */ public CopyOnWriteArraySet(Collection<? extends E> c) { if (c.getClass() == CopyOnWriteArraySet.class) { @SuppressWarnings("unchecked") CopyOnWriteArraySet<E> cc = (CopyOnWriteArraySet<E>)c; al = new CopyOnWriteArrayList<E>(cc.al); } else { al = new CopyOnWriteArrayList<E>(); al.addAllAbsent(c); } }
Example 17
Source File: QueryHandlerFactory.java From IGUANA with GNU Affero General Public License v3.0 | 5 votes |
/** * This will create a QueryHandler which first argument is a Collection of Workers. * The other arguments have to be of the specified classes * * * @param className The class name of the QueryHandler * @param constructorArgs2 The constructor arguments * @param constructorClasses2 The classes of the constructor arguments * @param workers the List of all workers which queries should be generated * @return the QueryHandler */ public QueryHandler createWorkerBasedQueryHandler(String className, Object[] constructorArgs2, Class<?>[] constructorClasses2, Collection<Worker> workers) { Object[] constructorArgs = new Object[1+constructorArgs2.length]; Class<?>[] constructorClasses = new Class<?>[1+constructorClasses2.length]; constructorArgs[0] = workers; constructorClasses[0] = workers.getClass(); for(int i=1;i<constructorArgs.length;i++) { constructorArgs[i] = constructorArgs2[i-1]; constructorClasses[i] = constructorClasses2[i-1]; } return create(className, constructorArgs, constructorClasses); }
Example 18
Source File: Wrappers.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "collections") public static void testAllDefaultMethodsOverridden(Collection c) throws NoSuchMethodException { Class cls = c.getClass(); for (Method m: defaultMethods) { Method m2 = cls.getMethod(m.getName(), m.getParameterTypes()); // default had been override assertFalse(m2.isDefault(), cls.getCanonicalName()); } }
Example 19
Source File: Wrappers.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "collections") public static void testAllDefaultMethodsOverridden(Collection c) throws NoSuchMethodException { Class cls = c.getClass(); for (Method m: defaultMethods) { Method m2 = cls.getMethod(m.getName(), m.getParameterTypes()); // default had been override assertFalse(m2.isDefault(), cls.getCanonicalName()); } }
Example 20
Source File: CopyOnWriteArrayList.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Creates a list containing the elements of the specified * collection, in the order they are returned by the collection's * iterator. * * @param c the collection of initially held elements * @throws NullPointerException if the specified collection is null */ public CopyOnWriteArrayList(Collection<? extends E> c) { Object[] elements; if (c.getClass() == CopyOnWriteArrayList.class) elements = ((CopyOnWriteArrayList<?>)c).getArray(); else { elements = c.toArray(); // c.toArray might (incorrectly) not return Object[] (see 6260652) if (elements.getClass() != Object[].class) elements = Arrays.copyOf(elements, elements.length, Object[].class); } setArray(elements); }