當前位置: 首頁>>代碼示例>>Java>>正文


Java Collection.getClass方法代碼示例

本文整理匯總了Java中java.util.Collection.getClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Collection.getClass方法的具體用法?Java Collection.getClass怎麽用?Java Collection.getClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Collection的用法示例。


在下文中一共展示了Collection.getClass方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addAll

import java.util.Collection; //導入方法依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:CopyOnWriteArrayList.java

示例2: addAll

import java.util.Collection; //導入方法依賴的package包/類
/**
 * 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;
    synchronized (lock) {
        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;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:CopyOnWriteArrayList.java

示例3: getJdbcType

import java.util.Collection; //導入方法依賴的package包/類
/**
 * 獲取java對象
 * 
 * @param obj
 *            集合
 * @return string java類型
 */
public static String getJdbcType(Collection<?> obj) {
    if (obj == null || obj.isEmpty()) {
        return javaToJdbcTypesMp.get(obj);
    }
    Object next = obj.iterator().next();
    for (Class<?> k : javaToJdbcTypesMp.keySet()) {
        if (k != null && k.isInstance(next)) {
            return javaToJdbcTypesMp.get(k);
        }
    }
    throw new RuntimeException("javaToJdbcTypesMp " + obj.getClass() + " not match jdbcTypes");
}
 
開發者ID:lftao,項目名稱:jkami,代碼行數:20,代碼來源:JdbcTypesUtils.java

示例4: CopyOnWriteArraySet

import java.util.Collection; //導入方法依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:CopyOnWriteArraySet.java

示例5: CopyOnWriteArrayList

import java.util.Collection; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:CopyOnWriteArrayList.java

示例6: testAllDefaultMethodsOverridden

import java.util.Collection; //導入方法依賴的package包/類
@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());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:Wrappers.java

示例7: CopyOnWriteArrayList

