/** * Replaces each substring of this string that matches the literal target * sequence with the specified literal replacement sequence. The replacement * proceeds from the beginning of the string to the end, for example, * replacing "aa" with "b" in the string "aaa" will result in "ba" rather * than "ab". * * @param target * The sequence of char values to be replaced * @param replacement * The replacement sequence of char values * @return The resulting string * @throws NullPointerException * if <code>target</code> or <code>replacement</code> is * <code>null</code>. */ public LangString replace(CharSequence target, CharSequence replacement) { return new LangString(toString().replace(target, replacement), getLang()); }
return split(regex, 0);
/** * Constructs a LangString using the given label and locale. * * @param label * @param locale */ public LangString(String label, Locale locale) { this(label, toLang(locale)); this.locale = locale; }
/** * Compares this string to the specified object. The result is {@code true} * if and only if the argument is not {@code null} and is a {@code String} * object that represents the same sequence of characters as this object. * * @param anObject * The object to compare this {@code String} against * * @return {@code true} if the given object represents a {@code String} * equivalent to this string, {@code false} otherwise * * @see #compareTo(String) * @see #equalsIgnoreCase(String) */ @Override public boolean equals(Object o) { if (this == o) return true; if (o instanceof LangString) { LangString other = (LangString) o; if (!toString().equals(other.toString())) return false; if (!getLang().equalsIgnoreCase(other.getLang())) return false; return true; } return false; }
return new LangString(toString().toUpperCase(getLocale()), getLang());
String concat = toString().concat(str.toString()); String l1 = getLang(); String l2 = str.getLang(); if (l1.equalsIgnoreCase(l2)) return new LangString(concat, l1); if (str.matchesLang(l1)) return new LangString(concat, l1); if (matchesLang(l2)) return new LangString(concat, l2); return new LangString(concat, common);
/** * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>. * * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise * <tt>false</tt> */ public final boolean isEmpty() { return toString().isEmpty(); }
/** * The language of the current LangString as a Locale. * * @return this language as a Locale */ public synchronized Locale getLocale() { if (locale == null) { String[] split = getLang().split("-", 3); if (split.length == 1) { locale = new Locale(getLang()); } else if (split.length == 2) { locale = new Locale(split[0], split[1]); } else { locale = new Locale(split[0], split[1], split[2]); } } return locale; }
/** * Constructs a LangString using the given label and language. * * @param label * @param language * @return a LangString with the given label and language */ public static LangString valueOf(String label, String language) { return new LangString(label, language); }
return new LangString(toString().toUpperCase(getLocale()), getLang());
/** * Compares this string to the specified object. The result is {@code true} * if and only if the argument is not {@code null} and is a {@code LangString} * object that represents the same sequence of characters as this object. * * @param o * The object to compare this {@code LangString} against * * @return {@code true} if the given object represents a {@code LangString} * equivalent to this string, {@code false} otherwise * * @see #compareTo(LangString) * @see #equalsIgnoreCase(Object) */ @Override public boolean equals(Object o) { if (this == o) return true; if (o instanceof LangString) { LangString other = (LangString) o; if (!toString().equals(other.toString())) return false; if (!getLang().equalsIgnoreCase(other.getLang())) return false; return true; } return false; }
String concat = toString().concat(str.toString()); String l1 = getLang(); String l2 = str.getLang(); if (l1.equalsIgnoreCase(l2)) return new LangString(concat, l1); if (str.matchesLang(l1)) return new LangString(concat, l1); if (matchesLang(l2)) return new LangString(concat, l2); return new LangString(concat, common);
/** * Returns the length of this string. * The length is equal to the number of <a href="Character.html#unicode">Unicode * code units</a> in the string. * * @return the length of the sequence of characters represented by this * object. */ public int length() { return toString().length(); }
/** * The language of the current LangString as a Locale. * * @return this language as a Locale */ public synchronized Locale getLocale() { if (locale == null) { String[] split = getLang().split("-", 3); if (split.length == 1) { locale = new Locale(getLang()); } else if (split.length == 2) { locale = new Locale(split[0], split[1]); } else { locale = new Locale(split[0], split[1], split[2]); } } return locale; }
/** * Constructs a LangString using the default {@link Locale} for the * language. * * @param label * @return a LangString with the given label and a default language */ public static LangString valueOf(String label) { return new LangString(label); }
/** * Replaces each substring of this string that matches the literal target * sequence with the specified literal replacement sequence. The replacement * proceeds from the beginning of the string to the end, for example, * replacing "aa" with "b" in the string "aaa" will result in "ba" rather * than "ab". * * @param target * The sequence of char values to be replaced * @param replacement * The replacement sequence of char values * @return The resulting string * @throws NullPointerException * if <code>target</code> or <code>replacement</code> is * <code>null</code>. */ public LangString replace(CharSequence target, CharSequence replacement) { return new LangString(toString().replace(target, replacement), getLang()); }
return new LangString(toString().toLowerCase(getLocale()), getLang());
/** * Compares two strings lexicographically, ignoring case differences. This * method returns an integer whose sign is that of calling * <code>compareTo</code> with normalized versions of the strings where case * differences have been eliminated by calling * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on * each character. * <p> * Note that this method does <em>not</em> take locale into account, and * will result in an unsatisfactory ordering for certain locales. The * java.text package provides <em>collators</em> to allow locale-sensitive * ordering. * * @param o * the <code>LangString</code> to be compared. * @return a negative integer, zero, or a positive integer as the specified * String is greater than, equal to, or less than this String, * ignoring case considerations. * @see java.text.Collator#compare(String, String) */ public int compareToIgnoreCase(LangString o) { if (this == o) return 0; if (o == null) return 1; int result = this.getLang().compareToIgnoreCase(o.getLang()); if (result == 0) return this.toString().compareToIgnoreCase(o.toString()); return result; }
/** * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>. * * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise * <tt>false</tt> */ public final boolean isEmpty() { return toString().isEmpty(); }
/** * Checks whether a string - with or without language information (see {@link LangString}) - * is preferred over another string wrt. the language preference given. * @param s The string to decide preference for. * @param other The string to compare to. * @return Returns true if the language of <code>s</code> is preferred over the one of * <code>other</code> or its language is in the preference list and the * one of <code>other</code> is not. Returns false if the language of <code>s</code> is not * in the preference list. */ private boolean isStringPreferred(CharSequence s, CharSequence other, List<String> preference) { String lang, otherLang; if(s instanceof LangString) { lang = ((LangString) s).getLang(); } else if(s == null) { return false; } else { lang = UNTYPED_LITERAL; } if(other instanceof LangString) { otherLang = ((LangString) other).getLang(); } else if(other == null) { return preference.contains(lang); } else { otherLang = UNTYPED_LITERAL; } return isLanguagePreferred(lang, otherLang, preference); }