Java Code Examples for java.util.Collections.checkedList()

The following are Jave code examples for showing how to use checkedList() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: DOMXMLSignature.java   View Source Code Vote up 6 votes
/**
 * Creates a <code>DOMXMLSignature</code> from the specified components.
 *
 * @param si the <code>SignedInfo</code>
 * @param ki the <code>KeyInfo</code>, or <code>null</code> if not specified
 * @param objs a list of <code>XMLObject</code>s or <code>null</code>
 *  if not specified. The list is copied to protect against subsequent
 *  modification.
 * @param id an optional id (specify <code>null</code> to omit)
 * @param signatureValueId an optional id (specify <code>null</code> to
 *  omit)
 * @throws NullPointerException if <code>si</code> is <code>null</code>
 */
public DOMXMLSignature(SignedInfo si, KeyInfo ki,
                       List<? extends XMLObject> objs,
                       String id, String signatureValueId)
{
    if (si == null) {
        throw new NullPointerException("signedInfo cannot be null");
    }
    this.si = si;
    this.id = id;
    this.sv = new DOMSignatureValue(signatureValueId);
    List<XMLObject> tempList =
        Collections.checkedList(new ArrayList<XMLObject>(),
                                XMLObject.class);
    if (objs != null) {
        tempList.addAll(objs);
    }
    this.objects = Collections.unmodifiableList(tempList);
    this.ki = ki;
}
 
Example 2
Project: openjdk-jdk10   File: SubList.java   View Source Code Vote up 6 votes
/**
 * Lists that don't allow resizing, but allow setting values
 */
@DataProvider
public static Object[][] unresizable() {
    final List<Integer> c1 = Arrays.asList(42);
    final List<Integer> c9 = Arrays.asList(40, 41, 42, 43, 44, 45, -1,
            Integer.MIN_VALUE, 1000500);

    Object[][] l1 = unsettable();
    Object[][] l2 = {
        {c1, 0, 1},
        {c1.subList(0, 1), 0, 1},
        {Collections.checkedList(c1, Integer.class), 0, 1},
        {Collections.synchronizedList(c1), 0, 1},
        {c9, 0, 4},
        {c9, 4, 6},
        {c9.subList(1, 8), 1, 4},
        {c9.subList(1, 8), 0, 7},
        {Collections.checkedList(c9, Integer.class), 3, 6},
        {Collections.synchronizedList(c9), 3, 5},
    };
    Object[][] res = Arrays.copyOf(l1, l1.length + l2.length);
    System.arraycopy(l2, 0, res, l1.length, l2.length);
    return res;
}
 
Example 3
Project: openjdk-jdk10   File: XPathFilter2ParameterSpec.java   View Source Code Vote up 5 votes
/**
 * Creates an <code>XPathFilter2ParameterSpec</code>.
 *
 * @param xPathList a list of one or more {@link XPathType} objects. The
 *    list is defensively copied to protect against subsequent modification.
 * @throws ClassCastException if <code>xPathList</code> contains any
 *    entries that are not of type {@link XPathType}
 * @throws IllegalArgumentException if <code>xPathList</code> is empty
 * @throws NullPointerException if <code>xPathList</code> is
 *    <code>null</code>
 */
public XPathFilter2ParameterSpec(List<XPathType> xPathList) {
    if (xPathList == null) {
        throw new NullPointerException("xPathList cannot be null");
    }
    List<XPathType> tempList =
        Collections.checkedList(new ArrayList<XPathType>(),
                                XPathType.class);
    tempList.addAll(xPathList);
    if (tempList.isEmpty()) {
        throw new IllegalArgumentException("xPathList cannot be empty");
    }
    this.xPathList = Collections.unmodifiableList(tempList);
}
 
Example 4
Project: openjdk-jdk10   File: SubList.java   View Source Code Vote up 5 votes
/**
 * Lists that allow any modifications: resizing and setting values
 */
@DataProvider
public static Object[][] modifiable() {
    final List<Integer> c1 = Arrays.asList(42);
    final List<Integer> c9 = Arrays.asList(40, 41, 42, 43, 44, 45, -1,
            Integer.MIN_VALUE, 1000500);

    return new Object[][] {
        {new ArrayList<>(c1), 0, 1},
        {new LinkedList<>(c1), 0, 1},
        {new Vector<>(c1), 0, 1},
        {new ArrayList<>(c1).subList(0, 1), 0, 1},
        {new LinkedList<>(c1).subList(0, 1), 0, 1},
        {new Vector<>(c1).subList(0, 1), 0, 1},
        {Collections.checkedList(new ArrayList<>(c1), Integer.class), 0, 1},
        {Collections.checkedList(new LinkedList<>(c1), Integer.class), 0, 1},
        {Collections.checkedList(new Vector<>(c1), Integer.class), 0, 1},
        {Collections.synchronizedList(new ArrayList<>(c1)), 0, 1},
        {Collections.synchronizedList(new LinkedList<>(c1)), 0, 1},
        {Collections.synchronizedList(new Vector<>(c1)), 0, 1},

        {new ArrayList<>(c9), 2, 5},
        {new LinkedList<>(c9), 2, 5},
        {new Vector<>(c9), 2, 5},
        {new ArrayList<>(c9).subList(1, 8), 1, 4},
        {new LinkedList<>(c9).subList(1, 8), 1, 4},
        {new Vector<>(c9).subList(1, 8), 1, 4},
        {Collections.checkedList(new ArrayList<>(c9), Integer.class), 2, 5},
        {Collections.checkedList(new LinkedList<>(c9), Integer.class), 2, 5},
        {Collections.checkedList(new Vector<>(c9), Integer.class), 2, 5},
        {Collections.synchronizedList(new ArrayList<>(c9)), 2, 5},
        {Collections.synchronizedList(new LinkedList<>(c9)), 2, 5},
        {Collections.synchronizedList(new Vector<>(c9)), 2, 5},
    };
}
 