import java.util.Collection; //導入方法依賴的package包/類
/**
 * 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();
        // defend against c.toArray (incorrectly) not returning Object[]
        // (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652)
        if (elements.getClass() != Object[].class)
            elements = Arrays.copyOf(elements, elements.length, Object[].class);
    }
    setArray(elements);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:CopyOnWriteArrayList.java

示例8: write

import java.util.Collection; //導入方法依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.out;

    if (object == null) {
        out.writeNull(SerializerFeature.WriteNullListAsEmpty);
        return;
    }

    Type elementType = null;
    if (out.isEnabled(SerializerFeature.WriteClassName)
            || SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName))
    {
        elementType = TypeUtils.getCollectionItemType(fieldType);
    }

    Collection<?> collection = (Collection<?>) object;

    SerialContext context = serializer.context;
    serializer.setContext(context, object, fieldName, 0);

    if (out.isEnabled(SerializerFeature.WriteClassName)) {
        if (HashSet.class == collection.getClass()) {
            out.append("Set");
        } else if (TreeSet.class == collection.getClass()) {
            out.append("TreeSet");
        }
    }

    try {
        int i = 0;
        out.append('[');
        for (Object item : collection) {

            if (i++ != 0) {
                out.append(',');
            }

            if (item == null) {
                out.writeNull();
                continue;
            }

            Class<?> clazz = item.getClass();

            if (clazz == Integer.class) {
                out.writeInt(((Integer) item).intValue());
                continue;
            }

            if (clazz == Long.class) {
                out.writeLong(((Long) item).longValue());

                if (out.isEnabled(SerializerFeature.WriteClassName)) {
                    out.write('L');
                }
                continue;
            }

            ObjectSerializer itemSerializer = serializer.getObjectWriter(clazz);
            if (SerializerFeature.isEnabled(features, SerializerFeature.WriteClassName)
                    && itemSerializer instanceof JavaBeanSerializer) {
                JavaBeanSerializer javaBeanSerializer = (JavaBeanSerializer) itemSerializer;
                javaBeanSerializer.writeNoneASM(serializer, item, i - 1, elementType, features);
            } else {
                itemSerializer.write(serializer, item, i - 1, elementType, features);
            }
        }
        out.append(']');
    } finally {
        serializer.context = context;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:73,代碼來源:CollectionCodec.java

示例9: write

import java.util.Collection; //導入方法依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.out;

    if (object == null) {
        out.writeNull(SerializerFeature.WriteNullListAsEmpty);
        return;
    }

    Type elementType = null;
    if (out.isEnabled(SerializerFeature.WriteClassName)) {
        elementType = TypeUtils.getCollectionItemType(fieldType);
    }

    Collection<?> collection = (Collection<?>) object;

    SerialContext context = serializer.context;
    serializer.setContext(context, object, fieldName, 0);

    if (out.isEnabled(SerializerFeature.WriteClassName)) {
        if (HashSet.class == collection.getClass()) {
            out.append("Set");
        } else if (TreeSet.class == collection.getClass()) {
            out.append("TreeSet");
        }
    }

    try {
        int i = 0;
        out.append('[');
        for (Object item : collection) {

            if (i++ != 0) {
                out.append(',');
            }

            if (item == null) {
                out.writeNull();
                continue;
            }

            Class<?> clazz = item.getClass();

            if (clazz == Integer.class) {
                out.writeInt(((Integer) item).intValue());
                continue;
            }

            if (clazz == Long.class) {
                out.writeLong(((Long) item).longValue());

                if (out.isEnabled(SerializerFeature.WriteClassName)) {
                    out.write('L');
                }
                continue;
            }

            ObjectSerializer itemSerializer = serializer.getObjectWriter(clazz);
            itemSerializer.write(serializer, item, i - 1, elementType, 0);
        }
        out.append(']');
    } finally {
        serializer.context = context;
    }
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:65,代碼來源:CollectionCodec.java

示例10: write

import java.util.Collection; //導入方法依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
    Throwable th;
    SerializeWriter out = serializer.getWriter();
    if (object != null) {
        Type elementType = null;
        if (serializer.isEnabled(SerializerFeature.WriteClassName) && (fieldType instanceof ParameterizedType)) {
            elementType = ((ParameterizedType) fieldType).getActualTypeArguments()[0];
        }
        Collection<?> collection = (Collection) object;
        SerialContext context = serializer.getContext();
        serializer.setContext(context, object, fieldName, 0);
        if (serializer.isEnabled(SerializerFeature.WriteClassName)) {
            if (HashSet.class == collection.getClass()) {
                out.append((CharSequence) "Set");
            } else if (TreeSet.class == collection.getClass()) {
                out.append((CharSequence) "TreeSet");
            }
        }
        out.append('[');
        int i = 0;
        for (Object item : collection) {
            int i2;
            try {
                i2 = i + 1;
                if (i != 0) {
                    out.append(',');
                }
                if (item == null) {
                    out.writeNull();
                    i = i2;
                } else {
                    try {
                        Class<?> clazz = item.getClass();
                        if (clazz == Integer.class) {
                            out.writeInt(((Integer) item).intValue());
                            i = i2;
                        } else if (clazz == Long.class) {
                            out.writeLong(((Long) item).longValue());
                            if (out.isEnabled(SerializerFeature.WriteClassName)) {
                                out.write('L');
                                i = i2;
                            } else {
                                i = i2;
                            }
                        } else {
                            serializer.getObjectWriter(clazz).write(serializer, item, Integer.valueOf(i2 - 1), elementType);
                            i = i2;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                    }
                }
            } catch (Throwable th3) {
                th = th3;
                i2 = i;
            }
        }
        out.append(']');
        serializer.setContext(context);
        return;
    } else if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
        out.write("[]");
        return;
    } else {
        out.writeNull();
        return;
    }
    serializer.setContext(context);
    throw th;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:71,代碼來源:CollectionSerializer.java

示例11: write

import java.util.Collection; //導入方法依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.getWriter();

    if (object == null) {
        if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
            out.write("[]");
        } else {
            out.writeNull();
        }
        return;
    }

    Type elementType = null;
    if (serializer.isEnabled(SerializerFeature.WriteClassName)) {
        if (fieldType instanceof ParameterizedType) {
            ParameterizedType param = (ParameterizedType) fieldType;
            elementType = param.getActualTypeArguments()[0];
        }
    }

    Collection<?> collection = (Collection<?>) object;

    SerialContext context = serializer.getContext();
    serializer.setContext(context, object, fieldName, 0);

    if (serializer.isEnabled(SerializerFeature.WriteClassName)) {
        if (HashSet.class == collection.getClass()) {
            out.append("Set");
        } else if (TreeSet.class == collection.getClass()) {
            out.append("TreeSet");
        }
    }

    try {
        int i = 0;
        out.append('[');
        for (Object item : collection) {

            if (i++ != 0) {
                out.append(',');
            }

            if (item == null) {
                out.writeNull();
                continue;
            }

            Class<?> clazz = item.getClass();

            if (clazz == Integer.class) {
                out.writeInt(((Integer) item).intValue());
                continue;
            }

            if (clazz == Long.class) {
                out.writeLong(((Long) item).longValue());

                if (out.isEnabled(SerializerFeature.WriteClassName)) {
                    out.write('L');
                }
                continue;
            }

            ObjectSerializer itemSerializer = serializer.getObjectWriter(clazz);
            itemSerializer.write(serializer, item, i - 1, elementType, 0);
        }
        out.append(']');
    } finally {
        serializer.setContext(context);
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:72,代碼來源:CollectionSerializer.java


注:本文中的java.util.Collection.getClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。