Java Code Examples for java.util.List#getClass()

The following examples show how to use java.util.List#getClass() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Test(dataProvider="lists")
public void testAccessToSublists(List<Integer> list, boolean modifiable) {
    Class<?> cls = list.getClass();
    for (int i = 0; i < NEST_LIMIT; ++i) {
        list = list.subList(0, 1);
    }

    try {
        list.get(0);
        if (modifiable) {
            list.remove(0);
            list.add(0, 42);
        }
    } catch (StackOverflowError e) {
        fail("failed for " + cls);
    }
}
 
Example 2
private <E> void appendList(List<E> list, DumpMode dumpMode, int depth) {
	Class<?> collectionClass = list.getClass();
	result.append(collectionClass.getName()).append("[");
	if (list.isEmpty()) {
		result.append(EMPTY);
	} else {
		result.append("\n");
		E element;
		for (int i = 0; i < list.size(); i++) {
			element = list.get(i);
			makeIndent(depth + 1);
			result.append(i).append(" => ");
			appendObject(element, getElementDumpMode(element, dumpMode), depth + 1);
			result.append("\n");
		}
		makeIndent(depth);
	}
	result.append("]");
}
 
Example 3
@Test
public void testImmutableList() throws Exception {
    List in = Collections.unmodifiableList(Lists.newArrayList(1, 2));
    Class<? extends List> clazz = in.getClass();

    Output output = new Output(new byte[20],20);
    kryo.writeObject(output, in);

    byte[] bytes = output.toBytes();
    assertNotNull(bytes);

    Input input = new Input(new ByteArrayInputStream(bytes), bytes.length);
    List out = kryo.readObject(input, clazz);

    assertNotNull(out);
    assertEquals(in, out);
}
 
Example 4
Source Project: breeze   File: SpringSpoutTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests the {@link SpringSpout#setFailSignature(String) fail signature} effect
 * on a {@link SpringSpout#setOutputStreamId(String) custom stream ID} with collection fields.
 */
@Test
public void failTransaction() throws Exception {
	List<Object> bean = new ArrayList<>();
	bean.add("dang");
	doReturn(bean).when(applicationContextMock).getBean(bean.getClass());

	SpringSpout subject = new SpringSpout(bean.getClass(), "clone()", "x");
	subject.setFailSignature("clear()");
	subject.setOutputStreamId("universe");

	subject.setApplicationContext(applicationContextMock);
	subject.open(stormConf, contextMock, collectorMock);
	subject.nextTuple();

	ArgumentCaptor<Object> messageIdCaptor = ArgumentCaptor.forClass(Object.class);
	verify(collectorMock).emit(eq("universe"), eq(asList((Object) bean)), messageIdCaptor.capture());

	subject.fail(messageIdCaptor.getValue());
	assertEquals(Collections.emptyList(), bean);
}
 
Example 5
@SuppressWarnings("unchecked")
public ConfigListConvOption(String name, boolean required, String desc,
                            Predicate<List<T>> pred, Function<T, R> convert,
                            Class<T> clazz, List<T> values) {
    super(name, required, desc, pred,
          (Class<List<T>>) values.getClass(), values);
    E.checkNotNull(convert, "convert");
    if (clazz == null && values.size() > 0) {
        clazz = (Class<T>) values.get(0).getClass();
    }
    E.checkArgumentNotNull(clazz, "Element class can't be null");
    this.elemClass = clazz;
    this.converter = convert;
}
 
Example 6
@SuppressWarnings("unchecked")
public ConfigListOption(String name, boolean required, String desc,
                        Predicate<List<T>> pred, Class<T> clazz,
                        List<T> values) {
    super(name, required, desc, pred,
          (Class<List<T>>) values.getClass(), values);
    if (clazz == null && values.size() > 0) {
        clazz = (Class<T>) values.get(0).getClass();
    }
    E.checkArgumentNotNull(clazz, "Element class can't be null");
    this.elemClass = clazz;
}
 
Example 7
Source Project: javageci   File: CompoundParams.java    License: Apache License 2.0 5 votes vote down vote up
private static List<String> assertListOfStrings(List value) {
    for (final var string : value) {
        if (!(string instanceof String)) {
            throw new IllegalArgumentException(value.getClass()
                                                   + " cannot be used in "
                                                   + CompoundParams.class.getSimpleName()
                                                   + " as parameter value as it contains non-String elements.");
        }
    }
    return value;
}
 
Example 8
Source Project: caja   File: ParseTreeNodes.java    License: Apache License 2.0 5 votes vote down vote up
private static String getCtorErrorMessage(
    Constructor<? extends ParseTreeNode> ctor, Object value,
    List<? extends ParseTreeNode> children) {
  return "Error calling ctor " + ctor.toString()
      +" with value = " + value
      +" (" + (value == null ? "" : value.getClass()) + ")"
      +" with children = " + children
      +" (" + (children == null ? "" : children.getClass()) + ")";
}
 
Example 9
Source Project: breeze   File: SpringSpoutTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests the {@link SpringSpout#setAckSignature(String) ack signature} effect
 * with {@link SpringSpout#setScatterOutput(boolean) record chunks}.
 */
@Test
public void ackTransaction() throws Exception {
	TestBean.Data record1 = new TestBean.Data();
	record1.setId(0);
	record1.setMessage("ding");
	TestBean.Data record2 = new TestBean.Data();
	record2.setId(1);
	record2.setMessage("dong");

	List<Object> bean = new ArrayList<>();
	bean.add(record1);
	bean.add(record2);
	doReturn(bean).when(applicationContextMock).getBean(bean.getClass());

	SpringSpout subject = new SpringSpout(bean.getClass(), "toArray()", "g");
	subject.setScatterOutput(true);
	subject.setAckSignature("set(id, message)");

	subject.setApplicationContext(applicationContextMock);
	subject.open(stormConf, contextMock, collectorMock);
	subject.nextTuple();

	ArgumentCaptor<Object> messageIdCaptor = ArgumentCaptor.forClass(Object.class);
	verify(collectorMock).emit(eq("default"), eq(bean.subList(0, 1)), messageIdCaptor.capture());
	verify(collectorMock).emit(eq("default"), eq(bean.subList(1, 2)), messageIdCaptor.capture());
	verifyNoMoreInteractions(collectorMock);

	subject.ack(messageIdCaptor.getAllValues().get(0));
	subject.ack(messageIdCaptor.getAllValues().get(1));
	assertEquals(asList((Object) "ding", "dong"), bean);
}
 
Example 10
@Override
ModelValue protect() {
    final List<ModelNode> list = this.list;
    for (final ModelNode node : list) {
        node.protect();
    }
    return list.getClass() == ArrayList.class ? new ListModelValue(Collections.unmodifiableList(list)) : this;
}
 
Example 11
Source Project: netbeans   File: FolderList.java    License: Apache License 2.0 4 votes vote down vote up
public FileListTransferable(final List<? extends File> data) {
    data.getClass();
    this.data = data;
}
 
Example 12
Source Project: laser   File: ListWritable.java    License: Apache License 2.0 4 votes vote down vote up
public ListWritable(List<Writable> values) {
	listClass = values.getClass();
	valueClass = values.get(0).getClass();
	this.values = values;
}