Example 5
Project: openjdk-jdk10   File: NestedSubList.java   View Source Code Vote up 5 votes
@DataProvider
public static Object[][] lists() {
    final boolean MODIFIABLE = true;
    final boolean NON_MODIFIABLE = false;
    List<Integer> c = Arrays.asList(42);

    return new Object[][] {
        {c, NON_MODIFIABLE},
        {new ArrayList<>(c), MODIFIABLE},
        {new LinkedList<>(c), MODIFIABLE},
        {new MyList(), NON_MODIFIABLE},
        {new Vector<>(c), MODIFIABLE},
        {Collections.singletonList(42), NON_MODIFIABLE},
        {Collections.checkedList(c, Integer.class), NON_MODIFIABLE},
        {Collections.checkedList(new ArrayList<>(c), Integer.class), MODIFIABLE},
        {Collections.checkedList(new LinkedList<>(c), Integer.class), MODIFIABLE},
        {Collections.checkedList(new Vector<>(c), Integer.class), MODIFIABLE},
        {Collections.synchronizedList(c), NON_MODIFIABLE},
        {Collections.synchronizedList(new ArrayList<>(c)), MODIFIABLE},
        {Collections.synchronizedList(new LinkedList<>(c)), MODIFIABLE},
        {Collections.synchronizedList(new Vector<>(c)), MODIFIABLE},
        {Collections.unmodifiableList(c), NON_MODIFIABLE},
        {Collections.unmodifiableList(new ArrayList<>(c)), NON_MODIFIABLE},
        {Collections.unmodifiableList(new LinkedList<>(c)), NON_MODIFIABLE},
        {Collections.unmodifiableList(new Vector<>(c)), NON_MODIFIABLE},
    };
}
 
Example 6
Project: firebase-admin-java   File: SyncPointTest.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
private static List<TestEvent> testEvents(List<? extends Event> events) {
  return Collections.checkedList((List) events, TestEvent.class);
}
 
Example 7
Project: lams   File: AttachmentList.java   View Source Code Vote up 4 votes
public AttachmentList(final int initialCapacity, final Class<T> valueClass) {
    delegate = Collections.checkedList(new ArrayList<T>(initialCapacity), valueClass);
    this.valueClass = valueClass;
}
 
Example 8
Project: lams   File: AttachmentList.java   View Source Code Vote up 4 votes
public AttachmentList(final Class<T> valueClass) {
    delegate = Collections.checkedList(new ArrayList<T>(), valueClass);
    this.valueClass = valueClass;
}
 
Example 9
Project: lams   File: AttachmentList.java   View Source Code Vote up 4 votes
public AttachmentList(final Collection<? extends T> c, final Class<T> valueClass) {
    delegate = Collections.checkedList(new ArrayList<T>(c.size()), valueClass);
    delegate.addAll(c);
    this.valueClass = valueClass;
}
 
Example 10
Project: jdk8u-jdk   File: java_util_Collections_CheckedList.java   View Source Code Vote up 4 votes
protected List<String> getObject() {
    List<String> list = Collections.singletonList("string");
    return Collections.checkedList(list, String.class);
}
 
Example 11
Project: jdk8u-jdk   File: java_util_Collections_CheckedList.java   View Source Code Vote up 4 votes
protected List<String> getAnotherObject() {
    List<String> list = Collections.emptyList();
    return Collections.checkedList(list, String.class);
}
 
Example 12
Project: jdk8u-jdk   File: java_util_Collections_CheckedRandomAccessList.java   View Source Code Vote up 4 votes
protected List<String> getObject() {
    List<String> list = new ArrayList<String>();
    list.add("string");
    return Collections.checkedList(list, String.class);
}
 
Example 13
Project: jdk8u-jdk   File: java_util_Collections_CheckedRandomAccessList.java   View Source Code Vote up 4 votes
protected List<String> getAnotherObject() {
    List<String> list = new ArrayList<String>();
    return Collections.checkedList(list, String.class);
}
 
Example 14
Project: openjdk-jdk10   File: ExcC14NParameterSpec.java   View Source Code Vote up 3 votes
/**
 * Creates a <code>ExcC14NParameterSpec</code> with the specified list
 * of prefixes. The list is copied to protect against subsequent
 * modification.
 *
 * @param prefixList the inclusive namespace prefix list. Each entry in
 *    the list is a <code>String</code> that represents a namespace prefix.
 * @throws NullPointerException if <code>prefixList</code> is
 *    <code>null</code>
 * @throws ClassCastException if any of the entries in the list are not
 *    of type <code>String</code>
 */
public ExcC14NParameterSpec(List<String> prefixList) {
    if (prefixList == null) {
        throw new NullPointerException("prefixList cannot be null");
    }
    List<String> tempList = Collections.checkedList(new ArrayList<>(),
                                                    String.class);
    tempList.addAll(prefixList);
    this.prefixList = Collections.unmodifiableList(tempList);
}