/** * 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; }
/** * 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; }
/** * 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); }
public Literal serialize(T text) { if (text instanceof LangString) return vf.createLiteral(text.toString(), ((LangString)text).getLang()); return vf.createLiteral(text.toString()); }
public Literal serialize(T text) { if (text instanceof LangString) return vf.createLiteral(text.toString(), ((LangString)text).getLang()); return vf.createLiteral(text.toString()); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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 str * the <code>String</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; }
/** * 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()); }
/** * 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()); }
/** * Returns a new string that is a substring of this string. The substring * begins with the character at the specified index and extends to the end * of this string. * <p> * Examples: <blockquote> * * <pre> * "unhappy".substring(2) returns "happy" * "Harbison".substring(3) returns "bison" * "emptiness".substring(9) returns "" (an empty string) * </pre> * * </blockquote> * * @param beginIndex * the beginning index, inclusive. * @return the specified substring. * @exception IndexOutOfBoundsException * if <code>beginIndex</code> is negative or larger than the * length of this <code>String</code> object. */ public LangString substring(int beginIndex) { return new LangString(toString().substring(beginIndex), getLang()); }
/** * Concatenates the specified string to the end of this string. * <p> * If the length of the argument string is <code>0</code>, then this * <code>String</code> object is returned. Otherwise, a new * <code>String</code> object is created, representing a character sequence * that is the concatenation of the character sequence represented by this * <code>String</code> object and the character sequence represented by the * argument string. * <p> * Examples: <blockquote> * * <pre> * "cares".concat("s") returns "caress" * "to".concat("get").concat("her") returns "together" * </pre> * * </blockquote> * * @param str * the <code>String</code> that is concatenated to the end of * this <code>String</code>. * @return a string that represents the concatenation of this object's * characters followed by the string argument's characters. */ public LangString concat(String str) { return new LangString(toString().concat(str), getLang()); }
/** * Returns a new string that is a substring of this string. The substring * begins with the character at the specified index and extends to the end * of this string. * <p> * Examples: <blockquote> * * <pre> * "unhappy".substring(2) returns "happy" * "Harbison".substring(3) returns "bison" * "emptiness".substring(9) returns "" (an empty string) * </pre> * * </blockquote> * * @param beginIndex * the beginning index, inclusive. * @return the specified substring. * @exception IndexOutOfBoundsException * if <code>beginIndex</code> is negative or larger than the * length of this <code>String</code> object. */ public LangString substring(int beginIndex) { return new LangString(toString().substring(beginIndex), getLang()); }
/** * Concatenates the specified string to the end of this string. * <p> * If the length of the argument string is <code>0</code>, then this * <code>String</code> object is returned. Otherwise, a new * <code>String</code> object is created, representing a character sequence * that is the concatenation of the character sequence represented by this * <code>String</code> object and the character sequence represented by the * argument string. * <p> * Examples: <blockquote> * * <pre> * "cares".concat("s") returns "caress" * "to".concat("get").concat("her") returns "together" * </pre> * * </blockquote> * * @param str * the <code>String</code> that is concatenated to the end of * this <code>String</code>. * @return a string that represents the concatenation of this object's * characters followed by the string argument's characters. */ public LangString concat(String str) { return new LangString(toString().concat(str), getLang()); }
/** * Returns a new string that is a substring of this string. The substring * begins at the specified <code>beginIndex</code> and extends to the * character at index <code>endIndex - 1</code>. Thus the length of the * substring is <code>endIndex-beginIndex</code>. * <p> * Examples: <blockquote> * * <pre> * "hamburger".substring(4, 8) returns "urge" * "smiles".substring(1, 5) returns "mile" * </pre> * * </blockquote> * * @param beginIndex * the beginning index, inclusive. * @param endIndex * the ending index, exclusive. * @return the specified substring. * @exception IndexOutOfBoundsException * if the <code>beginIndex</code> is negative, or * <code>endIndex</code> is larger than the length of this * <code>String</code> object, or <code>beginIndex</code> is * larger than <code>endIndex</code>. */ public LangString substring(int beginIndex, int endIndex) { return new LangString(toString().substring(beginIndex, endIndex), getLang()); }
return new LangString(toString().trim(), getLang());
/** * Returns a new string that is a substring of this string. The substring * begins at the specified <code>beginIndex</code> and extends to the * character at index <code>endIndex - 1</code>. Thus the length of the * substring is <code>endIndex-beginIndex</code>. * <p> * Examples: <blockquote> * * <pre> * "hamburger".substring(4, 8) returns "urge" * "smiles".substring(1, 5) returns "mile" * </pre> * * </blockquote> * * @param beginIndex * the beginning index, inclusive. * @param endIndex * the ending index, exclusive. * @return the specified substring. * @exception IndexOutOfBoundsException * if the <code>beginIndex</code> is negative, or * <code>endIndex</code> is larger than the length of this * <code>String</code> object, or <code>beginIndex</code> is * larger than <code>endIndex</code>. */ public LangString substring(int beginIndex, int endIndex) { return new LangString(toString().substring(beginIndex, endIndex), getLang()); }
return new LangString(toString().trim(), getLang());
return new LangString(toString().replace(oldChar, newChar), getLang());