List of usage examples for java.lang Character toString
public static String toString(int codePoint)
From source file:org.apache.lucene.benchmark.byTask.tasks.WriteLineDocTaskTest.java
public void testMultiThreaded() throws Exception { Path file = getWorkDir().resolve("one-line"); PerfRunData runData = createPerfRunData(file, false, ThreadingDocMaker.class.getName()); final WriteLineDocTask wldt = new WriteLineDocTask(runData); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread("t" + i) { @Override/*from ww w.j a v a 2 s . c om*/ public void run() { try { wldt.doLogic(); } catch (Exception e) { throw new RuntimeException(e); } } }; } for (Thread t : threads) t.start(); for (Thread t : threads) t.join(); wldt.close(); Set<String> ids = new HashSet<>(); try (BufferedReader br = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { String line = br.readLine(); assertHeaderLine(line); // header line is written once, no matter how many threads there are for (int i = 0; i < threads.length; i++) { line = br.readLine(); String[] parts = line.split(Character.toString(WriteLineDocTask.SEP)); assertEquals(3, parts.length); // check that all thread names written are the same in the same line String tname = parts[0].substring(parts[0].indexOf('_')); ids.add(tname); assertEquals(tname, parts[1].substring(parts[1].indexOf('_'))); assertEquals(tname, parts[2].substring(parts[2].indexOf('_'))); } // only threads.length lines should exist assertNull(br.readLine()); assertEquals(threads.length, ids.size()); } }
From source file:edu.psu.citeseerx.updates.IndexUpdateManager.java
/** * Builds a list of author normalizations to create more flexible * author search./* w ww .j ava 2s .co m*/ * @param names * @return */ private static List<String> buildAuthorNorms(List<String> names) { HashSet<String> norms = new HashSet<String>(); for (String name : names) { name = name.replaceAll("[^\\p{L} ]", ""); StringTokenizer st = new StringTokenizer(name); String[] tokens = new String[st.countTokens()]; int counter = 0; while (st.hasMoreTokens()) { tokens[counter] = st.nextToken(); counter++; } norms.add(joinStringArray(tokens)); if (tokens.length > 2) { String[] n1 = new String[tokens.length]; for (int i = 0; i < tokens.length; i++) { if (i < tokens.length - 1) { n1[i] = Character.toString(tokens[i].charAt(0)); } else { n1[i] = tokens[i]; } } String[] n2 = new String[tokens.length]; for (int i = 0; i < tokens.length; i++) { if (i > 0 && i < tokens.length - 1) { n2[i] = Character.toString(tokens[i].charAt(0)); } else { n2[i] = tokens[i]; } } norms.add(joinStringArray(n1)); norms.add(joinStringArray(n2)); } if (tokens.length > 1) { String[] n3 = new String[2]; n3[0] = tokens[0]; n3[1] = tokens[tokens.length - 1]; String[] n4 = new String[2]; n4[0] = Character.toString(tokens[0].charAt(0)); n4[1] = tokens[tokens.length - 1]; norms.add(joinStringArray(n3)); norms.add(joinStringArray(n4)); } } ArrayList<String> normList = new ArrayList<String>(); for (Iterator<String> it = norms.iterator(); it.hasNext();) { normList.add(it.next()); } return normList; }
From source file:com.livinglogic.ul4.FunctionFormat.java
public static String call(BigInteger obj, String formatString, Locale locale) { IntegerFormat format = new IntegerFormat(formatString); if (locale == null) locale = Locale.ENGLISH;//from w w w. j av a2 s .c o m String output = null; boolean neg = obj.signum() < 0; if (neg) obj = obj.negate(); switch (format.type) { case 'b': output = obj.toString(2); break; case 'c': if (neg || obj.compareTo(new BigInteger("65535")) > 0) throw new RuntimeException("value out of bounds for c format"); output = Character.toString((char) obj.intValue()); break; case 'd': output = obj.toString(); break; case 'o': output = obj.toString(8); break; case 'x': output = obj.toString(16); break; case 'X': output = obj.toString(16).toUpperCase(); break; case 'n': // FIXME: locale formatting output = obj.toString(); break; } return formatIntegerString(output, neg, format); }
From source file:org.ardverk.daap.DaapUtil.java
private static int parseHexToInt(int hex) { switch (hex) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'A': return 10; case 'a': return 10; case 'B': return 11; case 'b': return 11; case 'C': return 12; case 'c': return 12; case 'D': return 13; case 'd': return 13; case 'E': return 14; case 'e': return 14; case 'F': return 15; case 'f': return 15; default://from w w w . j a v a 2s .c om throw new NumberFormatException("'" + Character.toString((char) hex) + "'"); } }
From source file:com.webcohesion.enunciate.modules.javascript_client.JavaScriptClientModule.java
protected String packageToNamespace(String pckg) { if (pckg == null) { return null; } else {//from w w w .j a va 2 s .com StringBuilder ns = new StringBuilder(); for (StringTokenizer toks = new StringTokenizer(pckg, "."); toks.hasMoreTokens();) { String tok = toks.nextToken(); ns.append(Character.toString(tok.charAt(0)).toUpperCase()); if (tok.length() > 1) { ns.append(tok.substring(1)); } if (toks.hasMoreTokens()) { ns.append("."); } } return ns.toString(); } }
From source file:org.artifactory.util.RepoLayoutUtils.java
/** * Creates a regular expression based on the given path pattern and layout * * @param repoLayout Repo layout to target * @param patternToUse Pattern to translate * @param failOnUnknownToken Throw exception if the pattern contains an unknown token (neither reserved nor custom) * @param hasVersionTokens indicates if the pattern contains version tokens * @return Regular expression of given path *//* w w w. ja v a 2s.c o m*/ public static String generateRegExpFromPattern(RepoLayout repoLayout, String patternToUse, boolean failOnUnknownToken, boolean hasVersionTokens) { List<String> tokenAppearance = Lists.newArrayList(); StringBuilder itemPathPatternRegExpBuilder = new StringBuilder(); boolean withinToken = false; boolean withinCustomToken = false; StringBuilder currentTokenBuilder = new StringBuilder(); StringBuilder customRegExTokenBuilder = new StringBuilder(); for (char c : patternToUse.toCharArray()) { if (('[' == c) && !withinToken && !withinCustomToken) { withinToken = true; } else if ((']' == c) && withinToken && !withinCustomToken) { withinToken = false; String currentToken = currentTokenBuilder.toString(); currentTokenBuilder.delete(0, currentTokenBuilder.length()); if (isReservedToken(currentToken)) { appendToken(itemPathPatternRegExpBuilder, currentToken, tokenAppearance, getTokenRegExp(currentToken, repoLayout, hasVersionTokens)); } else if (customRegExTokenBuilder.length() != 0) { appendToken(itemPathPatternRegExpBuilder, currentToken, tokenAppearance, customRegExTokenBuilder.toString()); customRegExTokenBuilder.delete(0, customRegExTokenBuilder.length()); } else { String errorMessage = "The token '[" + currentToken + "]' is unknown. If this is not intended, " + "please verify the token name for correctness or add a mapping for this token using the " + "'[$NAME<REGEXP>]' syntax."; if (log.isDebugEnabled()) { log.debug("Error occurred while generating regular expressions from the repository layout " + "pattern '{}': {}", patternToUse, errorMessage); } if (failOnUnknownToken) { throw new IllegalArgumentException(errorMessage); } } } else if ('<' == c) { withinCustomToken = true; } else if ('>' == c) { withinCustomToken = false; } else if (withinCustomToken) { customRegExTokenBuilder.append(c); } else if (!withinToken) { appendNonReservedToken(itemPathPatternRegExpBuilder, Character.toString(c)); } else { currentTokenBuilder.append(c); } } return itemPathPatternRegExpBuilder.toString(); }
From source file:me.taylorkelly.mywarp.bukkit.util.FormattingUtils.java
/** * Creates a two-column-layout from the given strings, using the given character as padding in between with the given * total width. The left column will be aligned on the left, the right column on the right of the given width. *//from www. j av a 2 s .c o m * @param leftColumn the contents of the left column * @param rightColumn the contents of the right column * @param pad the padding character * @param totalWidth the horizontal width that should be covered by the layout * @return the formatted string */ public static String twoColumnAlign(String leftColumn, String rightColumn, char pad, int totalWidth) { int leftWidth = getWidth(leftColumn); int rightWidth = getWidth(rightColumn); totalWidth -= leftWidth + rightWidth; if (totalWidth > 0) { return leftColumn + StringUtils.repeat(Character.toString(pad), totalWidth / getWidth(pad)) + rightColumn; } // If both columns together are larger than the totalWidth, the larger // one is trimmed until it fits. int separatorWidth = getWidth(pad); totalWidth -= separatorWidth; if (leftWidth > rightWidth) { leftColumn = trim(leftColumn, leftWidth + totalWidth); } else { rightColumn = trim(rightColumn, rightWidth + totalWidth); } return leftColumn + pad + rightColumn; }
From source file:com.ettrema.zsync.Upload.java
/** * Returns an InputStream containing a complete ZSync upload (Params, Relocate stream, and ByteRange stream), * ready to be sent as the body of a PUT request. <p/> * // www . jav a 2 s . c o m * Note: In this implementation, any temporary file used to store the RelocateRanges will be automatically deleted when this stream * is closed, so a second invocation of this method on the same Upload object is likely to throw an exception. * Therefore, this method should be used only once per Upload object. * * @return The complete ZSync upload * @throws UnsupportedEncodingException * @throws IOException */ public InputStream getInputStream() throws UnsupportedEncodingException, IOException { List<InputStream> streamList = new ArrayList<InputStream>(); /* * The getParams and getRelocStream must be terminated by a single LF character. */ streamList.add(IOUtils.toInputStream(getParams(), CHARSET)); streamList.add(IOUtils.toInputStream(RELOCATE + ": ", CHARSET)); streamList.add(getRelocStream()); /* Prepend the data portion with a blank line. */ streamList.add(IOUtils.toInputStream(Character.toString(LF), CHARSET)); streamList.add(getDataStream()); return new SequenceInputStream(new IteratorEnum<InputStream>(streamList)); }
From source file:com.livinglogic.ul4.FunctionFormat.java
public static String call(long obj, String formatString, Locale locale) { IntegerFormat format = new IntegerFormat(formatString); if (locale == null) locale = Locale.ENGLISH;/*from w w w.j a v a 2 s.c om*/ String output = null; boolean neg = obj < 0; if (neg) obj = -obj; switch (format.type) { case 'b': output = Long.toBinaryString(obj); break; case 'c': if (neg || obj > 0xffff) throw new RuntimeException("value out of bounds for c format"); output = Character.toString((char) obj); break; case 'd': output = Long.toString(obj); break; case 'o': output = Long.toOctalString(obj); break; case 'x': output = Long.toHexString(obj); break; case 'X': output = Long.toHexString(obj).toUpperCase(); break; case 'n': // FIXME: locale formatting output = Long.toString(obj); break; } return formatIntegerString(output, neg, format); }
From source file:com.near.chimerarevo.fragments.PostsRecyclerFragment.java
private void addItem(final JSONObject jObject) throws JSONException { HashMap<String, String> map = new HashMap<>(); map.put(Constants.KEY_ID, String.valueOf(jObject.getInt(Constants.KEY_ID))); map.put(Constants.KEY_TITLE, jObject.getString(Constants.KEY_TITLE)); String cat = JSONUtils.getCategory(jObject); if (cat.trim().equalsIgnoreCase("") || cat.length() < 1) cat = Character.toString(jObject.getString(Constants.KEY_TYPE).charAt(0)).toUpperCase() + jObject.getString(Constants.KEY_TYPE).substring(1); map.put(Constants.KEY_DATE, jObject.getString(Constants.KEY_DATE) + " | " + cat); map.put(Constants.KEY_IMG, jObject.getString(Constants.KEY_IMG)); map.put(Constants.KEY_TYPE, jObject.getString(Constants.KEY_TYPE)); map.put(Constants.KEY_URL, jObject.getString(Constants.KEY_URL)); arrayList.add(map);/*from w w w. ja va 2s.c o m*/ mAdapter.notifyItemInserted(numEntries); }