/** * Indicates if this object has at least standoff item. * @return true if this object has at least standoff item, false otherwise. */ public boolean hasStandoff () { return !Util.isEmpty(standoff); }
/** * Converts a list of strings into an array of those strings. * @param list List of strings. * @return an array of strings. */ public static String[] stringListAsArray(List<String> list) { if (Util.isEmpty(list)) return new String[] {}; return (String[]) list.toArray(new String[] {}); }
/** * Disallows the locales which user part matches a given user part. * @param userPart the given user part. * @return this locale filter. */ public LocaleFilter excludeUserPart(String userPart) { if (Util.isEmpty(userPart)) return this; this.userPartExcludes.add("xx-xx-x-" + userPart); return this; }
/** * Gets the length of a string, even a null one. * @param string the string to examine. * @return the length of the given string, 0 if the string is null. */ static public int getLength (String string) { return (isEmpty(string)) ? 0 : string.length(); }
/** * Extracts the package name part of a qualified class name. * @param className Qualified class name * @return Package name (w/o the trailing dot) */ public static String extractPackageName(String className) { if (Util.isEmpty(className)) return ""; int index = className.lastIndexOf("."); if (index > -1) return className.substring(0, index); return ""; }
/** * Extracts the class name part of a qualified class name. * @param className Qualified class name * @return Class name */ public static String extractShortClassName(String className) { if (Util.isEmpty(className)) return ""; int index = className.lastIndexOf("."); if (index > -1) return className.substring(index + 1); return className; }
/** * Checks if a given string contains only whitespace characters. * @param str the given string * @return true if the given string is whitespace */ public static boolean isWhitespace(String str) { if (Util.isEmpty(str)) return false; // "" is neither whitespace return "".equals(str.trim()); }
/** * Disallows all locales matching a given regular expression with a given set of regex flags. * @param regex the given regular expression. * @param flags the given set of regex flags. * @return this locale filter. */ public LocaleFilter excludePattern(String regex, int flags) { if (Util.isEmpty(regex)) return this; patternExcludes.add(0, Pattern.compile(regex, flags)); return this; }
/** * Detects if a given string contains shell wildcard characters (e.g. * and ?). * @param string the given string. * @return true if the string contains the asterisk (*) or question mark (?). */ public static boolean containsWildcards(String string) { if (Util.isEmpty(string)) return false; return string.indexOf('*') != -1 || string.indexOf('?') != -1; }
/** * Adds all the annotations from a given list to this object. * @param newItems the list of annotations to add. */ public void addAll (List<GenericAnnotation> newItems) { if ( Util.isEmpty(newItems) ) return; // There is something to add: make sure we have a place where to copy if ( list == null ) list = new ArrayList<GenericAnnotation>(newItems.size()); // Add all annotations of the given list list.addAll(newItems); }
/** * Allows the locales which region matches a given region. * @param region the given region. * @return this locale filter. */ public LocaleFilter includeRegion(String region) { if (Util.isEmpty(region)) return this; String regionMask = "xx-" + region; removeFromRegionExcludes(regionMask); this.regionIncludes.add(regionMask); return this; }
/** * Adds a new part to this skeleton, and set a string data to it. * Empty or null data has no effect. * @param data the data to add. */ public void add (String data) { if ( Util.isEmpty(data) ) return; GenericSkeletonPart part = new GenericSkeletonPart(data); list.add(part); createNew = false; }
/** * Allows the locales which language matches any of the languages from a given array. * @param languages the given array of languages. * @return this locale filter. */ public LocaleFilter includeLanguage(String ... languages) { if (Util.isEmpty(languages)) return this; for (String language : languages) includeLanguage(language); return this; }
/** * Allows the locales which language matches a given language. * @param language the given language. * @return this locale filter. */ public LocaleFilter includeLanguage(String language) { if (Util.isEmpty(language)) return this; String languageMask = language; removeFromLanguageExcludes(languageMask); this.languageIncludes.add(languageMask); return this; }
/** * Disallows the locales from a given array of locales. * @param localeIds the given array of locales. * @return this locale filter. */ public LocaleFilter exclude(LocaleId ... localeIds) { if (Util.isEmpty(localeIds)) return this; for (LocaleId localeId : localeIds) exclude(localeId); return this; }
/** * Disallows the locales which language matches any of the languages from a given array. * @param languages the given array of languages. * @return this locale filter. */ public LocaleFilter excludeLanguage(String ... languages) { if (Util.isEmpty(languages)) return this; for (String language : languages) excludeLanguage(language); return this; }
/** * Disallows the locales which user part matches any of the user parts from a given array. * @param userParts the given array of user parts. * @return this locale filter. */ public LocaleFilter excludeUserPart(String ... userParts) { if (Util.isEmpty(userParts)) return this; for (String userPart : userParts) excludeUserPart(userPart); return this; }
public Map<String, String> toMap () { LinkedHashMap<String, String> table = new LinkedHashMap<String, String>(); String tmp = toString(); if ( Util.isEmpty(tmp) ) return table; String[] pairs = tmp.split("\n", 0); for ( String pair : pairs ) { String[] keyvalue = pair.split("="); table.put(keyvalue[0], // Handle empty parameters (( keyvalue.length > 1 ) ? keyvalue[1] : "")); } return table; }
/** * Helper method. */ private void setLanguage(boolean excludeMode, String language) { if (Util.isEmpty(language)) return; if (excludeMode) excludeLanguage(language); else includeLanguage(language); }
public static void convertTextPart_whitespaceCodesToText(TextPart textPart) { if (textPart.isSegment()) return; TextFragment tf = textPart.getContent(); if (tf.hasText()) return; if (Util.isEmpty(tf.toText().trim())) { // Move all codes into text textPart.setContent(new TextFragment(tf.toText())); } }