本文整理汇总了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();
}
}
示例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;
}
}
示例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");
}
示例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);
}
}
示例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);
}
示例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());
}
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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);
}
}