java.util.Collection#getClass ( )源码实例Demo

下面列出了java.util.Collection#getClass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pcgen   文件: CollectionInequality.java
@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;
}
 
源代码2 项目: openjdk-8-source   文件: CopyOnWriteArrayList.java
/**
 * 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();
    }
}
 
源代码3 项目: openjdk-8   文件: CopyOnWriteArrayList.java
/**
 * 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();
    }
}
 
源代码4 项目: dragonwell8_jdk   文件: CopyOnWriteArrayList.java
/**
 * 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();
    }
}
 
源代码5 项目: jdk8u-dev-jdk   文件: CopyOnWriteArrayList.java
/**
 * 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();
    }
}
 
/**
 * 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);
}
 
源代码7 项目: jdk8u-jdk   文件: Wrappers.java
@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());
    }
}
 
源代码8 项目: dragonwell8_jdk   文件: Wrappers.java
@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());
    }
}
 
源代码9 项目: IGUANA   文件: QueryHandlerFactory.java
/**
 * 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);
}
 
源代码10 项目: openjdk-jdk9   文件: CopyOnWriteArraySet.java
/**
 * 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);
    }
}
 
源代码11 项目: openjdk-8-source   文件: CopyOnWriteArrayList.java
/**
 * 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);
}
 
源代码12 项目: TencentKona-8   文件: Wrappers.java
@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());
    }
}
 
源代码13 项目: Bytecoder   文件: CopyOnWriteArraySet.java
/**
 * 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);
    }
}
 
源代码14 项目: telekom-workflow-engine   文件: JsonUtil.java
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 ) );
}
 
源代码15 项目: jdk8u-jdk   文件: CopyOnWriteArraySet.java
/**
 * 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);
    }
}
 
源代码16 项目: Java8CN   文件: CopyOnWriteArrayList.java
/**
 * 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);
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: Wrappers.java
@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());
    }
}
 
源代码18 项目: openjdk-8-source   文件: Wrappers.java
@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());
    }
}
 
源代码19 项目: jdk8u-dev-jdk   文件: Wrappers.java
@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());
    }
}
 
源代码20 项目: openjdk-jdk8u   文件: Wrappers.java
@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());
    }
}