List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:by.zatta.pilight.model.Config.java
@SuppressLint("SimpleDateFormat") public static List<DeviceEntry> update(OriginEntry originEntry) { lastUpdateString = ""; int decimals = -1; int gui_decimals = -1; String name = ""; String value = ""; DecimalFormat digits = new DecimalFormat("#,##0.0");// format to 1 decimal place for (DeviceEntry device : mDevices) { if (device.getNameID().equals(originEntry.getNameID())) { // Log.v(TAG, "updating: " + device.getNameID()); for (SettingEntry sentry : device.getSettings()) { // Log.v(TAG, sentry.getKey()); if (sentry.getKey().equals("name")) { originEntry.setPopularName(sentry.getValue()); name = sentry.getValue(); }/* w w w . j ava2 s .c o m*/ if (sentry.getKey().equals("device-decimals")) { decimals = Integer.valueOf(sentry.getValue()); // Log.v(TAG, sentry.getValue()); } if (sentry.getKey().equals("gui-decimals")) { gui_decimals = Integer.valueOf(sentry.getValue()); switch (gui_decimals) { case 1: digits = new DecimalFormat("#,##0.0");// format to 1 decimal place break; case 2: digits = new DecimalFormat("#,##0.00");// format to 1 decimal place break; case 3: digits = new DecimalFormat("#,##0.000");// format to 1 decimal place break; case 4: digits = new DecimalFormat("#,##0.0000");// format to 1 decimal place break; default: digits = new DecimalFormat("#,##0.0");// format to 1 decimal place break; } } } for (SettingEntry sentry : device.getSettings()) { for (SettingEntry orSentry : originEntry.getSettings()) { if (sentry.getKey().equals(orSentry.getKey())) { sentry.setValue(orSentry.getValue()); if (sentry.getKey().equals("temperature") && (decimals != -1)) { String temp = digits.format( Integer.valueOf(sentry.getValue()) / (Math.pow(10, decimals))) + " \u2103"; if (!value.contains("Temp:")) value = value + "Temp: " + temp + "\n"; } else if (sentry.getKey().equals("humidity") && (decimals != -1)) { String hum = digits.format( Integer.valueOf(sentry.getValue()) / (Math.pow(10, decimals))) + " %"; if (!value.contains("Humidity:")) value = value + "Humidity: " + hum + "\n"; } else if (sentry.getKey().equals("timestamp")) { if (!value.contains("Stamp: ")) value = value + "Stamp: " + new SimpleDateFormat("HH:mm:ss") .format(Long.valueOf(sentry.getValue()) * 1000) + "\n"; } else { char firstChar = orSentry.getKey().charAt(0); char replaceBy = Character.toUpperCase(firstChar); String what = orSentry.getKey().replaceFirst(Character.toString(firstChar), Character.toString(replaceBy)); if (!value.contains(what)) value = value + what + ": " + orSentry.getValue() + "\n"; } } } } } } lastUpdateString = name + "\n" + value; return mDevices; }
From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java
private String capitalize(String s) { if (s == null || s.length() == 0) { return ""; }// ww w. j a v a 2s. c o m char first = s.charAt(0); if (Character.isUpperCase(first)) { return s; } else { return Character.toUpperCase(first) + s.substring(1); } }
From source file:com.gistlabs.mechanize.util.apache.URLEncodedUtils.java
/** * Emcode/escape a portion of a URL, to use with the query part ensure {@code plusAsBlank} is true. * /* ww w. j a va 2 s. co m*/ * @param content the portion to decode * @param charset the charset to use * @param blankAsPlus if {@code true}, then convert space to '+' (e.g. for www-url-form-encoded content), otherwise leave as is. * @return */ private static String urlencode(final String content, final Charset charset, final BitSet safechars, final boolean blankAsPlus) { if (content == null) return null; StringBuilder buf = new StringBuilder(); ByteBuffer bb = charset.encode(content); while (bb.hasRemaining()) { int b = bb.get() & 0xff; if (safechars.get(b)) buf.append((char) b); else if (blankAsPlus && b == ' ') buf.append('+'); else { buf.append("%"); char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX)); char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX)); buf.append(hex1); buf.append(hex2); } } return buf.toString(); }
From source file:com.prowidesoftware.swift.io.parser.SwiftParser.java
/** * Attempt to detect if block 2 refers to an input or output message * @param s the block 2 value (as a FIN value) * @return whether it's an input block 2 (true) or an output one (false) *//*from ww w . j a va 2s . com*/ private boolean isInput(final String s) { // try to find out the in/out type final int i = s.indexOf(':'); if (i >= 0 && (i + 1) < s.length()) { // check for input mark return Character.toUpperCase(s.charAt(i + 1)) == 'I'; } return false; }
From source file:de.xwic.appkit.webbase.table.DefaultColumnLabelProvider.java
/** * @param propertyName//from ww w. ja v a2 s .com * @return */ private String makeGetterName(String s) { if (s == null || s.length() == 0) { return s; } char chars[] = s.toCharArray(); chars[0] = Character.toUpperCase(chars[0]); return "is" + new String(chars); }
From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPProxyConfigurator.java
/** * Matches a string against a pattern. The pattern contains two special * characters: '*' which means zero or more characters, * * @param pattern//w ww .ja va 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. */ private 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.itude.mobile.android.util.StringUtil.java
/** * Capitalizes every word in str /*from w w w . ja v a 2s . co m*/ * * @param str {@link String} * @return Capitalizes {@link String} */ public static String capitalize(String str) { if (str == null || str.length() == 0) return str; boolean capitalizeNext = true; StringBuilder result = new StringBuilder(); for (int i = 0; i < str.length(); ++i) { char ch = str.charAt(i); if (capitalizeNext) result.append(Character.toUpperCase(ch)); else result.append(ch); capitalizeNext = Character.isWhitespace(ch); } return result.toString(); }
From source file:net.sf.jabref.importer.fetcher.GVKParser.java
private BibEntry parseEntry(Element e) { String author = null;//from w w w . j a v a 2s . c om String editor = null; String title = null; String publisher = null; String year = null; String address = null; String series = null; String edition = null; String isbn = null; String issn = null; String number = null; String pagetotal = null; String volume = null; String pages = null; String journal = null; String ppn = null; String booktitle = null; String url = null; String note = null; String quelle = ""; String mak = ""; String subtitle = ""; String entryType = "book"; // Default // Alle relevanten Informationen einsammeln List<Element> datafields = getChildren("datafield", e); for (Element datafield : datafields) { String tag = datafield.getAttribute("tag"); LOGGER.debug("tag: " + tag); // mak if ("002@".equals(tag)) { mak = getSubfield("0", datafield); if (mak == null) { mak = ""; } } //ppn if ("003@".equals(tag)) { ppn = getSubfield("0", datafield); } //author if ("028A".equals(tag)) { String vorname = getSubfield("d", datafield); String nachname = getSubfield("a", datafield); if (author == null) { author = ""; } else { author = author.concat(" and "); } author = author.concat(vorname + " " + nachname); } //author (weiterer) if ("028B".equals(tag)) { String vorname = getSubfield("d", datafield); String nachname = getSubfield("a", datafield); if (author == null) { author = ""; } else { author = author.concat(" and "); } author = author.concat(vorname + " " + nachname); } //editor if ("028C".equals(tag)) { String vorname = getSubfield("d", datafield); String nachname = getSubfield("a", datafield); if (editor == null) { editor = ""; } else { editor = editor.concat(" and "); } editor = editor.concat(vorname + " " + nachname); } //title and subtitle if ("021A".equals(tag)) { title = getSubfield("a", datafield); subtitle = getSubfield("d", datafield); } //publisher and address if ("033A".equals(tag)) { publisher = getSubfield("n", datafield); address = getSubfield("p", datafield); } //year if ("011@".equals(tag)) { year = getSubfield("a", datafield); } //year, volume, number, pages (year bei Zeitschriften (evtl. redundant mit 011@)) if ("031A".equals(tag)) { year = getSubfield("j", datafield); volume = getSubfield("e", datafield); number = getSubfield("a", datafield); pages = getSubfield("h", datafield); } // 036D seems to contain more information than the other fields // overwrite information using that field // 036D also contains information normally found in 036E if ("036D".equals(tag)) { // 021 might have been present if (title != null) { // convert old title (contained in "a" of 021A) to volume if (title.startsWith("@")) { // "@" indicates a number title = title.substring(1); } else { // we nevertheless keep the old title data } number = title; } //title and subtitle title = getSubfield("a", datafield); subtitle = getSubfield("d", datafield); volume = getSubfield("l", datafield); } //series and number if ("036E".equals(tag)) { series = getSubfield("a", datafield); number = getSubfield("l", datafield); String kor = getSubfield("b", datafield); if (kor != null) { series = series + " / " + kor; } } //note if ("037A".equals(tag)) { note = getSubfield("a", datafield); } //edition if ("032@".equals(tag)) { edition = getSubfield("a", datafield); } //isbn if ("004A".equals(tag)) { final String isbn10 = getSubfield("0", datafield); final String isbn13 = getSubfield("A", datafield); if (isbn10 != null) { isbn = isbn10; } if (isbn13 != null) { isbn = isbn13; } } // Hochschulschriftenvermerk // Bei einer Verlagsdissertation ist der Ort schon eingetragen if ("037C".equals(tag)) { if (address == null) { address = getSubfield("b", datafield); if (address != null) { address = removeSortCharacters(address); } } String st = getSubfield("a", datafield); if ((st != null) && st.contains("Diss")) { entryType = "phdthesis"; } } //journal oder booktitle /* Problematiken hier: Sowohl fr Artikel in * Zeitschriften als fr Beitrge in Bchern * wird 027D verwendet. Der Titel mu je nach * Fall booktitle oder journal zugeordnet * werden. Auch bei Zeitschriften werden hier * ggf. Verlag und Ort angegeben (sind dann * eigentlich berflssig), whrend bei * Buchbeitrgen Verlag und Ort wichtig sind * (sonst in Kategorie 033A). */ if ("027D".equals(tag)) { journal = getSubfield("a", datafield); booktitle = getSubfield("a", datafield); address = getSubfield("p", datafield); publisher = getSubfield("n", datafield); } //pagetotal if ("034D".equals(tag)) { pagetotal = getSubfield("a", datafield); if (pagetotal != null) { // S, S. etc. entfernen pagetotal = pagetotal.replaceAll(" S\\.?$", ""); } } // Behandlung von Konferenzen if ("030F".equals(tag)) { address = getSubfield("k", datafield); if (!"proceedings".equals(entryType)) { subtitle = getSubfield("a", datafield); } entryType = "proceedings"; } // Wenn eine Verlagsdiss vorliegt if ("phdthesis".equals(entryType) && (isbn != null)) { entryType = "book"; } //Hilfskategorien zur Entscheidung @article //oder @incollection; hier knnte man auch die //ISBN herausparsen als Erleichterung fr das //Auffinden der Quelle, die ber die //SRU-Schnittstelle gelieferten Daten zur //Quelle unvollstndig sind (z.B. nicht Serie //und Nummer angegeben werden) if ("039B".equals(tag)) { quelle = getSubfield("8", datafield); } if ("046R".equals(tag) && ((quelle == null) || quelle.isEmpty())) { quelle = getSubfield("a", datafield); } // URLs behandeln if ("009P".equals(tag) && ("03".equals(datafield.getAttribute("occurrence")) || "05".equals(datafield.getAttribute("occurrence"))) && (url == null)) { url = getSubfield("a", datafield); } } // Abfangen von Nulleintraegen if (quelle == null) { quelle = ""; } // Nichtsortierzeichen entfernen if (author != null) { author = removeSortCharacters(author); } if (editor != null) { editor = removeSortCharacters(editor); } if (title != null) { title = removeSortCharacters(title); } if (subtitle != null) { subtitle = removeSortCharacters(subtitle); } // Dokumenttyp bestimmen und Eintrag anlegen if (mak.startsWith("As")) { entryType = "misc"; if (quelle.contains("ISBN")) { entryType = "incollection"; } if (quelle.contains("ZDB-ID")) { entryType = "article"; } } else if (mak.isEmpty()) { entryType = "misc"; } else if (mak.startsWith("O")) { entryType = "misc"; // FIXME: online only available in Biblatex //entryType = "online"; } /* * Wahrscheinlichkeit, dass ZDB-ID * vorhanden ist, ist grer als ISBN bei * Buchbeitrgen. Daher bei As?-Stzen am besten immer * dann @incollection annehmen, wenn weder ISBN noch * ZDB-ID vorhanden sind. */ BibEntry result = new BibEntry(IdGenerator.next(), entryType); // Zuordnung der Felder in Abhngigkeit vom Dokumenttyp if (author != null) { result.setField(FieldName.AUTHOR, author); } if (editor != null) { result.setField(FieldName.EDITOR, editor); } if (title != null) { result.setField(FieldName.TITLE, title); } if (!Strings.isNullOrEmpty(subtitle)) { // ensure that first letter is an upper case letter // there could be the edge case that the string is only one character long, therefore, this special treatment // this is Apache commons lang StringUtils.capitalize (https://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/StringUtils.html#capitalize%28java.lang.String%29), but we don't want to add an additional dependency ('org.apache.commons:commons-lang3:3.4') StringBuilder newSubtitle = new StringBuilder( Character.toString(Character.toUpperCase(subtitle.charAt(0)))); if (subtitle.length() > 1) { newSubtitle.append(subtitle.substring(1)); } result.setField("subtitle", newSubtitle.toString()); } if (publisher != null) { result.setField(FieldName.PUBLISHER, publisher); } if (year != null) { result.setField(FieldName.YEAR, year); } if (address != null) { result.setField("address", address); } if (series != null) { result.setField("series", series); } if (edition != null) { result.setField("edition", edition); } if (isbn != null) { result.setField(FieldName.ISBN, isbn); } if (issn != null) { result.setField(FieldName.ISSN, issn); } if (number != null) { result.setField(FieldName.NUMBER, number); } if (pagetotal != null) { result.setField("pagetotal", pagetotal); } if (pages != null) { result.setField(FieldName.PAGES, pages); } if (volume != null) { result.setField(FieldName.VOLUME, volume); } if (journal != null) { result.setField(FieldName.JOURNAL, journal); } if (ppn != null) { result.setField("ppn_GVK", ppn); } if (url != null) { result.setField(FieldName.URL, url); } if (note != null) { result.setField("note", note); } if ("article".equals(entryType) && (journal != null)) { result.setField(FieldName.JOURNAL, journal); } else if ("incollection".equals(entryType) && (booktitle != null)) { result.setField("booktitle", booktitle); } return result; }
From source file:com.microsoft.tfs.core.clients.versioncontrol.localworkspace.IgnoreFile.java
/** * Similar to .NET's String.Compare(String, Int32, String, Int32, Int32, * StringComparison), but always does a locale-invariant case-insensitive * comparison instead of honoring a StringComparison arg. * <p>//from w ww .j a v a 2 s . com * This method is here and not in {@link LocaleInvariantStringHelpers} * because it does bounds checking in the .NET way, which differs from * Java's {@link String#regionMatches(boolean, int, String, int, int)} * enough to keep it separate. But the match algorithm at the bottom could * be useful in a new method there. */ private int compareCaseInsensitive(final String strA, final int offsetA, final String strB, final int offsetB, final int length) { if (strA == null && strB != null) { return -1; } else if (strA != null && strB == null) { return 1; } // .NET is documented to throw when length > 0 and one is not null else if ((strA == null || strB == null) && length > 0) { throw new IndexOutOfBoundsException("length cannot be > 0 with null string arguments"); //$NON-NLS-1$ } // End values exclusive final int endA = offsetA + length; final int endB = offsetB + length; if (endA > strA.length()) { throw new IndexOutOfBoundsException("offsetA + length is past the end of strA"); //$NON-NLS-1$ } if (endB > strB.length()) { throw new IndexOutOfBoundsException("offsetB + length is past the end of strB"); //$NON-NLS-1$ } /* * We checked that we won't walk off the end of either string, so we can * use just one of the end indices (endA) to limit our loop. */ for (int iA = offsetA, iB = offsetB; iA < endA; iA++, iB++) { char a = strA.charAt(iA); char b = strB.charAt(iB); if (a != b) { // Try both as upper case a = Character.toUpperCase(a); b = Character.toUpperCase(b); if (a != b) { // Try both as lower case a = Character.toLowerCase(a); b = Character.toLowerCase(b); if (a != b) { // Unicode difference works return a - b; } } } } // Got to end of both segments without a difference return 0; }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static boolean isUpperCase(final CharSequence sequence) { if (isEmpty(sequence)) { return true; }/*w w w .j a va 2s . c o m*/ for (int i = 0; i < sequence.length(); i++) { char c = sequence.charAt(i); if (c != Character.toUpperCase(c)) { return false; } } return true; }