Tabnine Logo
CheckedArrayList.castOrCopy
Code IndexAdd Tabnine to your IDE (free)

How to use
castOrCopy
method
in
org.apache.sis.internal.util.CheckedArrayList

Best Java code snippets using org.apache.sis.internal.util.CheckedArrayList.castOrCopy (Showing top 7 results out of 315)

origin: org.apache.sis.core/sis-feature

/**
 * Creates a new association of the given role initialized to the given values.
 *
 * @param role   Information about the association.
 * @param values The initial values, or {@code null} for initializing to an empty list.
 */
MultiValuedAssociation(final DefaultAssociationRole role, final Object values) {
  super(role);
  if (values == null) {
    this.values = new CheckedArrayList<>(AbstractFeature.class);
  } else {
    this.values = CheckedArrayList.castOrCopy((CheckedArrayList<?>) values, AbstractFeature.class);
  }
}
origin: apache/sis

/**
 * Creates a new association of the given role initialized to the given values.
 *
 * @param role   Information about the association.
 * @param values The initial values, or {@code null} for initializing to an empty list.
 */
MultiValuedAssociation(final DefaultAssociationRole role, final Object values) {
  super(role);
  if (values == null) {
    this.values = new CheckedArrayList<>(AbstractFeature.class);
  } else {
    this.values = CheckedArrayList.castOrCopy((CheckedArrayList<?>) values, AbstractFeature.class);
  }
}
origin: org.apache.sis.core/sis-feature

/**
 * Verifies the validity of the given attribute value, and returns the value to store in the feature.
 * An attribute:
 * <ul>
 *   <li>May be a singleton,  in which case the value class is verified.</li>
 *   <li>May be a collection, in which case the class each elements in the collection is verified.</li>
 * </ul>
 *
 * @param  value  the value, which shall be non-null.
 */
private static <T> Object verifyAttributeValue(final DefaultAttributeType<T> type, final Object value) {
  final Class<T> valueClass = type.getValueClass();
  final boolean isSingleton = Field.isSingleton(type.getMaximumOccurs());
  if (valueClass.isInstance(value)) {
    return isSingleton ? value : singletonList(valueClass, type.getMinimumOccurs(), value);
  } else if (!isSingleton && value instanceof Collection<?>) {
    return CheckedArrayList.castOrCopy((Collection<?>) value, valueClass);
  } else {
    throw new ClassCastException(illegalValueClass(type, valueClass, value));
  }
}
origin: apache/sis

/**
 * Verifies the validity of the given attribute value, and returns the value to store in the feature.
 * An attribute:
 * <ul>
 *   <li>May be a singleton,  in which case the value class is verified.</li>
 *   <li>May be a collection, in which case the class each elements in the collection is verified.</li>
 * </ul>
 *
 * @param  value  the value, which shall be non-null.
 */
private static <T> Object verifyAttributeValue(final DefaultAttributeType<T> type, final Object value) {
  final Class<T> valueClass = type.getValueClass();
  final boolean isSingleton = Field.isSingleton(type.getMaximumOccurs());
  if (valueClass.isInstance(value)) {
    return isSingleton ? value : singletonList(valueClass, type.getMinimumOccurs(), value);
  } else if (!isSingleton && value instanceof Collection<?>) {
    return CheckedArrayList.castOrCopy((Collection<?>) value, valueClass);
  } else {
    throw new ClassCastException(illegalValueClass(type, valueClass, value));
  }
}
origin: org.apache.sis.core/sis-feature

  return CheckedArrayList.castOrCopy((Collection<?>) value, AbstractFeature.class);
} else {
  throw new ClassCastException(illegalValueClass(role, AbstractFeature.class, value));
origin: apache/sis

  return CheckedArrayList.castOrCopy((Collection<?>) value, AbstractFeature.class);
} else {
  throw new ClassCastException(illegalValueClass(role, AbstractFeature.class, value));
origin: apache/sis

  /**
   * Tests {@link CheckedArrayList#castOrCopy(Collection, Class)}.
   */
  @Test
  @DependsOnMethod("testAddAll")
  public void testCastOrCopy() {
    assertNull(CheckedArrayList.castOrCopy(null, String.class));
    final List<String> fruits = Arrays.asList("Apple", "Orange", "Raisin");
    final CheckedArrayList<String> asStrings = CheckedArrayList.castOrCopy(fruits, String.class);
    assertEquals ("Should have the given element type.", String.class, asStrings.getElementType());
    assertNotSame("Should have created a new instance.", fruits, asStrings);
    assertEquals ("Should contain the same data.",       fruits, asStrings);
    assertSame   ("Should cast existing instance.", asStrings, CheckedArrayList.castOrCopy(asStrings, String.class));

    final CheckedArrayList<CharSequence> asChars = CheckedArrayList.castOrCopy(asStrings, CharSequence.class);
    assertEquals ("Should have the given element type.", CharSequence.class, asChars.getElementType());
    assertNotSame("Should have created a new instance.", asStrings, asChars);
    assertEquals ("Should contain the same data.",       asStrings, asChars);
    assertEquals ("Should contain the same data.",       fruits,    asChars);

    try {
      CheckedArrayList.castOrCopy(asChars, Integer.class);
      fail("Should not be allowed to cast String to Integer.");
    } catch (ClassCastException e) {
      final String message = e.getMessage();
      assertTrue(message, message.contains("String"));
      assertTrue(message, message.contains("Integer"));
    }
  }
}
org.apache.sis.internal.utilCheckedArrayListcastOrCopy

Javadoc

Returns the given collection as a CheckedArrayList instance of the given element type.

Popular methods of CheckedArrayList

  • <init>
    Constructs a list of the specified type and initial capacity.
  • addAll
    Appends all of the elements in the specified collection to the end of this list, in the order that t
  • add
    Appends the specified element to the end of this list.
  • get
  • clear
  • clone
  • ensureValid
    Ensures that the given element is non-null and assignable to the type specified at construction time
  • ensureValidCollection
    Ensures that all elements of the given collection can be added to this list.
  • equals
  • getElementType
    Returns the element type given at construction time.
  • hashCode
  • illegalElement
    Invoked when an illegal element has been given to the add(E) method. The element may be illegal eith
  • hashCode,
  • illegalElement,
  • size,
  • subList

Popular in Java

  • Start an intent from android
  • getSystemService (Context)
  • putExtra (Intent)
  • getSharedPreferences (Context)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Kernel (java.awt.image)
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • JTable (javax.swing)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now