/** Returns the shortest title inferred from the specified authority. */ private static InternationalString getShortestTitle(final Citation authority) { InternationalString title = authority.getTitle(); int length = title.length(); final Collection<? extends InternationalString> alt = authority.getAlternateTitles(); if (alt != null) { for (final InternationalString candidate : alt) { final int candidateLength = candidate.length(); if (candidateLength > 0 && candidateLength < length) { title = candidate; length = candidateLength; } } } return title; }
/** * Returns 0 if the other string is empty, or -1 otherwise. */ @Override public int compareTo(final InternationalString other) { return other.length() == 0 ? 0 : -1; }
/** * Returns 0 if the other string is empty, or -1 otherwise. */ @Override public int compareTo(final InternationalString other) { return other.length() == 0 ? 0 : -1; }
/** * Returns the shortest title inferred from the specified authority. * This is used both for creating a generic name, or for inferring a * default identifier code space. */ static InternationalString getShortestTitle(final Citation authority) { InternationalString title = authority.getTitle(); int length = title.length(); final Collection<? extends InternationalString> alt = authority.getAlternateTitles(); if (alt != null) { for (final InternationalString candidate : alt) { final int candidateLength = candidate.length(); if (candidateLength > 0 && candidateLength < length) { title = candidate; length = candidateLength; } } } return title; }
/** * Verifies that the given text is non-null and non-empty. */ private static void assertNonEmpty(final String name, final InternationalString i18n) { assertNotNull(name, i18n); assertTrue(name, i18n.length() != 0); } }
/** * Ensures that the {@link CharSequence} methods are consistent with the {@code toString()} value. * * @param object the object to validate, or {@code null}. */ public void validate(final InternationalString object) { if (object == null) { return; } final int length = object.length(); final String s = object.toString(); mandatory("CharSequence: toString() shall never returns null.", s); if (s != null) { assertEquals("CharSequence: length is inconsistent with toString() length.", s.length(), length); boolean expectLowSurrogate = false; for (int i=0; i<length; i++) { final char c = s.charAt(i); assertEquals("CharSequence: character inconsistent with toString().", c, object.charAt(i)); if (expectLowSurrogate) { assertTrue("CharSequence: High surrogate shall be followed by low surrogate.", Character.isLowSurrogate(c)); } expectLowSurrogate = Character.isHighSurrogate(c); } assertFalse("CharSequence: High surrogate shall be followed by low surrogate.", expectLowSurrogate); } mandatory("InternationalString: toString(Locale) shall not return null.", object.toString(null)); assertEquals("InternationalString: shall be equal to itself.", object, object); assertEquals("InternationalString: shall be comparable to itself.", 0, object.compareTo(object)); }
/** * Ensures that the {@link CharSequence} methods are consistent with the {@code toString()} value. * * @param object The object to validate, or {@code null}. */ public void validate(final InternationalString object) { if (object == null) { return; } final int length = object.length(); final String s = object.toString(); mandatory("InternationalString: toString() should never returns null.", s); if (s != null) { assertEquals("InternationalString: CharSequence length is inconsistent with toString().", s.length(), length); for (int i=0; i<length; i++) { assertEquals("InternationalString: CharSequence is inconsistent with toString().", s.charAt(i), object.charAt(i)); } } mandatory("InternationalString: toString(Locale) should not return null.", object.toString(null)); assertEquals("InternationalString: should be equals to itself.", object, object); assertEquals("InternationalString: should be comparable to itself.", 0, object.compareTo(object)); }