List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:com.amazon.carbonado.repo.jdbc.JDBCStorableIntrospector.java
/** * Generates aliases for the given name, converting camel case form into * various underscore forms.//from ww w .j ava 2s. co m */ static String[] generateAliases(String base) { int length = base.length(); if (length <= 1) { return new String[] { base.toUpperCase(), base.toLowerCase() }; } ArrayList<String> aliases = new ArrayList<String>(4); StringBuilder buf = new StringBuilder(); int i; for (i = 0; i < length;) { char c = base.charAt(i++); if (c == '_' || !Character.isJavaIdentifierPart(c)) { // Keep scanning for first letter. buf.append(c); } else { buf.append(Character.toUpperCase(c)); break; } } boolean canSeparate = false; boolean appendedIdentifierPart = false; for (; i < length; i++) { char c = base.charAt(i); if (c == '_' || !Character.isJavaIdentifierPart(c)) { canSeparate = false; appendedIdentifierPart = false; } else if (Character.isLowerCase(c)) { canSeparate = true; appendedIdentifierPart = true; } else { if (appendedIdentifierPart && i + 1 < length && Character.isLowerCase(base.charAt(i + 1))) { canSeparate = true; } if (canSeparate) { buf.append('_'); } canSeparate = false; appendedIdentifierPart = true; } buf.append(c); } String derived = buf.toString(); addToSet(aliases, derived.toUpperCase()); addToSet(aliases, derived.toLowerCase()); addToSet(aliases, derived); addToSet(aliases, base.toUpperCase()); addToSet(aliases, base.toLowerCase()); addToSet(aliases, base); return aliases.toArray(new String[aliases.size()]); }
From source file:com.gelakinetic.mtgfam.helpers.CardDbAdapter.java
public Cursor Search(String cardname, String cardtext, String cardtype, String color, int colorlogic, String sets, float pow_choice, String pow_logic, float tou_choice, String tou_logic, int cmc, String cmcLogic, String format, String rarity, String flavor, String artist, int type_logic, int text_logic, int set_logic, boolean backface, String[] returnTypes, boolean consolidate) throws FamiliarDbException { Cursor mCursor = null;/*from www .j a v a 2 s. c om*/ if (cardname != null) cardname = cardname.replace("'", "''").replace(Character.toChars(0xE6)[0], Character.toChars(0xC6)[0]) .trim(); if (cardtext != null) cardtext = cardtext.replace("'", "''").trim(); if (cardtype != null) cardtype = cardtype.replace("'", "''").trim(); if (flavor != null) flavor = flavor.replace("'", "''").trim(); if (artist != null) artist = artist.replace("'", "''").trim(); String statement = " WHERE 1=1"; if (cardname != null) { String[] nameParts = cardname.split(" "); for (String s : nameParts) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_NAME + " LIKE '%" + s + "%' OR " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " LIKE '%" + s.toLowerCase().replace("ae", String.valueOf(Character.toChars(0xC6)[0])) + "%')"; } } /*************************************************************************************/ /** * Reuben's version Differences: Original code is verbose only, but mine * allows for matching exact text, all words, or just any one word. */ if (cardtext != null) { String[] cardTextParts = cardtext.split(" "); // Separate each // individual /** * The following switch statement tests to see which text search * logic was chosen by the user. If they chose the first option (0), * then look for cards with text that includes all words, but not * necessarily the exact phrase. The second option (1) finds cards * that have 1 or more of the chosen words in their text. The third * option (2) searches for the exact phrase as entered by the user. * The 'default' option is impossible via the way the code is * written, but I believe it's also mandatory to include it in case * someone else is perhaps fussing with the code and breaks it. The * if statement at the end is theorhetically unnecessary, because * once we've entered the current if statement, there is no way to * NOT change the statement variable. However, you never really know * who's going to break open your code and fuss around with it, so * it's always good to leave some small safety measures. */ switch (text_logic) { case 0: for (String s : cardTextParts) { if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " NOT LIKE '%" + s.substring(EXCLUDE_TOKEN_START) + "%')"; else statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " LIKE '%" + s + "%')"; } break; case 1: boolean firstRun = true; for (String s : cardTextParts) { if (firstRun) { firstRun = false; if (s.contains(EXCLUDE_TOKEN)) statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " NOT LIKE '%" + s.substring(EXCLUDE_TOKEN_START) + "%')"; else statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " LIKE '%" + s + "%')"; } else { if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " NOT LIKE '%" + s.substring(EXCLUDE_TOKEN_START) + "%')"; else statement += " OR (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " LIKE '%" + s + "%')"; } } statement += ")"; break; case 2: statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ABILITY + " LIKE '%" + cardtext + "%')"; break; default: break; } } /** End Reuben's version */ /** * Reuben's version Differences: Original version only allowed for * including all types, not any of the types or excluding the given * types. */ String supertypes = null; String subtypes = null; if (cardtype != null && !cardtype.equals("-")) { boolean containsSupertype = true; if (cardtype.substring(0, 2).equals("- ")) { containsSupertype = false; } String[] split = cardtype.split(" - "); if (split.length >= 2) { supertypes = split[0].replace(" -", ""); subtypes = split[1].replace(" -", ""); } else if (containsSupertype) { supertypes = cardtype.replace(" -", ""); } else { subtypes = cardtype.replace("- ", ""); } } if (supertypes != null) { String[] supertypesParts = supertypes.split(" "); // Separate each // individual switch (type_logic) { case 0: for (String s : supertypesParts) { if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } break; case 1: boolean firstRun = true; for (String s : supertypesParts) { if (firstRun) { firstRun = false; if (s.contains(EXCLUDE_TOKEN)) statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } else if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " OR (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } statement += ")"; break; case 2: for (String s : supertypesParts) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s + "%')"; } break; default: break; } } if (subtypes != null) { String[] subtypesParts = subtypes.split(" "); // Separate each // individual switch (type_logic) { case 0: for (String s : subtypesParts) { if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } break; case 1: boolean firstRun = true; for (String s : subtypesParts) { if (firstRun) { firstRun = false; if (s.contains(EXCLUDE_TOKEN)) statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " AND ((" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } else if (s.contains(EXCLUDE_TOKEN)) statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s.substring(1) + "%')"; else statement += " OR (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " LIKE '%" + s + "%')"; } statement += ")"; break; case 2: for (String s : subtypesParts) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_TYPE + " NOT LIKE '%" + s + "%')"; } break; default: break; } } /** End Reuben's version */ /*************************************************************************************/ if (flavor != null) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_FLAVOR + " LIKE '%" + flavor + "%')"; } if (artist != null) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_ARTIST + " LIKE '%" + artist + "%')"; } /*************************************************************************************/ /** * Code below added/modified by Reuben. Differences: Original version * only had 'Any' and 'All' options and lacked 'Exclusive' and 'Exact' * matching. In addition, original programming only provided exclusive * results. */ if (!(color.equals("wubrgl") || (color.equals("WUBRGL") && colorlogic == 0))) { boolean firstPrint = true; // Can't contain these colors /** * ...if the chosen color logic was exactly (2) or none (3) of the * selected colors */ if (colorlogic > 1) // if colorlogic is 2 or 3 it will be greater // than 1 { statement += " AND (("; for (byte b : color.getBytes()) { char c = (char) b; if (c > 'a') { if (firstPrint) firstPrint = false; else statement += " AND "; if (c == 'l' || c == 'L') statement += DATABASE_TABLE_CARDS + "." + KEY_COLOR + " NOT GLOB '[CLA]'"; else statement += DATABASE_TABLE_CARDS + "." + KEY_COLOR + " NOT LIKE '%" + Character.toUpperCase(c) + "%'"; } } statement += ") AND ("; } firstPrint = true; // Might contain these colors if (colorlogic < 2) statement += " AND ("; for (byte b : color.getBytes()) { char c = (char) b; if (c < 'a') { if (firstPrint) firstPrint = false; else { if (colorlogic == 1 || colorlogic == 3) statement += " AND "; else statement += " OR "; } if (c == 'l' || c == 'L') statement += DATABASE_TABLE_CARDS + "." + KEY_COLOR + " GLOB '[CLA]'"; else statement += DATABASE_TABLE_CARDS + "." + KEY_COLOR + " LIKE '%" + c + "%'"; } } if (colorlogic > 1) statement += "))"; else statement += ")"; } /** End of addition */ /*************************************************************************************/ if (sets != null) { statement += " AND ("; boolean first = true; for (String s : sets.split("-")) { if (first) { first = false; } else { statement += " OR "; } statement += DATABASE_TABLE_CARDS + "." + KEY_SET + " = '" + s + "'"; } statement += ")"; } if (pow_choice != NOONECARES) { statement += " AND ("; if (pow_choice > STAR) { statement += DATABASE_TABLE_CARDS + "." + KEY_POWER + " " + pow_logic + " " + pow_choice; if (pow_logic.equals("<")) { statement += " AND " + DATABASE_TABLE_CARDS + "." + KEY_POWER + " > " + STAR; } } else if (pow_logic.equals("=")) { statement += DATABASE_TABLE_CARDS + "." + KEY_POWER + " " + pow_logic + " " + pow_choice; } statement += ")"; } if (tou_choice != NOONECARES) { statement += " AND ("; if (tou_choice > STAR) { statement += DATABASE_TABLE_CARDS + "." + KEY_TOUGHNESS + " " + tou_logic + " " + tou_choice; if (tou_logic.equals("<")) { statement += " AND " + DATABASE_TABLE_CARDS + "." + KEY_TOUGHNESS + " > " + STAR; } } else if (tou_logic.equals("=")) { statement += DATABASE_TABLE_CARDS + "." + KEY_TOUGHNESS + " " + tou_logic + " " + tou_choice; } statement += ")"; } if (cmc != -1) { statement += " AND ("; statement += DATABASE_TABLE_CARDS + "." + KEY_CMC + " " + cmcLogic + " " + cmc + ")"; } if (rarity != null) { statement += " AND ("; boolean firstPrint = true; for (int i = 0; i < rarity.length(); i++) { if (firstPrint) { firstPrint = false; } else { statement += " OR "; } statement += DATABASE_TABLE_CARDS + "." + KEY_RARITY + " = " + (int) rarity.toUpperCase().charAt(i) + ""; } statement += ")"; } String tbl = DATABASE_TABLE_CARDS; if (format != null) { if (!(format.equals("Legacy") || format.equals("Vintage"))) { tbl = "(" + DATABASE_TABLE_CARDS + " JOIN " + DATABASE_TABLE_LEGAL_SETS + " ON " + DATABASE_TABLE_CARDS + "." + KEY_SET + "=" + DATABASE_TABLE_LEGAL_SETS + "." + KEY_SET + " AND " + DATABASE_TABLE_LEGAL_SETS + "." + KEY_FORMAT + "='" + format + "')"; } else { statement += " AND NOT " + KEY_SET + "= 'UNH' AND NOT " + KEY_SET + "= 'UG'"; } statement += " AND NOT EXISTS (SELECT * FROM " + DATABASE_TABLE_BANNED_CARDS + " WHERE " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " = " + DATABASE_TABLE_BANNED_CARDS + "." + KEY_NAME + " AND " + DATABASE_TABLE_BANNED_CARDS + "." + KEY_FORMAT + " = '" + format + "' AND " + DATABASE_TABLE_BANNED_CARDS + "." + KEY_LEGALITY + " = " + BANNED + ")"; } if (!backface) { statement += " AND (" + DATABASE_TABLE_CARDS + "." + KEY_NUMBER + " NOT LIKE '%b%')"; } if (set_logic != MOSTRECENTPRINTING && set_logic != ALLPRINTINGS) { statement = " JOIN (SELECT iT" + DATABASE_TABLE_CARDS + "." + KEY_NAME + ", MIN(" + DATABASE_TABLE_SETS + "." + KEY_DATE + ") AS " + KEY_DATE + " FROM " + DATABASE_TABLE_CARDS + " AS iT" + DATABASE_TABLE_CARDS + " JOIN " + DATABASE_TABLE_SETS + " ON iT" + DATABASE_TABLE_CARDS + "." + KEY_SET + " = " + DATABASE_TABLE_SETS + "." + KEY_CODE + " GROUP BY iT" + DATABASE_TABLE_CARDS + "." + KEY_NAME + ") AS FirstPrints" + " ON " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " = FirstPrints." + KEY_NAME + statement; if (set_logic == FIRSTPRINTING) statement = " AND " + DATABASE_TABLE_SETS + "." + KEY_DATE + " = FirstPrints." + KEY_DATE + statement; else statement = " AND " + DATABASE_TABLE_SETS + "." + KEY_DATE + " <> FirstPrints." + KEY_DATE + statement; } if (statement.equals(" WHERE 1=1")) { // If the statement is just this, it means we added nothing return null; } try { String sel = null; for (String s : returnTypes) { if (sel == null) { sel = DATABASE_TABLE_CARDS + "." + s + " AS " + s; } else { sel += ", " + DATABASE_TABLE_CARDS + "." + s + " AS " + s; } } sel += ", " + DATABASE_TABLE_SETS + "." + KEY_DATE; String sql = "SELECT * FROM (SELECT " + sel + " FROM " + tbl + " JOIN " + DATABASE_TABLE_SETS + " ON " + DATABASE_TABLE_CARDS + "." + KEY_SET + " = " + DATABASE_TABLE_SETS + "." + KEY_CODE + statement; if (consolidate) { sql += " ORDER BY " + DATABASE_TABLE_SETS + "." + KEY_DATE + ") GROUP BY " + KEY_NAME + " ORDER BY " + KEY_NAME + " COLLATE UNICODE"; } else { sql += " ORDER BY " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " COLLATE UNICODE" + ", " + DATABASE_TABLE_SETS + "." + KEY_DATE + " DESC)"; } mCursor = mDb.rawQuery(sql, null); } catch (SQLiteException e) { throw new FamiliarDbException(e); } catch (IllegalStateException e) { throw new FamiliarDbException(e); } if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; }
From source file:gov.va.med.imaging.proxy.ImageXChangeHttpCommonsSender.java
/** * Matches a string against a pattern. The pattern contains two special * characters: '*' which means zero or more characters, * * @param pattern/*from w ww .j a v a 2 s. co m*/ * the (non-null) pattern to match against * @param str * the (non-null) string that must be matched against the pattern * @param isCaseSensitive * * @return <code>true</code> when the string matches against the pattern, * <code>false</code> otherwise. */ protected static boolean match(String pattern, String str, boolean isCaseSensitive) { char[] patArr = pattern.toCharArray(); char[] strArr = str.toCharArray(); int patIdxStart = 0; int patIdxEnd = patArr.length - 1; int strIdxStart = 0; int strIdxEnd = strArr.length - 1; char ch; boolean containsStar = false; for (int i = 0; i < patArr.length; i++) { if (patArr[i] == '*') { containsStar = true; break; } } if (!containsStar) { // No '*'s, so we make a shortcut if (patIdxEnd != strIdxEnd) { return false; // Pattern and string do not have the // same size } for (int i = 0; i <= patIdxEnd; i++) { ch = patArr[i]; if (isCaseSensitive && (ch != strArr[i])) { return false; // Character mismatch } if (!isCaseSensitive && (Character.toUpperCase(ch) != Character.toUpperCase(strArr[i]))) { return false; // Character mismatch } } return true; // String matches against pattern } if (patIdxEnd == 0) { return true; // Pattern contains only '*', which matches anything } // Process characters before first star while ((ch = patArr[patIdxStart]) != '*' && (strIdxStart <= strIdxEnd)) { if (isCaseSensitive && (ch != strArr[strIdxStart])) { return false; // Character mismatch } if (!isCaseSensitive && (Character.toUpperCase(ch) != Character.toUpperCase(strArr[strIdxStart]))) { return false; // Character mismatch } patIdxStart++; strIdxStart++; } if (strIdxStart > strIdxEnd) { // All characters in the string are used. Check if only '*'s are // left in the pattern. If so, we succeeded. Otherwise failure. for (int i = patIdxStart; i <= patIdxEnd; i++) { if (patArr[i] != '*') { return false; } } return true; } // Process characters after last star while ((ch = patArr[patIdxEnd]) != '*' && (strIdxStart <= strIdxEnd)) { if (isCaseSensitive && (ch != strArr[strIdxEnd])) { return false; // Character mismatch } if (!isCaseSensitive && (Character.toUpperCase(ch) != Character.toUpperCase(strArr[strIdxEnd]))) { return false; // Character mismatch } patIdxEnd--; strIdxEnd--; } if (strIdxStart > strIdxEnd) { // All characters in the string are used. Check if only '*'s are // left in the pattern. If so, we succeeded. Otherwise failure. for (int i = patIdxStart; i <= patIdxEnd; i++) { if (patArr[i] != '*') { return false; } } return true; } // process pattern between stars. padIdxStart and patIdxEnd point // always to a '*'. while ((patIdxStart != patIdxEnd) && (strIdxStart <= strIdxEnd)) { int patIdxTmp = -1; for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { if (patArr[i] == '*') { patIdxTmp = i; break; } } if (patIdxTmp == patIdxStart + 1) { // Two stars next to each other, skip the first one. patIdxStart++; continue; } // Find the pattern between padIdxStart & padIdxTmp in str between // strIdxStart & strIdxEnd int patLength = (patIdxTmp - patIdxStart - 1); int strLength = (strIdxEnd - strIdxStart + 1); int foundIdx = -1; strLoop: for (int i = 0; i <= strLength - patLength; i++) { for (int j = 0; j < patLength; j++) { ch = patArr[patIdxStart + j + 1]; if (isCaseSensitive && (ch != strArr[strIdxStart + i + j])) { continue strLoop; } if (!isCaseSensitive && (Character.toUpperCase(ch) != Character.toUpperCase(strArr[strIdxStart + i + j]))) { continue strLoop; } } foundIdx = strIdxStart + i; break; } if (foundIdx == -1) { return false; } patIdxStart = patIdxTmp; strIdxStart = foundIdx + patLength; } // All characters in the string are used. Check if only '*'s are left // in the pattern. If so, we succeeded. Otherwise failure. for (int i = patIdxStart; i <= patIdxEnd; i++) { if (patArr[i] != '*') { return false; } } return true; }
From source file:com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.java
protected String guessResultType(String type) { StringBuilder sb = null;/*w w w . ja va 2 s.c om*/ if (type != null) { sb = new StringBuilder(); boolean capNext = false; for (int x = 0; x < type.length(); x++) { char c = type.charAt(x); if (c == '-') { capNext = true; continue; } else if (Character.isLowerCase(c) && capNext) { c = Character.toUpperCase(c); capNext = false; } sb.append(c); } } return (sb != null ? sb.toString() : null); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration.java
/** * Transforms the specified string from delimiter-separated (e.g. <tt>font-size</tt>) * to camel-cased (e.g. <tt>fontSize</tt>). * @param string the string to camelize//from w w w . j a v a 2 s . c o m * @return the transformed string * @see com.gargoylesoftware.htmlunit.javascript.host.dom.DOMStringMap#decamelize(String) */ protected static String camelize(final String string) { if (string == null) { return null; } String result = CamelizeCache_.get(string); if (null != result) { return result; } // not found in CamelizeCache_; convert and store in cache final int pos = string.indexOf('-'); if (pos == -1 || pos == string.length() - 1) { // cache also this strings for performance CamelizeCache_.put(string, string); return string; } final StringBuilder buffer = new StringBuilder(string); buffer.deleteCharAt(pos); buffer.setCharAt(pos, Character.toUpperCase(buffer.charAt(pos))); int i = pos + 1; while (i < buffer.length() - 1) { if (buffer.charAt(i) == '-') { buffer.deleteCharAt(i); buffer.setCharAt(i, Character.toUpperCase(buffer.charAt(i))); } i++; } result = buffer.toString(); CamelizeCache_.put(string, result); return result; }
From source file:com.glaf.core.util.ReflectUtils.java
public static void setFieldValue(Object target, String name, Class<?> type, Object value) { if (target == null || StringUtils.isEmpty(name) || (value != null && !type.isAssignableFrom(value.getClass()))) { return;//from w ww. j a va2s . co m } Class<?> clazz = target.getClass(); try { Method method = clazz .getDeclaredMethod("set" + Character.toUpperCase(name.charAt(0)) + name.substring(1), type); if (!Modifier.isPublic(method.getModifiers())) { method.setAccessible(true); } method.invoke(target, value); } catch (Exception ex) { if (LogUtils.isDebug()) { logger.debug(ex); } try { Field field = clazz.getDeclaredField(name); if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true); } field.set(target, value); } catch (Exception e) { if (LogUtils.isDebug()) { logger.debug(e); } } } }
From source file:de.rrze.idmone.utils.jpwgen.PwGenerator.java
/** * The real password generation is performed in this method * //from w ww . j av a 2 s . c om * @param size * the length of the password * @param pw_flags * the settings for the password * @return the newly created password */ private synchronized static String phonemes(int size, int pw_flags, Random random) { int c, i, len, flags, feature_flags; int prev, should_be; boolean first; String str; char ch; StringBuffer buf = new StringBuffer(); do { buf.delete(0, buf.length()); feature_flags = pw_flags; c = 0; prev = 0; should_be = 0; first = true; should_be = random.nextBoolean() ? VOWEL : CONSONANT; while (c < size) { i = random.nextInt(PW_ELEMENTS.length); str = PW_ELEMENTS[i].getValue(); len = str.length(); flags = PW_ELEMENTS[i].getType(); /* Filter on the basic type of the next element */ if ((flags & should_be) == 0) { continue; } /* Handle the NOT_FIRST flag */ if (first && ((flags & NOT_FIRST) != 0)) continue; /* Don't allow VOWEL followed a Vowel/Dipthong pair */ if (((prev & VOWEL) != 0) && ((flags & VOWEL) != 0) && ((flags & DIPTHONG) != 0)) continue; /* Don't allow us to overflow the buffer */ if (len > size - c) continue; /* * OK, we found an element which matches our criteria, let's do * it! */ buf.append(str); c += len; /* Handle the AMBIGUOUS flag */ if ((pw_flags & PW_AMBIGUOUS) != 0) { int k = -1; for (int j = 0; j < PW_AMBIGUOUS_SYMBOLS.length(); j++) { k = buf.indexOf(String.valueOf(PW_AMBIGUOUS_SYMBOLS.charAt(j))); if (k != -1) break; } if (k != -1) { buf.delete(k, buf.length()); c = buf.length(); } } /* Time to stop? */ if (c >= size) { // System.out.println("BREAK 1: "+c + " - "+size); break; } /* * Handle PW_DIGITS */ if ((pw_flags & PW_DIGITS) != 0) { if (!first && (random.nextInt(10) < 3)) { do { ch = (new Integer(random.nextInt(10))).toString().charAt(0); } while (((pw_flags & PW_AMBIGUOUS) != 0) && (PW_AMBIGUOUS_SYMBOLS.indexOf(ch) != -1)); c++; buf = buf.append(ch); feature_flags &= ~PW_DIGITS; first = true; prev = 0; should_be = random.nextBoolean() ? VOWEL : CONSONANT; continue; } } /* Handle PW_SYMBOLS */ if ((pw_flags & PW_SYMBOLS) != 0) { if (!first && (random.nextInt(10) < 2)) { do { ch = PW_SPECIAL_SYMBOLS.charAt(random.nextInt(PW_SPECIAL_SYMBOLS.length())); } while (((pw_flags & PW_AMBIGUOUS) != 0) && (PW_AMBIGUOUS_SYMBOLS.indexOf(ch) != -1)); c++; buf = buf.append(ch); feature_flags &= ~PW_SYMBOLS; } } else if ((pw_flags & PW_SYMBOLS_REDUCED) != 0) { if (!first && (random.nextInt(10) < 2)) { do { ch = PW_SPECIAL_SYMBOLS_REDUCED .charAt(random.nextInt(PW_SPECIAL_SYMBOLS_REDUCED.length())); } while (((pw_flags & PW_AMBIGUOUS) != 0) && (PW_AMBIGUOUS_SYMBOLS.indexOf(ch) != -1)); c++; buf = buf.append(ch); feature_flags &= ~PW_SYMBOLS_REDUCED; } } /* Handle PW_UPPERS */ if ((pw_flags & PW_UPPERS) != 0) { if ((first || ((flags & CONSONANT) != 0)) && (random.nextInt(10) < 2)) { int lastChar = buf.length() - 1; buf.setCharAt(lastChar, Character.toUpperCase(buf.charAt(lastChar))); feature_flags &= ~PW_UPPERS; } } /* * OK, figure out what the next element should be */ if (should_be == CONSONANT) { should_be = VOWEL; } else { /* should_be == VOWEL */ if (((prev & VOWEL) != 0) || ((flags & DIPTHONG) != 0) || (random.nextInt(10) > 3)) should_be = CONSONANT; else should_be = VOWEL; } prev = flags; first = false; } } while ((feature_flags & (PW_UPPERS | PW_DIGITS | PW_SYMBOLS | PW_SYMBOLS_REDUCED)) != 0); return buf.toString(); }
From source file:com.glaf.core.util.StringTools.java
public static String toCamelCase(String s) { if (s == null) { return null; }//from w w w.j a va 2 s . c om s = s.toLowerCase(); StringBuilder sb = new StringBuilder(s.length()); boolean upperCase = false; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == SEPARATOR) { upperCase = true; } else if (upperCase) { sb.append(Character.toUpperCase(c)); upperCase = false; } else { sb.append(c); } } return sb.toString(); }
From source file:lucee.commons.lang.StringUtil.java
/** * translate a string in hypen notation to a string in camel notation * example:/* w ww.j a v a 2 s . co m*/ * hello-world -> helloWorld * @param str * @return */ public static String hypenToCamelNotation(String str) { if (isEmpty(str)) return str; StringBuilder sb = new StringBuilder(); int len = str.length(); char c; for (int i = 0; i < str.length(); i++) { c = str.charAt(i); if (c == '-') { if (len > ++i) sb.append(Character.toUpperCase(str.charAt(i))); } else sb.append(c); } return sb.toString(); }
From source file:edu.usc.cssl.tacit.classify.naivebayes.services.Vectors2Classify.java
private static ClassifierTrainer getTrainer(String arg) { // parse something like Maxent,gaussianPriorVariance=10,numIterations=20 // first, split the argument at commas. java.lang.String fields[] = arg.split(","); // Massage constructor name, so that MaxEnt, MaxEntTrainer, new // MaxEntTrainer() // all call new MaxEntTrainer() java.lang.String constructorName = fields[0]; Object trainer;/* ww w .j a va 2 s . c o m*/ if (constructorName.indexOf('(') != -1) // if contains (), pass it // though trainer = createTrainer(arg); else { if (constructorName.endsWith("Trainer")) { trainer = createTrainer("new " + constructorName + "()"); // add // parens // if // they // forgot } else { trainer = createTrainer("new " + constructorName + "Trainer()"); // make // trainer // name // from // classifier // name } } // find methods associated with the class we just built Method methods[] = trainer.getClass().getMethods(); // find setters corresponding to parameter names. for (int i = 1; i < fields.length; i++) { java.lang.String nameValuePair[] = fields[i].split("="); java.lang.String parameterName = nameValuePair[0]; java.lang.String parameterValue = nameValuePair[1]; // todo: check // for val // present! java.lang.Object parameterValueObject; try { parameterValueObject = interpreter.eval(parameterValue); } catch (bsh.EvalError e) { throw new IllegalArgumentException( "Java interpreter eval error on parameter " + parameterName + "\n" + e); } boolean foundSetter = false; for (int j = 0; j < methods.length; j++) { // System.out.println("method " + j + " name is " + // methods[j].getName()); // System.out.println("set" + // Character.toUpperCase(parameterName.charAt(0)) + // parameterName.substring(1)); if (("set" + Character.toUpperCase(parameterName.charAt(0)) + parameterName.substring(1)) .equals(methods[j].getName()) && methods[j].getParameterTypes().length == 1) { // System.out.println("Matched method " + // methods[j].getName()); // Class[] ptypes = methods[j].getParameterTypes(); // System.out.println("Parameter types:"); // for (int k=0; k<ptypes.length; k++){ // System.out.println("class " + k + " = " + // ptypes[k].getName()); // } try { java.lang.Object[] parameterList = new java.lang.Object[] { parameterValueObject }; // System.out.println("Argument types:"); // for (int k=0; k<parameterList.length; k++){ // System.out.println("class " + k + " = " + // parameterList[k].getClass().getName()); // } methods[j].invoke(trainer, parameterList); } catch (IllegalAccessException e) { System.out.println("IllegalAccessException " + e); throw new IllegalArgumentException("Java access error calling setter\n" + e); } catch (InvocationTargetException e) { System.out.println("IllegalTargetException " + e); throw new IllegalArgumentException("Java target error calling setter\n" + e); } foundSetter = true; break; } } if (!foundSetter) { System.out.println("Parameter " + parameterName + " not found on trainer " + constructorName); System.out.println("Available parameters for " + constructorName); for (int j = 0; j < methods.length; j++) { if (methods[j].getName().startsWith("set") && methods[j].getParameterTypes().length == 1) { System.out.println(Character.toLowerCase(methods[j].getName().charAt(3)) + methods[j].getName().substring(4)); } } throw new IllegalArgumentException("no setter found for parameter " + parameterName); } } assert (trainer instanceof ClassifierTrainer); return ((ClassifierTrainer) trainer); }