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

The following examples show how to use java.util.Collections#checkedList() . 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 check out the related API usage on the sidebar.
Example 1
/**
 * 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 2
/**
 * Creates a new {@code AttachmentList}.
 *
 * @param c initial contents of the list. Cannot be {@code null}
 * @param valueClass the type of element the list is permitted to hold
 */
public AttachmentList(final Collection<? extends E> c, final Class<E> valueClass) {
    delegate = Collections.checkedList(new ArrayList<>(), valueClass);
    delegate.addAll(c);
    this.valueClass = valueClass;
    mutex = this;
}
 
Example 3
@Test
public void testCsvUnmarshal() throws Exception {
    final String request = "PROGRAMMING,Camel in Action,en,Claus Ibsen,Jon Anstey,Dec-2010,49.99\n" +
        "PROGRAMMING,Apache Camel Developer's Cookbook,en,Scott Cranton,Jakub Korab,Dec-2013,49.99\n";

    @SuppressWarnings("unchecked")
    final List<BookModel> response = Collections.checkedList(template.requestBody("direct:unmarshal", request, List.class), BookModel.class);

    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM-yyyy");

    BookModel book1 = new BookModel();
    book1.setCategory("PROGRAMMING");
    book1.setTitle("Camel in Action");
    book1.setTitleLanguage("en");
    book1.setAuthor1("Claus Ibsen");
    book1.setAuthor2("Jon Anstey");
    book1.setPublishDate(simpleDateFormat.parse("Dec-2010"));
    book1.setPrice(BigDecimal.valueOf(49.99));

    BookModel book2 = new BookModel();
    book2.setCategory("PROGRAMMING");
    book2.setTitle("Apache Camel Developer's Cookbook");
    book2.setTitleLanguage("en");
    book2.setAuthor1("Scott Cranton");
    book2.setAuthor2("Jakub Korab");
    book2.setPublishDate(simpleDateFormat.parse("Dec-2013"));
    book2.setPrice(BigDecimal.valueOf(49.99));

    BookModel response1 = response.get(0);
    assertEquals(book1, response1);

    BookModel response2 = response.get(1);
    assertEquals(book2, response2);
}
 
Example 4
protected List<String> getObject() {
    List<String> list = new ArrayList<String>();
    list.add("string");
    return Collections.checkedList(list, String.class);
}
 
Example 5
Source Project: quarkus-http   File: AttachmentList.java    License: Apache License 2.0 4 votes vote down vote up
public AttachmentList(final Class<T> valueClass) {
    delegate = Collections.checkedList(new ArrayList<T>(), valueClass);
    this.valueClass = valueClass;
}
 
Example 6
Source Project: quarkus-http   File: AttachmentList.java    License: Apache License 2.0 4 votes vote down vote up
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 7
protected List<String> getObject() {
    List<String> list = new ArrayList<String>();
    list.add("string");
    return Collections.checkedList(list, String.class);
}
 
Example 8
protected List<String> getObject() {
    List<String> list = new ArrayList<String>();
    list.add("string");
    return Collections.checkedList(list, String.class);
}
 
Example 9
protected List<String> getAnotherObject() {
    List<String> list = Collections.emptyList();
    return Collections.checkedList(list, String.class);
}
 
Example 10
PojoWithObjectCollectionFields fill()
{
    LinkedList<String> ll = new LinkedList<String>();
    ll.add("zero");
    HashMap<String, Boolean> empty = newMap();

    TreeSet<String> ts = new TreeSet<String>();
    ts.add("two");

    EnumSet<Size> es = EnumSet.allOf(Size.class);

    emptySet = Collections.emptySet();
    emptyList = Collections.emptyList();
    singletonSet = Collections.singleton("three");
    singletonList = Collections.singletonList("four");
    setFromMap = Collections.newSetFromMap(empty);
    copiesList = Collections.nCopies(1, "five");

    unmodifiableCollection = Collections
            .unmodifiableCollection(Collections.emptyList()); // no
    // equals
    // impl
    unmodifiableSet = Collections.unmodifiableSet(Collections
            .emptySet());
    unmodifiableSortedSet = Collections.unmodifiableSortedSet(ts);
    unmodifiableList = Collections.unmodifiableList(ll);
    unmodifiableRandomAccessList = Collections
            .unmodifiableList(newList("six"));

    assertTrue(unmodifiableRandomAccessList.getClass().getName()
            .endsWith("RandomAccessList"));

    synchronizedCollection = Collections
            .synchronizedCollection(Collections.emptyList()); // no
    // equals
    // impl
    synchronizedSet = Collections.synchronizedSet(es);
    synchronizedSortedSet = Collections.synchronizedSortedSet(ts);
    synchronizedList = Collections.synchronizedList(ll);
    synchronizedRandomAccessList = Collections
            .synchronizedList(newList("seven"));

    assertTrue(synchronizedRandomAccessList.getClass().getName()
            .endsWith("RandomAccessList"));

    checkedCollection = Collections.checkedCollection(newList("eight"),
            String.class); // no equals impl
    checkedSet = Collections.checkedSet(es, Size.class);
    checkedSortedSet = Collections.checkedSortedSet(ts, String.class);
    checkedList = Collections.checkedList(ll, String.class);
    checkedRandomAccessList = Collections.checkedList(newList("nine"),
            String.class);

    assertTrue(checkedRandomAccessList.getClass().getName()
            .endsWith("RandomAccessList"));

    return this;
}
 
