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());
}
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;
}
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());
}
}
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));
}
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));
}
Aggregations