List of usage examples for java.lang Character toString
public static String toString(int codePoint)
From source file:com.nridge.core.io.gson.RangeJSON.java
/** * Saves the data field to the writer stream specified as a parameter. * * @param aWriter Json writer stream instance. * @param aFieldRange Field range instance. * * @throws IOException I/O related exception. */// ww w. j a v a 2 s . co m public void save(JsonWriter aWriter, FieldRange aFieldRange) throws IOException { aWriter.name(IO.JSON_RANGE_OBJECT_NAME).beginObject(); IOJSON.writeNameValue(aWriter, IO.JSON_TYPE_MEMBER_NAME, Field.typeToString(aFieldRange.getType())); if (aFieldRange.getType() == Field.Type.Text) { IOJSON.writeNameValue(aWriter, IO.JSON_DELIMITER_MEMBER_NAME, Character.toString(aFieldRange.getDelimiterChar())); String singleString = StrUtl.collapseToSingle(aFieldRange.getItems(), aFieldRange.getDelimiterChar()); aWriter.name(IO.JSON_VALUE_MEMBER_NAME).value(singleString); } else { switch (aFieldRange.getType()) { case Long: IOJSON.writeNameValue(aWriter, "min", aFieldRange.getMinLong()); IOJSON.writeNameValue(aWriter, "max", aFieldRange.getMaxLong()); break; case Integer: IOJSON.writeNameValue(aWriter, "min", aFieldRange.getMinInteger()); IOJSON.writeNameValue(aWriter, "max", aFieldRange.getMaxInteger()); break; case Double: IOJSON.writeNameValue(aWriter, "min", aFieldRange.getMinDouble()); IOJSON.writeNameValue(aWriter, "max", aFieldRange.getMaxDouble()); break; case DateTime: IOJSON.writeNameValue(aWriter, "min", aFieldRange.getMinString()); IOJSON.writeNameValue(aWriter, "max", aFieldRange.getMaxString()); break; } } aWriter.endObject(); }
From source file:ASCII2NATIVE.java
/** * Native character to ascii string. * //www . ja va 2 s .c o m * @param c * native character * @return ascii string */ private static String char2Ascii(char c) { if (c > 255) { StringBuilder sb = new StringBuilder(); sb.append(PREFIX); int code = (c >> 8); String tmp = Integer.toHexString(code); if (tmp.length() == 1) { sb.append("0"); } sb.append(tmp); code = (c & 0xFF); tmp = Integer.toHexString(code); if (tmp.length() == 1) { sb.append("0"); } sb.append(tmp); return sb.toString(); } else { return Character.toString(c); } }
From source file:Main.java
/** * @param source/*from w w w .ja v a 2 s . co m*/ * @param quoteChar * @param escapedChars * @param quotingTriggers * @param escapeChar * @param force * @return the String quoted and escaped * @since 1.5.1 */ public static String quoteAndEscape(String source, char quoteChar, final char[] escapedChars, final char[] quotingTriggers, char escapeChar, boolean force) { if (source == null) { return null; } if (!force && source.startsWith(Character.toString(quoteChar)) && source.endsWith(Character.toString(quoteChar))) { return source; } String escaped = escape(source, escapedChars, escapeChar); boolean quote = false; if (force) { quote = true; } else if (!escaped.equals(source)) { quote = true; } else { for (int i = 0; i < quotingTriggers.length; i++) { if (escaped.indexOf(quotingTriggers[i]) > -1) { quote = true; break; } } } if (quote) { return quoteChar + escaped + quoteChar; } return escaped; }
From source file:com.ameron32.apps.tapnotes._trial._demo.fragment.expandable.ExampleExpandableDataProvider.java
public ExampleExpandableDataProvider() { final String groupItems = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; final String childItems = "abc"; mData = new LinkedList<>(); for (int i = 0; i < groupItems.length(); i++) { //noinspection UnnecessaryLocalVariable final long groupId = i; final String groupText = Character.toString(groupItems.charAt(i)); final int groupSwipeReaction = RecyclerViewSwipeManager.REACTION_CAN_SWIPE_LEFT | RecyclerViewSwipeManager.REACTION_CAN_SWIPE_RIGHT; final ConcreteGroupData group = new ConcreteGroupData(groupId, groupText, groupSwipeReaction); final List<ChildData> children = new ArrayList<>(); for (int j = 0; j < childItems.length(); j++) { final long childId = group.generateNewChildId(); final String childText = Character.toString(childItems.charAt(j)); final int childSwipeReaction = RecyclerViewSwipeManager.REACTION_CAN_SWIPE_LEFT | RecyclerViewSwipeManager.REACTION_CAN_SWIPE_RIGHT; children.add(new ConcreteChildData(childId, childText, childSwipeReaction)); }//w w w . j av a 2 s. c o m mData.add(new Pair<GroupData, List<ChildData>>(group, children)); } }
From source file:controllers.FormsController.java
private static JsonNode generateFieldFromProperty(String fieldName) { Properties props = getPropertyFile(); ObjectNode formElememt = Json.newObject(); formElememt.put("name", fieldName); formElememt.put("label", props.getProperty(fieldName + "_label")); formElememt.put("type", props.getProperty(fieldName + "_type")); if (formElememt.get("type").asText().equalsIgnoreCase("list")) { try {//from ww w . j a v a 2 s . c o m Class<?> cl = Class.forName("models.fixed." + Character.toString(fieldName.charAt(0)).toUpperCase() + fieldName.substring(1)); List<?> l = Ebean.find(cl).findList(); formElememt.put("options", Json.toJson(l)); } catch (ClassNotFoundException ex) { Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex); } } ObjectNode validations = Json.newObject(); validations.put("required", props.getProperty(fieldName + "_validations_required")); validations.put("pattern", props.getProperty(fieldName + "_validations_pattern")); formElememt.put("validations", validations); ObjectNode messages = Json.newObject(); messages.put("invalid", props.getProperty(fieldName + "_validationmessages_invalid")); messages.put("required", props.getProperty(fieldName + "_validationmessages_required")); messages.put("pattern", props.getProperty(fieldName + "_validationmessages_pattern")); formElememt.put("validationMessages", messages); return Json.toJson(formElememt); }
From source file:com.microsoft.azure.management.datalake.store.uploader.StringExtensions.java
/** * Finds the index in the given buffer of a newline character, either the first or the last (based on the parameters). * If a combined newline (\r\n), the index returned is that of the last character in the sequence. * * @param buffer The buffer to search in. * @param startOffset The index of the first byte to start searching at. * @param length The number of bytes to search, starting from the given startOffset. * @param reverse If true, searches from the startOffset down to the beginning of the buffer. If false, searches upwards. * @param encoding Indicates the type of encoding to use for the buffered bytes. * @param delimiter Optionally indicates the delimiter to consider as the "new line", which MUST BE a single character. If null, the default is '\\r', '\\n' and '\\r\\n'. * @return The index of the closest newline character in the sequence (based on direction) that was found. Returns -1 if not found. *///from www .jav a 2s . c o m public static int findNewline(byte[] buffer, int startOffset, int length, boolean reverse, Charset encoding, String delimiter) { if (buffer.length == 0 || length == 0) { return -1; } // define the bytes per character to use int bytesPerChar; if (encoding.equals(StandardCharsets.UTF_16) || encoding.equals(StandardCharsets.UTF_16BE) || encoding.equals(StandardCharsets.UTF_16LE)) { bytesPerChar = 2; } else if (encoding.equals(StandardCharsets.US_ASCII) || encoding.equals(StandardCharsets.UTF_8)) { bytesPerChar = 1; } else { throw new IllegalArgumentException( "Only the following encodings are allowed: UTF-8, UTF-16, UTF-16BE, UTF16-LE and ASCII"); } if (delimiter != null && !StringUtils.isEmpty(delimiter) && delimiter.length() > 1) { throw new IllegalArgumentException( "The delimiter must only be a single character or unspecified to represent the CRLF delimiter"); } if (delimiter != null && !StringUtils.isEmpty(delimiter)) { // convert the byte array back to a String int startOfSegment = reverse ? startOffset - length + 1 : startOffset; String bytesToString = new String(buffer, startOfSegment, length, encoding); if (!bytesToString.contains(delimiter)) { // didn't find the delimiter. return -1; } // the index is returned, which is 0 based, so our loop must include the zero case. int numCharsToDelim = reverse ? bytesToString.lastIndexOf(delimiter) : bytesToString.indexOf(delimiter); int toReturn = 0; for (int i = 0; i <= numCharsToDelim; i++) { toReturn += Character.toString(bytesToString.charAt(startOfSegment + i)).getBytes(encoding).length; } // we get the total number of bytes, but we want to return the index (which starts at 0) // so we subtract 1 from the total number of bytes to get the final byte index. return toReturn - 1; } //endOffset is a 'sentinel' value; we use that to figure out when to stop searching int endOffset = reverse ? startOffset - length : startOffset + length; // if we are starting at the end, we need to move toward the front enough to grab the right number of bytes startOffset = reverse ? startOffset - (bytesPerChar - 1) : startOffset; if (startOffset < 0 || startOffset >= buffer.length) { throw new IndexOutOfBoundsException( "Given start offset is outside the bounds of the given buffer. In reverse cases, the start offset is modified to ensure we check the full size of the last character"); } // make sure that the length we are traversing is at least as long as a single character if (length < bytesPerChar) { throw new IllegalArgumentException( "length must be at least as long as the length, in bytes, of a single character"); } if (endOffset < -1 || endOffset > buffer.length) { throw new IndexOutOfBoundsException( "Given combination of startOffset and length would execute the search outside the bounds of the given buffer."); } int bufferEndOffset = reverse ? startOffset : startOffset + length; int result = -1; for (int charPos = startOffset; reverse ? charPos != endOffset : charPos + bytesPerChar - 1 < endOffset; charPos = reverse ? charPos - 1 : charPos + 1) { char c; if (bytesPerChar == 1) { c = (char) buffer[charPos]; } else { String temp = new String(buffer, charPos, bytesPerChar, encoding); if (StringUtils.isEmpty(temp)) { continue; } else { c = temp.toCharArray()[0]; } } if (isNewline(c, delimiter)) { result = charPos + bytesPerChar - 1; break; } } if ((delimiter == null || StringUtils.isEmpty(delimiter)) && !reverse && result < bufferEndOffset - bytesPerChar) { char c; if (bytesPerChar == 1) { c = (char) buffer[result + bytesPerChar]; } else { String temp = new String(buffer, result + 1, bytesPerChar, encoding); if (StringUtils.isEmpty(temp)) { // this can occur if the number of bytes for characters in the string result in an empty string (an invalid code for the given encoding) // in this case, that means that we are done for the default delimiter. return result; } else { c = temp.toCharArray()[0]; } } if (isNewline(c, delimiter)) { //we originally landed on a \r character; if we have a \r\n character, advance one position to include that result += bytesPerChar; } } return result; }
From source file:au.org.ala.delta.translation.delta.DeltaWriter.java
/** * Converts a list of id/value pairs into a string of the format * <id1>,<value1> <id2>,<value2>. In addition, if sequential ids in * the list have the same value, they will be condensed in the form * <id1-idx>,<value1>./*from ww w.j av a2 s . c o m*/ */ public <T> String valueRangeToString(List<Pair<Integer, T>> values, char rangeSeparator, String valueSeparator, boolean valueLast) { if (values.isEmpty()) { return ""; } StringBuilder builder = new StringBuilder(); T previousValue = null; int firstInRange = -1; int previousNum = -1; for (Pair<Integer, T> value : values) { int id = value.getFirst(); if (!value.getSecond().equals(previousValue) || (id != previousNum + 1)) { if (firstInRange >= 0) { appendRange(builder, previousValue, firstInRange, previousNum, Character.toString(rangeSeparator), valueSeparator, valueLast); } firstInRange = value.getFirst(); previousValue = value.getSecond(); } previousNum = value.getFirst(); } appendRange(builder, previousValue, firstInRange, previousNum, Character.toString(rangeSeparator), valueSeparator, valueLast); return builder.toString(); }
From source file:com.zimbra.qa.unittest.TestDocument.java
/** * Tests documents created with the {@code Note} flag set. *//* ww w . j a v a2 s.co m*/ public void testNote() throws Exception { // Create a document and a note. ZMailbox mbox = TestUtil.getZMailbox(USER_NAME); String folderId = Integer.toString(Mailbox.ID_FOLDER_BRIEFCASE); ZDocument doc = TestUtil.createDocument(mbox, folderId, NAME_PREFIX + "-doc.txt", "text/plain", "doc".getBytes()); ZDocument note = TestUtil.createDocument(mbox, folderId, NAME_PREFIX + "-note.txt", "text/plain", "note".getBytes(), true); String flags = Character.toString(ZItem.Flag.note.getFlagChar()); mbox.updateItem(note.getId(), null, null, flags, null); // Confirm that the Note flag is set when getting the documents. doc = mbox.getDocument(doc.getId()); assertEquals(null, doc.getFlags()); assertEquals(flags, note.getFlags()); // Test searching for notes. List<String> ids = TestUtil.search(mbox, "in:briefcase tag:\\note", ZSearchParams.TYPE_DOCUMENT); assertEquals(1, ids.size()); assertEquals(note.getId(), ids.get(0)); }
From source file:com.websystique.springmvc.youtube_api.Function.java
public String chuyenchuoistring(String s) { String regex = "?;."; String[] charArray = new String[s.length()]; String[] stringArray = new String[s.length()]; char[] delimArray = new char[regex.length()]; int i = 0;/*from w w w.j a va2 s .co m*/ // Outer loop outer: for (int k = 0; k < s.length(); k++) { // Inner loop inner: for (int j = 0; j < delimArray.length; j++) { // The if checks the current character in the string with each // delimiter character and proceeds till it checks all the // delimiters if (s.charAt(k) != regex.charAt(j)) { continue inner; } else { // Else block is reached when any of the character in the // string is a delimiter // Check if the current array position is null(which means // nothing is assigned so far) and move to the next position // only if it is not null if (stringArray[i] != null) { i++; } // Assign the delimiter in the output array stringArray[i] = Character.toString(s.charAt(k)); // Increment to the next position in the array i++; continue outer; } } // This if is to avoid null being appended to the string if (stringArray[i] == null) { stringArray[i] = ""; } // Add the character(since it is not a delimiter) to the current // index i stringArray[i] += Character.toString(s.charAt(k)); } String[] splitStrArr = new String[i + 1]; int m = 0; s = ""; do { splitStrArr[m] = stringArray[m]; if (splitStrArr[m] != null) { if (splitStrArr[m].equals(".") || splitStrArr[m].equals("?") || splitStrArr[m].equals(";")) { s += " " + splitStrArr[m] + "####"; } else { s += splitStrArr[m]; } } // System.out.println(splitStrArr[m]); m++; } while (m <= i); System.out.println(s); return s; }
From source file:edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageHelper.java
/** * Create a string holding either the character or its hex-encoding. *//*www.j a v a 2s . c o m*/ private static String hexEncodeCharacter(char c) { if ((c < 0x21) || (c > 0x7e) || (HEX_ENCODE_SOURCES.indexOf(c) >= 0)) { return new StringBuilder().append(HEX_ESCAPE_CHAR).append(toHexDigit(c / 16)).append(toHexDigit(c % 16)) .toString(); } else { return Character.toString(c); } }