public static String[] parseTokenizedString(String string2BeParsed, String demiliter) { StringTokenizer tokenizer = new StringTokenizer(string2BeParsed, demiliter); String[] choices = new String[tokenizer.countTokens()]; int index = 0; // each token is the display name for the column while (tokenizer.hasMoreTokens()) { choices[index] = tokenizer.nextToken(); index++; } return choices; }
/** * Parses the given accelerator text, and converts it to an accelerator key code. * * @param acceleratorText the accelerator text * @result the SWT key code, or 0 if there is no accelerator */ private int convertAccelerator(String acceleratorText) { int accelerator = 0; StringTokenizer stok = new StringTokenizer(acceleratorText, "+"); // $NON-NLS-1$ int keyCode = -1; boolean hasMoreTokens = stok.hasMoreTokens(); while (hasMoreTokens) { String token = stok.nextToken(); hasMoreTokens = stok.hasMoreTokens(); // Every token except the last must be one of the modifiers // Ctrl, Shift, or Alt. if (hasMoreTokens) { int modifier = Action.findModifier(token); if (modifier != 0) { accelerator |= modifier; } else { // Leave if there are none return 0; } } else { keyCode = Action.findKeyCode(token); } } if (keyCode != -1) { accelerator |= keyCode; } return accelerator; }
private void createStaticDeclaration(StringTokenizer tokenizer) { StringBuffer stringBuffer = new StringBuffer(); tokenizer.nextToken(); tokenizer.nextToken(); String variableName = tokenizer.nextToken(); stringBuffer.setLength(0); stringBuffer.append(" "); stringBuffer.append(PUBLIC); stringBuffer.append(" "); stringBuffer.append(STATIC); stringBuffer.append(" "); stringBuffer.append(STRING); stringBuffer.append(" "); stringBuffer.append(variableName); stringBuffer.append(";"); System.out.println(stringBuffer); }
private String getConvertedOrthogonalSampleDataRepresentation(String sOldRepresentation) { StringTokenizer strtok = new StringTokenizer(sOldRepresentation, ","); // $NON-NLS-1$ StringBuffer sbNewRepresentation = new StringBuffer(""); // $NON-NLS-1$ while (strtok.hasMoreTokens()) { String sElement = strtok.nextToken().trim(); if (sElement.startsWith("H")) // $NON-NLS-1$ // Orthogonal sample data is for a // stock chart (Orthogonal sample // data CANNOT // be text { StringTokenizer strStockTokenizer = new StringTokenizer(sElement); sbNewRepresentation.append(strStockTokenizer.nextToken().trim().substring(1)); } else { sbNewRepresentation.append(sElement); } sbNewRepresentation.append(","); // $NON-NLS-1$ } return sbNewRepresentation.toString().substring(0, sbNewRepresentation.length() - 1); }
private void createClassFile() { try { String line; BufferedReader in = new BufferedReader(new FileReader(dir + javaFileName)); while ((line = in.readLine()) != null) { line = removeEverythingAfterEquals( line); // This handles the case where there is no space before the equal sign StringTokenizer tokenizer = new StringTokenizer(line); if (tokenizer.countTokens() > 1) { String firstToken = tokenizer.nextToken(); String secondToken = tokenizer.nextToken(); if (firstToken.equals(PACKAGE)) { System.out.println(line); System.out.println(); createNLSImportStatement(); System.out.println(); } else if (firstToken.equals(PUBLIC) && secondToken.equals(INTERFACE)) { String className = tokenizer.nextToken(); System.out.println(); createClassSignature(className); System.out.println(); createBundleNameDeclaration(); System.out.println(); createClassConstructor(className); System.out.println(); createStaticInitializer(className); } else { if (firstToken.equals(PUBLIC) && secondToken.equals(STATIC)) createStaticDeclaration(tokenizer); else System.out.println(line); // not interested in this line, no changes } } else System.out.println(line); // not interested in this line, no changes } } catch (IOException e) { e.printStackTrace(); } }
/** * Determines if currently tracing a category * * @param category * @return true if tracing category, false otherwise */ public static boolean isTracing(String category) { if (!isDebugging()) return false; String traceFilter = Platform.getDebugOption(PLUGIN_ID + TRACEFILTER_LOCATION); if (traceFilter != null) { StringTokenizer tokenizer = new StringTokenizer(traceFilter, ","); // $NON-NLS-1$ while (tokenizer.hasMoreTokens()) { String cat = tokenizer.nextToken().trim(); if (category.equals(cat)) { return true; } } } return false; }
@Test public void testSourceInputOutputWriters() throws IOException { _sourceInputsBuffer = new DataOutputBuffer(16348 * 4); _sourceInputsTrackingFilter = new URLFPBloomFilter(100000, NUM_HASH_FUNCTIONS, NUM_BITS); String sourceDomainURL = "http://sourcedomain.com/foo"; URLFPV2 sourceFP = URLUtils.getURLFPV2FromCanonicalURL(sourceDomainURL); String urls[] = {"http://somedomain.com/foo", "http://someother.com/bar"}; for (String url : urls) { URLFPV2 fp = URLUtils.getURLFPV2FromCanonicalURL(url); // double insert and validate actual single insertion trackPotentialLinkSource(fp, url, sourceFP); trackPotentialLinkSource(fp, url, sourceFP); } // validate data ... TextBytes firstVersion = new TextBytes(); firstVersion.set(_sourceInputsBuffer.getData(), 0, _sourceInputsBuffer.getLength()); StringTokenizer tokenizer = new StringTokenizer(firstVersion.toString(), "\n"); int itemIndex = 0; while (tokenizer.hasMoreElements()) { String nextLine = tokenizer.nextToken(); String splits[] = nextLine.split("\t"); // validate fp URLFPV2 fp = URLUtils.getURLFPV2FromCanonicalURL(urls[itemIndex]); Assert.assertEquals(fp.getDomainHash(), Long.parseLong(splits[0])); // validate actual url ... Assert.assertEquals(splits[1], urls[itemIndex]); itemIndex++; } // reset output buffer ... _sourceInputsBuffer = new DataOutputBuffer(16348 * 4); // and source bloom filter ... _sourceInputsTrackingFilter = new URLFPBloomFilter(10000000, NUM_HASH_FUNCTIONS, NUM_BITS); importLinkSourceData(sourceFP, firstVersion); // second text should match first .. TextBytes secondVersion = new TextBytes(); secondVersion.set(_sourceInputsBuffer.getData(), 0, _sourceInputsBuffer.getLength()); Assert.assertEquals(firstVersion, secondVersion); }
/** * Parses the input string to a GRB object. * * @param string The input string. * @return The RGB object represented the string. */ protected RGB parseString(String string) { int colors[] = ColorUtil.getRGBs(string); if (colors != null) return new RGB(colors[0], colors[1], colors[2]); StringTokenizer st = new StringTokenizer(string, " ,()"); // $NON-NLS-1$ if (!st.hasMoreTokens()) return null; int[] rgb = new int[] {0, 0, 0}; int index = 0; while (st.hasMoreTokens()) { try { rgb[index] = Integer.decode(st.nextToken()).intValue(); if (rgb[index] < 0 || rgb[index] > 255) return null; index++; } catch (Exception e) { return null; } } return new RGB(rgb[0], rgb[1], rgb[2]); }
/** Create the relationship of Java key to properties key */ private HashMap createMapping() { mapping = new HashMap(); try { String line; BufferedReader in = new BufferedReader(new FileReader(dir + javaFileName)); while ((line = in.readLine()) != null) { StringTokenizer tokenizer = new StringTokenizer(line); int numberOfTokens = tokenizer.countTokens(); if (numberOfTokens > 5) { String firstToken = tokenizer.nextToken(); String secondToken = tokenizer.nextToken(); tokenizer.nextToken(); tokenizer.nextToken(); String key = tokenizer.nextToken(); String value = tokenizer.nextToken(); if (firstToken.equals(PUBLIC) && secondToken.equals(STATIC)) { if (numberOfTokens == 6) { // handle "=" with key and value both in one token because there was no space before // the equal sign int offset = key.indexOf('='); String key1 = key.substring(0, offset); String key2 = key.substring(offset + 2, key.length() - 2); mapping.put(key2, key1); } else if (numberOfTokens == 7) { // handle " =" and "= " with key and value both in different tokens if (value.charAt(0) == '=') { value = value.substring(2, value.length() - 2); } else { key = key.substring(0, key.length() - 1); } mapping.put(value, key); } else if (numberOfTokens == 8) { // handle " = " with key and value both in different tokens value = tokenizer.nextToken(); value = value.substring(1, value.length() - 2); mapping.put(value, key); } else { System.out.println(key + " - I do not understand this line!!!"); } } } } } catch (IOException e) { e.printStackTrace(); } return mapping; }