public boolean equals(Object o) { if( o instanceof StringValue ) { StringValue r = (StringValue)o; return StringUtil.equals(value, r.value); } return false; } public int getValueType() {
@Override public String toString() { return StringUtil.format( "[AccessToken: appId = {0}, serviceName = {1}, userId = {2}, moduleId = {3}, tokenName = {4}, expiresIn = {5}, authorizationExpiresIn = {6}, sessionHandle = {7}]", new Object[] { appId, serviceName, userId, moduleId, tokenName, expiresIn, authorizationExpiresIn, sessionHandle } ); } }
public static String[] splitString( String s, String sep, boolean trim ) { if( s==null ) { return EMPTY_STRING_ARRAY; } if( isEmpty(sep) ){ // Handling this like the JavaScript split method, // if the separator is omitted, the entire string is returned. // Different to the Java String split method, which returns // an array full with entries for each character. return new String[]{s}; } return splitString( null, 0, s, 0, sep, trim ); } private static String[] splitString( String[] result, int count, String s, int pos, String sep, boolean trim ) {
public static String toString(int year, int month, int day, int hour, int minute, int second, int millis) { return StringUtil.format( "{0}-{1}-{2}", //$NON-NLS-1$ StringUtil.toString(year), StringUtil.toString(month), StringUtil.toString(day)) + StringUtil.format( " {0}:{1}:{2}", //.{3}", //$NON-NLS-1$ StringUtil.toString(hour), StringUtil.toString(minute), StringUtil.toString(second) ); // StringUtil.toString(millis)); } public static int getYear( long dt ) {
public static boolean isContainedWithin(String s, String[] container) { if(isNotEmpty(s) && isNotEmpty(container)) { for(int i = 0; i < container.length; i++) { if(equals(s, container[i])) { return true; } } } return false; }
/** * Remove line breaks. */ public static String removeLineBreaks(String s) { if (lineSeparators == null) { lineSeparators = getLineSeparators(); } for (int i = 0; i < lineSeparators.length; i++) { s = replace(s, lineSeparators[i], SPACE); } return s; }
/** * Check if a Topic is locked * * @method isLocked * @return boolean */ public boolean isLocked(){ boolean lock = false; if(StringUtil.isNotEmpty(getAsString(ForumsXPath.flag))){ List<String> flags = Arrays.asList(getDataHandler().getAsString(ForumsXPath.flag).split(" ")); for (int i = 0; i < flags.size(); i++) { if(StringUtil.equalsIgnoreCase(flags.get(i), FlagType.LOCK.getFlagType())){ lock = true; break; } } } return lock; }
public String getAuthenticationPage() { if(StringUtil.isEmpty(authenticationPage)){ // return default authentication page if it is not given in managed bean return "/sbt/loginForm.html"; } return authenticationPage; }
/** * Update Community Logo, supported for connections * * @param file * image to be uploaded as Community Logo * @param communityId * @throws ClientServicesException */ public void updateCommunityLogo(java.io.File file, String communityId) throws ClientServicesException{ Map<String, String> parameters = new HashMap<String, String>(); parameters.put(COMMUNITY_UNIQUE_IDENTIFIER, communityId); String name = file.getName(); int dot = StringUtil.lastIndexOfIgnoreCase(name, "."); String ext = ""; if (dot > -1) { ext = name.substring(dot + 1); // add one for the dot! } if (!StringUtil.isEmpty(ext)) { Map<String, String> headers = new HashMap<String, String>(); if (StringUtil.equalsIgnoreCase(ext,"jpg")) { headers.put("Content-Type", "image/jpeg"); // content-type should be image/jpeg for file extension - jpeg/jpg } else { headers.put("Content-Type", "image/" + ext); } // the url doesn't have atom in base String url = "/communities/service/html/image"; getClientService().put(url, parameters, headers, file, ClientService.FORMAT_NULL); } }
private void checkValue(String value) { if(StringUtil.isNotEmpty(value)) { if(value.indexOf((char)0)>=0) { throw new IllegalArgumentException("Value cannot contain '\\0' character"); // $NLS-Preferences.Valuecannotcontaina0character-1$ } } }
/** * Replace any of the listed values with the specified replacement in the source string. * * @param source * @param values * @param replace * @return string with updated value */ private String replace(String source, String[] values, String[] replaces) { if (StringUtil.isEmpty(source) || values == null || replaces == null) { return ""; //$NON-NLS-1$ } for (int i=0; i<values.length; i++) { source = StringUtil.replace(source, values[i], replaces[i]); } return source; }
public static boolean parseBoolean(String s) { if(StringUtil.isEmpty(s)) { return false; } if(s.equals("true")) //$NON-NLS-1$ return true; if(s.equals("false")) //$NON-NLS-1$ return false; throw new NumberFormatException(StringUtil.format("Invalid Boolean format", s)); // $NLS-XMIConverter.InvalidBooleanformat-1$ }
private String extractInviteUuid(String uid) { if (StringUtil.isNotEmpty(uid) && StringUtil.startsWithIgnoreCase(uid, "urn:lsid:ibm.com:communities:invite-")) { return uid.substring("urn:lsid:ibm.com:communities:invite-".length()); } else { return uid; } }
public void setRuntimes(String sRuntimes){ this.runtimes = StringUtil.splitString(sRuntimes, ','); } public boolean hasRuntime(String runtime) {
/** * Get the index of a specific string begining at a specific index. * The string are compared by value and not by the object pointer. * @param item the string to look for * @param index the index where to start the search * @return the index of that string (-1 if it does'nt esist) */ public final int indexOf( Object item, int index ) { int size = size(); String s = (String)item; if( caseInsensitive ) { for( int i=index; i<size; i++ ) { if( StringUtil.equalsIgnoreCase(getString(i),s) ) { return i; } } return -1; } else { for( int i=index; i<size; i++ ) { if( StringUtil.equals(getString(i),s) ) { return i; } } return -1; } }
protected boolean isHeaderAllowed(String headerName) throws ServletException { // content-length header will be automatically added by the HTTP client // host header causes request failures when it does not match the proxy host see x-forwaded-for comment above // Origin is added by chrome / safari in post/put/delete same-origin requests. if(StringUtil.equalsIgnoreCase(headerName, "content-length") || StringUtil.equalsIgnoreCase(headerName, "host") || StringUtil.equalsIgnoreCase(headerName, "origin")) { return false; } return true; } protected boolean forwardCookies(HttpRequestBase method, HttpServletRequest request) {
/** * Trims the spaces characters from both ends of of the character array. * @param array the char array to trim * @return the trimmed string * @ibm-api */ public static final String trim( char[] array ) { int count = array.length; int last = count; int st = 0; while ((st < last) && isSpace(array[st])) { st++; } while ((st < last) && isSpace(array[last - 1])) { last--; } if( last>st ) { return new String( array, st, last-st ); } return ""; //$NON-NLS-1$ }
/** * If a decimal number contains thousand separator (example : a coma in US), * they are removed, so that the string can be correctly interpreted by Double.parseDouble * @ibm-api */ public static String removeThousandSeparator(String doubleString, Locale loc) { DecimalFormatSymbols symb = new DecimalFormatSymbols(loc); char thoSep = symb.getGroupingSeparator(); if (thoSep=='.') { // don't remove thousand separator if it is a '.' return doubleString; } if (thoSep==160) { // insecable white space thoSep=' '; } return StringUtil.replace(doubleString, String.valueOf(thoSep), null); }
/** * Generates a sequence of spaces * @param count * @return */ public static String spaces(int count) { switch(count) { case 0: return ""; case 1: return " "; case 2: return " "; case 3: return " "; case 4: return " "; case 5: return " "; case 6: return " "; case 7: return " "; case 8: return " "; } return StringUtil.repeat(' ', count); } }