List of usage examples for java.lang Character charValue
@HotSpotIntrinsicCandidate public char charValue()
From source file:org.xwiki.annotation.maintainer.AbstractAnnotationMaintainer.java
/** * Helper function to adjust passed annotation to make sure it is unique in the content. * //from w w w . ja va 2 s . c o m * @param annotation the annotation to ensure uniqueness for * @param content the content in which the annotation must be unique * @param cStart precomputed position where the annotation starts, passed here for cache reasons * @param cLeftSize precomputed length of the context to the left side of the selection inside the annotation * context, passed here for cache reasons * @param sLength precomputed length of the annotation selection, passed here for cache reasons * @param cRightSize precomputed length of the context to the right side of the selection inside the annotation, * passed here for cache reasons */ private void ensureUnique(Annotation annotation, String content, int cStart, int cLeftSize, int sLength, int cRightSize) { // find out if there is another encounter of the selection text & context than the one at cStart List<Integer> occurrences = getOccurrences(content, annotation.getSelectionInContext(), cStart); if (occurrences.size() == 0) { // it appears only once, it's done return; } // enlarge the context to the left and right with one character, until it is unique boolean isUnique = false; int cLength = cLeftSize + sLength + cRightSize; // size expansion of the context of the annotation such as it becomes unique int expansionLeft = 0; int expansionRight = 0; // the characters corresponding to the ends of the expanded context, to compare with all other occurrences and // check if they're unique // TODO: an odd situation can happen by comparing characters: at each expansion position there's another // occurrence that matches, therefore an unique context is never found although it exists // TODO: maybe expansion should be considered by words? char charLeft = content.charAt(cStart - expansionLeft); char charRight = content.charAt(cStart + cLength + expansionRight - 1); while (!isUnique) { boolean updated = false; // get the characters at left and right and expand, but only if the positions are valid. If one stops being // valid, only the other direction will be expanded in search of a new context if (cStart - expansionLeft - 1 > 0) { expansionLeft++; charLeft = content.charAt(cStart - expansionLeft); updated = true; } if (cStart + cLength + expansionRight + 1 <= content.length()) { expansionRight++; charRight = content.charAt(cStart + cLength + expansionRight - 1); updated = true; } if (!updated) { // couldn't update the context to the left nor to the right break; } if (charLeft == ' ' || charRight == ' ') { // don't consider uniqueness from space chars continue; } // assume it's unique isUnique = true; // and check again all occurrences for (int occurence : occurrences) { // get the chars relative to the current occurrence at the respective expansion positions to the right // and left Character occurenceCharLeft = getSafeCharacter(content, occurence - expansionLeft); Character occurenceCharRight = getSafeCharacter(content, occurence + cLength + expansionRight - 1); if ((occurenceCharLeft != null && occurenceCharLeft.charValue() == charLeft) && (occurenceCharRight != null && occurenceCharRight.charValue() == charRight)) { isUnique = false; break; } } } if (isUnique) { // update the context with the new indexes // expand the context to the entire word that it touches (just to make more sense and not depend with only // one letter) expansionLeft = expansionLeft + toNextWord(content, cStart - expansionLeft, true); expansionRight = expansionRight + toNextWord(content, cStart + cLength + expansionRight, false); // normally selection is not updated here, only the context therefore we don't set original selection String contextLeft = content.substring(cStart - expansionLeft, cStart + cLeftSize); String selection = content.substring(cStart + cLeftSize, cStart + cLeftSize + sLength); String contextRight = content.substring(cStart + cLeftSize + sLength, cStart + cLength + expansionRight); annotation.setSelection(selection, contextLeft, contextRight); } else { // left the loop for other reasons: for example couldn't expand context // leave it unchanged there's not much we could do anyway } }
From source file:org.opengroupware.logic.authz.OGoAuthzFetchContext.java
/** * Combines the given permission sets into a single one. * Example: 'lr', 'r', 'rw' will return 'lrw'. * /*from w w w .j av a2 s . c o m*/ * @param _perms - a collection of permission sets * @return the combined set of permission characters */ public String unionPermissions(final Collection<String> _perms) { int size; if (_perms == null || (size = _perms.size()) == 0) return noPermission; /* shortcut */ if (size == 1 && _perms instanceof List<?>) return ((List<String>) _perms).get(0); // TBD: make this stuff sane final Set<Character> a = new HashSet<Character>(8); for (final String perms : _perms) { for (char permission : perms.toCharArray()) a.add(permission); } if ((size = a.size()) == 0) return noPermission; final StringBuilder sb = new StringBuilder(size); for (Character c : a) sb.append(c.charValue()); return sb.toString(); }
From source file:com.tasktop.internal.hp.qc.core.model.comments.mylyn3_8.HtmlStreamTokenizer_m3_8.java
/** * Replaces (in-place) HTML escapes in a StringBuffer with their corresponding characters. * /*from w w w . ja v a 2s.c om*/ * @deprecated use {@link StringEscapeUtils#unescapeHtml(String)} instead */ @Deprecated public static StringBuffer unescape(StringBuffer sb) { int i = 0; // index into the unprocessed section of the buffer int j = 0; // index into the processed section of the buffer while (i < sb.length()) { char ch = sb.charAt(i); if (ch == '&') { int start = i; String escape = null; for (i = i + 1; i < sb.length(); i++) { ch = sb.charAt(i); if (!Character.isLetterOrDigit(ch) && !(ch == '#' && i == (start + 1))) { escape = sb.substring(start + 1, i); break; } } if (i == sb.length() && i != (start + 1)) { escape = sb.substring(start + 1); } if (escape != null) { Character character = parseReference(escape); if (character != null && !((0x0A == character || 0x0D == character || 0x09 == ch) || (character >= 0x20 && character <= 0xD7FF) || (character >= 0xE000 && character <= 0xFFFD) || (character >= 0x10000 && character <= 0x10FFFF))) { // Character is an invalid xml character // http://www.w3.org/TR/REC-xml/#charsets character = null; } if (character != null) { ch = character.charValue(); } else { // not an HTML escape; rewind i = start; ch = '&'; } } } sb.setCharAt(j, ch); i++; j++; } sb.setLength(j); return sb; }
From source file:com.prowidesoftware.swift.model.field.Field.java
/** * Tell if this field is of a given letter option. * letter is case sensitive/*from w w w.j ava2s .c o m*/ */ public boolean isLetterOption(final char c) { final Character l = letterOption(); if (l != null) { return l.charValue() == c; } return false; }
From source file:com.glaf.core.util.DBUtils.java
public static boolean isTableColumn(String columnName) { if (columnName == null || columnName.trim().length() < 2 || columnName.trim().length() > 26) { return false; }//from w w w.j a v a 2s . c om char[] sourceChrs = columnName.toCharArray(); Character chr = Character.valueOf(sourceChrs[0]); if (!((chr.charValue() == 95) || (65 <= chr.charValue() && chr.charValue() <= 90) || (97 <= chr.charValue() && chr.charValue() <= 122))) { return false; } for (int i = 1; i < sourceChrs.length; i++) { chr = Character.valueOf(sourceChrs[i]); if (!((chr.charValue() == 95) || (47 <= chr.charValue() && chr.charValue() <= 57) || (65 <= chr.charValue() && chr.charValue() <= 90) || (97 <= chr.charValue() && chr.charValue() <= 122))) { return false; } } return true; }
From source file:com.glaf.core.util.DBUtils.java
public static boolean isTableName(String sourceString) { if (sourceString == null || sourceString.trim().length() < 2 || sourceString.trim().length() > 25) { return false; }/*from w w w .j a v a2s . co m*/ char[] sourceChrs = sourceString.toCharArray(); Character chr = Character.valueOf(sourceChrs[0]); if (!((chr.charValue() == 95) || (65 <= chr.charValue() && chr.charValue() <= 90) || (97 <= chr.charValue() && chr.charValue() <= 122))) { return false; } for (int i = 1; i < sourceChrs.length; i++) { chr = Character.valueOf(sourceChrs[i]); if (!((chr.charValue() == 95) || (47 <= chr.charValue() && chr.charValue() <= 57) || (65 <= chr.charValue() && chr.charValue() <= 90) || (97 <= chr.charValue() && chr.charValue() <= 122))) { return false; } } return true; }
From source file:org.protorabbit.model.impl.DefaultEngine.java
private static IParameter[] getParams(String paramsString) { paramsString = paramsString.trim();//from w w w .j ava2 s . c o m // for simple case of one item if (paramsString.indexOf(",") == -1 && paramsString.startsWith("\"") && paramsString.endsWith("\"")) { String text = paramsString.substring(0, paramsString.length()); IParameter param = getParameter(text, new Character('\"')); IParameter[] params = new IParameter[1]; params[0] = param; return params; } // otherwise we have quoted text or JSON objects ArrayList<IParameter> params = new ArrayList<IParameter>(); int index = 0; int paramStart = index; boolean inQuote = false; boolean inArray = false; boolean inObject = false; int braceDepth = 0; int arrayDepth = 0; Character lastToken = null; while (index < paramsString.length()) { char c = paramsString.charAt(index); switch (c) { // string case '\"': { if (inQuote) { // if not escaped end the quote if (index > 0 && paramsString.charAt(index - 1) != '\\') { inQuote = false; lastToken = new Character('\"'); } } else if (!inArray && !inObject) { inQuote = true; lastToken = new Character('\"'); } break; } case '[': { if (!inQuote) { arrayDepth += 1; lastToken = new Character('['); inArray = true; } break; } case ']': { if (!inQuote) { arrayDepth -= 1; if (arrayDepth == 0 && braceDepth == 0) { inArray = false; String text = paramsString.substring(paramStart, index + 1).trim(); IParameter param = getParameter(text, lastToken); params.add(param); paramStart = index + 1; lastToken = new Character(']'); } } break; } case '{': { if (!inQuote) { if (braceDepth == 0) { inObject = true; paramStart = index; lastToken = new Character('{'); } braceDepth += 1; } break; } case '}': { if (!inQuote) { braceDepth -= 1; lastToken = new Character('}'); } if (braceDepth == 0 && arrayDepth == 0 && lastToken != null && lastToken.charValue() != ']' && lastToken.charValue() != '}') { inObject = false; String text = paramsString.substring(paramStart, index + 1).trim(); IParameter param = getParameter(text, lastToken); params.add(param); paramStart = index + 1; lastToken = null; } break; } // could be a number or boolean case ',': { if (!inQuote && !inArray && !inObject) { String text = paramsString.substring(paramStart, index).trim(); IParameter param = getParameter(text, lastToken); params.add(param); paramStart = index + 1; lastToken = null; } break; } } index += 1; } // get the trailing param if there is one if (paramStart < paramsString.length()) { String text = paramsString.substring(paramStart, paramsString.length()); IParameter param = getParameter(text, lastToken); params.add(param); } IParameter[] a = new IParameter[params.size()]; return params.toArray(a); }
From source file:net.ymate.platform.commons.lang.TreeObject.java
/** * * * @param c */ public TreeObject(Character c) { _object = c != null ? c.charValue() : Character.MIN_VALUE; _type = TYPE_CHAR; }
From source file:net.ymate.platform.commons.lang.TreeObject.java
/** * - Char/*from w w w .j a v a 2 s . c om*/ * * @param c */ public TreeObject add(Character c) { return add(c != null ? c.charValue() : Character.MIN_CODE_POINT, TYPE_CHAR); }
From source file:com.neovisionaries.security.Digest.java
/** * Update the wrapped {@code MessageDigest} object with the * given input data./*from w ww .j a v a2s . c o m*/ * * <p> * This method is an alias of {@link #update(char) * update}{@code (input.charValue())}. * </p> * * @param input * Input data. * * @return * {@code this} object. * * @since 1.4 */ public Digest update(Character input) { if (input == null) { return this; } return update(input.charValue()); }