Example 11
@Override
public List<X509Certificate> getSigningCertificateChain() throws SigningCertChainException, UnexpectedJCAException
{
    ensureInitialized();
    try
    {
        List<X509Certificate> availableSignCerts = new ArrayList<X509Certificate>(keyStore.size());

        for (Enumeration<String> aliases = keyStore.aliases(); aliases.hasMoreElements();)
        {
            String alias = aliases.nextElement();
            if (keyStore.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class))
            {
                Certificate cer = keyStore.getCertificate(alias);
                if (cer instanceof X509Certificate)
                    availableSignCerts.add((X509Certificate)cer);
            }
        }

        if (availableSignCerts.isEmpty())
            throw new SigningCertChainException("No certificates available in the key store");

        // Select the signing certificate from the available certificates.
        X509Certificate signingCert = this.certificateSelector.selectCertificate(availableSignCerts);

        String signingCertAlias = this.keyStore.getCertificateAlias(signingCert);
        if (null == signingCertAlias)
            throw new SigningCertChainException("Selected certificate not present in the key store");

        Certificate[] signingCertChain = this.keyStore.getCertificateChain(signingCertAlias);
        if (null == signingCertChain)
            throw new SigningCertChainException("Selected certificate doesn't match a key and corresponding certificate chain");

        if (this.returnFullChain)
        {
            List lChain = Arrays.asList(signingCertChain);
            return Collections.checkedList(lChain, X509Certificate.class);
        } else
            return Collections.singletonList((X509Certificate)signingCertChain[0]);

    } catch (KeyStoreException ex)
    {
        // keyStore.getCertificateAlias, keyStore.getCertificateChain -> if the
        // keystore is not loaded.
        throw new UnexpectedJCAException(ex.getMessage(), ex);
    }
}
 
Example 12
protected List<String> getAnotherObject() {
    List<String> list = new ArrayList<String>();
    return Collections.checkedList(list, String.class);
}
 
Example 13
protected List<String> getAnotherObject() {
    List<String> list = new ArrayList<String>();
    return Collections.checkedList(list, String.class);
}
 
Example 14
protected List<String> getAnotherObject() {
    List<String> list = Collections.emptyList();
    return Collections.checkedList(list, String.class);
}
 
Example 15
protected List<String> getAnotherObject() {
    List<String> list = Collections.emptyList();
    return Collections.checkedList(list, String.class);
}
 
Example 16
protected List<String> getAnotherObject() {
    List<String> list = Collections.emptyList();
    return Collections.checkedList(list, String.class);
}
 
Example 17
protected List<String> getObject() {
    List<String> list = new ArrayList<String>();
    list.add("string");
    return Collections.checkedList(list, String.class);
}
 
Example 18
/**
 * 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);
}
 
Example 19
Source Project: sis   File: CheckedArrayList.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns a checked sublist.
 *
 * <p><b>Limitation:</b> current implementation checks only the type.
 * It does not prevent the insertion of {@code null} values.</p>
 *
 * @param  fromIndex  index of the first element.
 * @param  toIndex    index after the last element.
 * @return the sublist in the given index range.
 */
@Override
public List<E> subList(final int fromIndex, final int toIndex) {
    return Collections.checkedList(super.subList(fromIndex, toIndex), type);
}
 
Example 20
/**
 * Creates a new {@code AttachmentList}.
 *
 * @param initialCapacity the initial capacity of the list
 * @param valueClass the type of element the list is permitted to hold
 */
public AttachmentList(final int initialCapacity, final Class<E> valueClass) {
    delegate = Collections.checkedList(new ArrayList<>(initialCapacity), valueClass);
    this.valueClass = valueClass;
    mutex = this;
}