Search in sources :

Example 1 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class TreeTablesTest method testReplaceCharSequences.

/**
 * Tests the {@link TreeTables#replaceCharSequences(TreeTable, Locale)} method.
 */
@Test
public void testReplaceCharSequences() {
    final TreeTable table = new DefaultTreeTable(NAME, VALUE_AS_NUMBER);
    final TreeTable.Node root = table.getRoot();
    final TreeTable.Node parent = root.newChild();
    final TreeTable.Node child1 = parent.newChild();
    final TreeTable.Node child2 = root.newChild();
    root.setValue(NAME, new StringBuilder("Root"));
    parent.setValue(NAME, "A parent");
    child1.setValue(NAME, new StringBuilder("A child"));
    child2.setValue(NAME, new SimpleInternationalString("A child"));
    root.setValue(VALUE_AS_NUMBER, 8);
    parent.setValue(VALUE_AS_NUMBER, 4);
    final String asString = table.toString();
    assertEquals(3, replaceCharSequences(table, null));
    assertInstanceOf("replaceCharSequences:", String.class, root.getValue(NAME));
    assertInstanceOf("replaceCharSequences:", String.class, parent.getValue(NAME));
    assertInstanceOf("replaceCharSequences:", String.class, child1.getValue(NAME));
    assertInstanceOf("replaceCharSequences:", String.class, child2.getValue(NAME));
    assertSame("Expected unique instance of String.", child1.getValue(NAME), child2.getValue(NAME));
    assertEquals("String representation shall be the same.", asString, table.toString());
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test)

Example 2 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class LandsatReader method band.

/**
 * Returns the band at the given index, creating it if needed.
 * If the given index is out of range, then this method logs a warning and returns {@code null}.
 *
 * @param  key    the key without its band number. Used only for formatting warning messages.
 * @param  index  the band index.
 */
private DefaultBand band(final String key, int index) {
    if (index < 1 || index > BAND_NAMES.length) {
        listeners.warning(errors().getString(Errors.Keys.UnexpectedValueInElement_2, key + index, index), null);
        return null;
    }
    DefaultBand band = bands[--index];
    if (band == null) {
        band = new DefaultBand();
        band.setDescription(new SimpleInternationalString(BAND_NAMES[index]));
        band.setPeakResponse((double) WAVELENGTHS[index]);
        band.setBoundUnits(Units.NANOMETRE);
        bands[index] = band;
    }
    return band;
}
Also used : DefaultBand(org.apache.sis.metadata.iso.content.DefaultBand) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 3 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class CharSequencesTest method testCopyChars.

/**
 * Tests the {@link CharSequences#copyChars(CharSequence, int, char[], int, int)} method.
 */
@Test
public void testCopyChars() {
    final char[] buffer = new char[12];
    for (int i = 0; i <= 4; i++) {
        final CharSequence sequence;
        switch(i) {
            case 0:
                sequence = ("testCopyChars()");
                break;
            case 1:
                sequence = new StringBuilder("testCopyChars()");
                break;
            case 2:
                sequence = new StringBuffer("testCopyChars()");
                break;
            case 3:
                sequence = CharBuffer.wrap("testCopyChars()");
                break;
            case 4:
                sequence = new SimpleInternationalString("testCopyChars()");
                break;
            default:
                throw new AssertionError(i);
        }
        Arrays.fill(buffer, '-');
        copyChars(sequence, 4, buffer, 2, 9);
        assertEquals("--CopyChars-", String.valueOf(buffer));
        // CharBuffer position must be unchanged.
        assertEquals("testCopyChars()", sequence.toString());
    }
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test)

Example 4 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class CharSequencesTest method testIndexOf.

/**
 * Tests the {@link CharSequences#indexOf(CharSequence, CharSequence, int, int)} method.
 * We test four times with different kind of character sequences.
 */
@Test
public void testIndexOf() {
    for (int i = 0; i < 3; i++) {
        CharSequence string = "An ordinary sentence.";
        switch(i) {
            case 0:
                /* Test directly on the String instance. */
                break;
            case 1:
                string = new StringBuilder((String) string);
                break;
            case 2:
                string = new StringBuffer((String) string);
                break;
            case 3:
                string = new SimpleInternationalString((String) string);
                break;
            default:
                throw new AssertionError(i);
        }
        final int length = string.length();
        assertEquals(-1, indexOf(string, "dummy", 0, length));
        assertEquals(0, indexOf(string, "An", 0, length));
        assertEquals(-1, indexOf(string, "An", 1, length));
        assertEquals(12, indexOf(string, "sentence.", 0, length));
        assertEquals(-1, indexOf(string, "sentence;", 0, length));
    }
    assertEquals(-1, indexOf("", "An", 0, 0));
    assertEquals(-1, indexOf(null, "An", 0, 0));
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test)

Example 5 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class MetadataStandardTest method testEquals.

/**
 * Tests the {@link MetadataStandard#equals(Object, Object, ComparisonMode)} method.
 */
@Test
@DependsOnMethod("testGetAccessor")
public void testEquals() {
    standard = MetadataStandard.ISO_19115;
    // Self equality test
    DefaultCitation instance = HardCodedCitations.EPSG;
    assertFalse(standard.equals(instance, HardCodedCitations.SIS, ComparisonMode.STRICT));
    assertTrue(standard.equals(instance, HardCodedCitations.EPSG, ComparisonMode.STRICT));
    // Test comparison with a copy
    instance = new DefaultCitation(HardCodedCitations.EPSG);
    assertFalse(standard.equals(instance, HardCodedCitations.SIS, ComparisonMode.STRICT));
    assertTrue(standard.equals(instance, HardCodedCitations.EPSG, ComparisonMode.STRICT));
    // test comparison with a modified copy
    instance.setTitle(new SimpleInternationalString("A dummy title"));
    assertFalse(standard.equals(instance, HardCodedCitations.EPSG, ComparisonMode.STRICT));
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)45 Test (org.junit.Test)20 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)19 InternationalString (org.opengis.util.InternationalString)14 URI (java.net.URI)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)3 Citation (org.opengis.metadata.citation.Citation)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 Collection (java.util.Collection)2 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)2 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)2 DefaultAcquisitionInformation (org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation)2 DefaultInstrument (org.apache.sis.metadata.iso.acquisition.DefaultInstrument)2 DefaultPlatform (org.apache.sis.metadata.iso.acquisition.DefaultPlatform)2 DefaultFormat (org.apache.sis.metadata.iso.distribution.DefaultFormat)2 DefaultDataQuality (org.apache.sis.metadata.iso.quality.DefaultDataQuality)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1