List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:ClassPath.java
/** * Search for classes in given path.//from w ww . jav a 2 s . com */ public ClassPath(String class_path) { this.class_path = class_path; List vec = new ArrayList(); for (StringTokenizer tok = new StringTokenizer(class_path, System.getProperty("path.separator")); tok .hasMoreTokens();) { String path = tok.nextToken(); if (!path.equals("")) { File file = new File(path); try { if (file.exists()) { if (file.isDirectory()) { vec.add(new Dir(path)); } else { vec.add(new Zip(new ZipFile(file))); } } } catch (IOException e) { System.err.println("CLASSPATH component " + file + ": " + e); } } } paths = new PathEntry[vec.size()]; vec.toArray(paths); }
From source file:com.ajitkbaral.entitygenerator.controller.GenerateController.java
@RequestMapping(method = RequestMethod.POST) public String indexPost(HttpServletRequest request, HttpServletResponse response) { String result = ""; String packageName = request.getParameter("packageName"); String className = request.getParameter("className"); String variableNames = request.getParameter("variableNames"); String variableTypes = request.getParameter("variableTypes"); String defaultPath = request.getParameter("fullPath"); String filePath = packageName.replace(".", "\\"); String finalFilePath = defaultPath + "\\" + filePath; String finalFilePathWithEntity = finalFilePath + "\\" + className + ".java"; System.out.println("Variables and types " + variableNames + " " + variableTypes); if (!variableNames.equals("") && !variableTypes.equals("")) { List<String> variableNameList = new ArrayList<String>(); List<String> variableTypeList = new ArrayList<String>(); StringTokenizer variableNameTokenizer = new StringTokenizer(variableNames, ","); while (variableNameTokenizer.hasMoreTokens()) { variableNameList.add(variableNameTokenizer.nextToken()); }/*ww w. jav a 2 s. c o m*/ StringTokenizer variableTypeTokenizer = new StringTokenizer(variableTypes, ","); while (variableTypeTokenizer.hasMoreTokens()) { variableTypeList.add(variableTypeTokenizer.nextToken()); } System.out.println(variableNameList.toString() + " " + variableTypeList.toString()); try { File fileFolder = new File(finalFilePath); if (!fileFolder.exists()) { fileFolder.mkdirs(); } FileWriter fileWriter = new FileWriter(finalFilePathWithEntity); String content = GenerateClass.packageNameContent(packageName) + GenerateClass.classNameContent(className) + GenerateClass.variableDecleration(variableNameList, variableTypeList) + GenerateClass.defaultConstructor(className) + GenerateClass.overrideConstructor(className, variableNameList, variableTypeList) + GenerateClass.getter(variableNameList, variableTypeList) + GenerateClass.setter(variableNameList, variableTypeList) + GenerateClass.close(); fileWriter.write(content); fileWriter.close(); System.out.println("DONE"); result = finalFilePathWithEntity; } catch (IOException ioe) { result = ioe.getMessage() + ". Please Try again"; } } else { result = "Error"; } return result; }
From source file:com.chinamobile.bcbsp.examples.connectedcomponent.CCVertexLiteNew.java
@Override public void fromString(String vertexData) throws Exception { String[] buffer = new String[2]; StringTokenizer str = new StringTokenizer(vertexData, Constants.KV_SPLIT_FLAG); if (str.hasMoreElements()) { buffer[0] = str.nextToken();/* w ww . j a v a 2 s . co m*/ } else { throw new Exception(); } if (str.hasMoreElements()) { buffer[1] = str.nextToken(); } str = new StringTokenizer(buffer[0], Constants.SPLIT_FLAG); if (str.countTokens() != 2) { throw new Exception(); } this.vertexID = Integer.valueOf(str.nextToken()); float tmp = Float.valueOf(str.nextToken()); this.vertexValue = (int) tmp; if (buffer[1].length() > 0) { // There has edges. str = new StringTokenizer(buffer[1], Constants.SPACE_SPLIT_FLAG); while (str.hasMoreTokens()) { CCEdgeLiteNew edge = new CCEdgeLiteNew(); edge.fromString(str.nextToken()); this.edgesList.add(edge); } } }
From source file:jobimtext.example.annotators.ParseAnnotator.java
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { StringTokenizer tok = new StringTokenizer(jcas.getDocumentText(), "\n"); int b = 0;/* w w w .j a v a2 s. c om*/ int si = 0; int idxLine = 0; // add sentence while (tok.hasMoreElements()) { String line = tok.nextToken(); String[] sl = line.split("\t"); String strSentence = sl[0]; Sentence sentence = new Sentence(jcas, b, b + strSentence.length()); sentence.setPosTagString( new Annotation(jcas, sentence.getEnd() + 1, sentence.getEnd() + 1 + sl[1].length())); sentence.setParsesString(new Annotation(jcas, sentence.getPosTagString().getEnd() + 1, sentence.getPosTagString().getEnd() + 1 + sl[2].length())); sentence.setParsesTreeString(new Annotation(jcas, sentence.getParsesString().getEnd() + 1, sentence.getParsesString().getEnd() + 1 + sl[3].length())); sentence.setPosTreeString(new Annotation(jcas, sentence.getParsesTreeString().getEnd() + 1, sentence.getParsesTreeString().getEnd() + 1 + sl[4].length())); // String[] splitSentence = strSentence.split(" "); String[] splitPosTags = sl[1].split(" "); // if (splitSentence.length != splitPosTags.length) { // getLogger().log(Level.WARNING, // "Line "+idxLine+": Length of POS tag String and number of tokens in sentence differ"); // } List<Token> ts = new ArrayList<Token>(); if (!tokenizePosStanf) { si = 0; for (int i = 0; i < splitPosTags.length; i++) { int idx = splitPosTags[i].lastIndexOf("/"); Token token; // System.out.println(strSentence.substring(token.getBegin(),token.getEnd())); String strToken = splitPosTags[i].substring(0, idx); strToken = clean(strToken); strToken = strToken.replaceAll("-LRB-", "("); strToken = strToken.replaceAll("-LCB-", "{"); strToken = strToken.replaceAll("-RCB-", "}"); strSentence = strSentence.replaceAll("\\]", "("); strToken = strToken.replaceAll("-RRB-", ")"); strSentence = strSentence.replaceAll("\\]", ")"); if (strToken.equals("-RRB-") || strToken.equals("-LRB-")) { token = new Token(jcas, b + si, b + si + 1); si += 1; } else if (strSentence.substring(si).startsWith(strToken)) { token = new Token(jcas, b + si, b + si + strToken.length()); si += strToken.length(); } else if (strToken.matches("^[^a-zA-Z]+$")) { int six = 0; // System.out.println(strSentence.substring(si)); while (strSentence.length() > (si + six) && strSentence.substring(si + six, si + six + 1).matches("[^a-zA-Z]")) { six++; } token = new Token(jcas, b + si, b + si + six); si += six; // token = null; } else { token = new Token(jcas, b + si, b + si + idx); si += idx; } while (strSentence.length() > si && (strSentence.substring(si).matches("^[\\s].*") || strSentence.charAt(si) == 160)) { si += 1; } token.addToIndexes(); POS pos = new POS(jcas, token.getBegin(), token.getEnd()); int p = splitPosTags[i].lastIndexOf("/"); String[] postag = new String[] { splitPosTags[i].substring(0, p), splitPosTags[i].substring(p + 1) }; if (!postag[0].equals(token.getCoveredText())) { getLogger().log(Level.WARNING, "Line " + idxLine + ": Token and POS tag token are different ( " + token.getCoveredText() + " != " + postag[0] + " )"); //System.out.println("Line " + idxLine + ": Token and POS tag token are different ( " + token.getCoveredText() + " != " + postag[0] + " )"); } pos.setPosValue(postag[1]); token.setPos(pos); ts.add(token); } annotateParses(ts, sentence.getParsesTreeString()); } else { si = sentence.getPosTagString().getBegin(); // System.out.println(sentence.getPosTagString().getCoveredText()); for (String t : splitPosTags) { int idx = t.lastIndexOf("/"); Token token = new Token(jcas, si, si + idx); si += t.length() + 1; // System.out.println(token.getCoveredText() + "\t" + t); token.addToIndexes(); } sentence.setEnd(sentence.getPosTagString().getEnd()); } b = b + line.length() + 1; sentence.addToIndexes(); idxLine++; } }
From source file:com.l2jfree.gameserver.datatables.StaticObjects.java
public static L2StaticObjectInstance parse(String line) { StringTokenizer st = new StringTokenizer(line, ";"); st.nextToken(); //Pass over static object name (not used in server) int id = Integer.parseInt(st.nextToken()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); int z = Integer.parseInt(st.nextToken()); int type = Integer.parseInt(st.nextToken()); String texture = st.nextToken(); int map_x = Integer.parseInt(st.nextToken()); int map_y = Integer.parseInt(st.nextToken()); StatsSet npcDat = new StatsSet(); npcDat.set("npcId", id); npcDat.set("level", 0); npcDat.set("jClass", "staticobject"); npcDat.set("baseSTR", 0); npcDat.set("baseCON", 0); npcDat.set("baseDEX", 0); npcDat.set("baseINT", 0); npcDat.set("baseWIT", 0); npcDat.set("baseMEN", 0); npcDat.set("baseShldDef", 0); npcDat.set("baseShldRate", 0); npcDat.set("baseAccCombat", 38); npcDat.set("baseEvasRate", 38); npcDat.set("baseCritRate", 38); //npcDat.set("name", ""); npcDat.set("collision_radius", 10); npcDat.set("collision_height", 10); npcDat.set("fcollision_radius", 10); npcDat.set("fcollision_height", 10); npcDat.set("sex", "male"); npcDat.set("type", ""); npcDat.set("baseAtkRange", 0); npcDat.set("baseMpMax", 0); npcDat.set("baseCpMax", 0); npcDat.set("rewardExp", 0); npcDat.set("rewardSp", 0); npcDat.set("basePAtk", 0); npcDat.set("baseMAtk", 0); npcDat.set("basePAtkSpd", 0); npcDat.set("aggroRange", 0); npcDat.set("baseMAtkSpd", 0); npcDat.set("rhand", 0); npcDat.set("lhand", 0); npcDat.set("armor", 0); npcDat.set("baseWalkSpd", 0); npcDat.set("baseRunSpd", 0); npcDat.set("name", ""); npcDat.set("baseHpMax", 1); npcDat.set("baseHpReg", 3.e-3f); npcDat.set("baseMpReg", 3.e-3f); npcDat.set("basePDef", 1); npcDat.set("baseMDef", 1); L2CreatureTemplate template = new L2CreatureTemplate(npcDat); L2StaticObjectInstance obj = new L2StaticObjectInstance(IdFactory.getInstance().getNextId(), template, id); obj.setType(type);/*from w ww . j a va 2s . c o m*/ obj.getPosition().setXYZ(x, y, z); obj.setMap(texture, map_x, map_y); obj.spawnMe(); return obj; }
From source file:com.quui.chat.Preprocessor.java
/** * Tokenizes the user input, then every word thats not in the stopwords-list * is stemmed and these are returned.//from ww w. j av a 2 s. com * @param s The input to answer to. * @return Returns those words (stemmed) that will be processed */ public Vector<String> preProcess(String s) { if (s == null) { throw new NullPointerException("Word to process is null."); } StringTokenizer tokenizer = new StringTokenizer(s, " .!?,;:^\"$%&/\\()[]#'+*<>|\t-"); String[] tokens = new String[tokenizer.countTokens()]; int i = 0; while (tokenizer.hasMoreElements()) { tokens[i] = tokenizer.nextToken(); i++; } Vector<String> result = new Vector<String>(); for (String element : tokens) { String firstStem = element; if (this.isWordNetEnabled) { firstStem = WNLookup.getStaticStem(element); if (firstStem.equals("")) { firstStem = element; } } if (!this.stopwords.contains(firstStem) && firstStem.trim().length() > 1) { if (firstStem.trim().equals("")) { throw new NullPointerException("Empty token!"); } result.add(firstStem); } } return result; }
From source file:Main.java
public static String[] getTokens(String line, String delim) { if (line == null || line.equals("")) { return null; }/*from w w w .j a va 2s.co m*/ if (line.indexOf(delim) < 0) { if (delim.length() > 1 && !"\r\n".equals(delim)) { String regex = "^.*[" + delim + "].*"; if (!line.matches(regex)) { return new String[] { line }; } } else { return new String[] { line }; } } StringTokenizer st = new StringTokenizer(line, delim); int length = st.countTokens(); String[] tokens = new String[length]; for (int i = 0; i < length; i++) { tokens[i] = st.nextToken(); } return tokens; }
From source file:net.sf.excelutils.tags.SheetTag.java
/** * Parse #sheet detail in list by sheetName *//*from w w w .j av a 2s. c o m*/ public int[] parseTag(Object context, Workbook wb, Sheet sheet, Row curRow, Cell curCell) throws ExcelException { String sheetExpr = curCell.getStringCellValue(); StringTokenizer st = new StringTokenizer(sheetExpr, " "); String properties = ""; String property = ""; String sheetName = ""; // parse the collection an object int pos = 0; while (st.hasMoreTokens()) { String str = st.nextToken(); if (pos == 1) { property = str; } if (pos == 3) { properties = str; } if (pos == 5) { sheetName = str; } pos++; } // get collection Object collection = ExcelParser.parseStr(context, properties); if (null == collection) { return new int[] { 0, 0, 1 }; } // remove #sheet tag sheet.removeRow(curRow); // remove merged region in forstart & forend for (int i = 0; i < sheet.getNumMergedRegions(); i++) { CellRangeAddress r = sheet.getMergedRegion(i); if (r.getFirstRow() >= curRow.getRowNum() && r.getLastRow() <= curRow.getRowNum()) { sheet.removeMergedRegion(i); i = i - 1; } } sheet.shiftRows(curRow.getRowNum() + 1, sheet.getLastRowNum(), -1, true, true); // get the iterator of collection Iterator iterator = ExcelParser.getIterator(collection); if (null != iterator) { // first obj, use parse method Object firstObj = null; if (iterator.hasNext()) { firstObj = iterator.next(); } // next obj, clone sheet and use parseSheet method while (iterator.hasNext()) { Object obj = iterator.next(); ExcelUtils.addValue(context, property, obj); try { int sheetIndex = WorkbookUtils.getSheetIndex(wb, sheet); // clone sheet Sheet cloneSheet = wb.cloneSheet(sheetIndex); // set cloneSheet name int cloneSheetIndex = WorkbookUtils.getSheetIndex(wb, cloneSheet); setSheetName(obj, wb, cloneSheetIndex, sheetName); // parse cloneSheet ExcelUtils.parseSheet(context, wb, cloneSheet); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("parse sheet error", e); } } } if (null != firstObj) { ExcelUtils.addValue(context, property, firstObj); // set sheet name int sheetIndex = WorkbookUtils.getSheetIndex(wb, sheet); setSheetName(firstObj, wb, sheetIndex, sheetName); } } return new int[] { 0, -1, 0 }; }
From source file:com.googlecode.jcimd.charset.GsmCharsetProvider.java
private static int init(BufferedReader reader) throws IOException { String line = null;/*w ww. j a v a 2 s . co m*/ int count = 0; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { if (logger.isTraceEnabled()) { logger.trace("Skipping line starting with '#': " + line); } continue; } StringTokenizer tokenizer = new StringTokenizer(line, "\t"); String hex1 = null; String hex2 = null; if (tokenizer.hasMoreTokens()) { hex1 = tokenizer.nextToken(); } if (tokenizer.hasMoreTokens()) { hex2 = tokenizer.nextToken(); } if (hex1 == null || hex2 == null) { continue; } int bite = Integer.parseInt(hex1.substring(2), 16); byte index = (byte) (bite & 0xFF); char ch = (char) Integer.parseInt(hex2.substring(2), 16); CHAR_TO_BYTE_SMALL_C_CEDILLA[ch] = bite; if ((bite & 0xFF00) >> 8 == ESCAPE) { // escape to extension table BYTE_TO_CHAR_ESCAPED_DEFAULT[index] = ch; if (logger.isTraceEnabled()) { logger.trace(String.format("(escaped) %d == %s", index, (ch != 10 && ch != 12 && ch != 13) ? ch : (ch == 10 ? "\\n" : (ch == 12 ? "0x0C (form feed)" : "\\r")))); } } else { BYTE_TO_CHAR_SMALL_C_CEDILLA[index] = ch; if (logger.isTraceEnabled()) { logger.trace(String.format("%d == %s", index, (ch != 10 && ch != 13) ? ch : (ch == 10 ? "\\n" : "\\r"))); } } count++; } if (count < 128 && logger.isWarnEnabled()) { logger.warn("Character look-up initialized with only " + count + " value(s) (expecting 128 values)"); } return count; }
From source file:com.adito.networkplaces.tags.PathsTag.java
public int doStartTag() throws JspException { // Look up the requested property value LaunchSession launchSession = (LaunchSession) TagUtils.getInstance().lookup(pageContext, name, property, scope);// w ww .ja v a 2 s . com FileSystemForm fsf = (FileSystemForm) pageContext.getRequest().getAttribute("fileSystemForm"); StringBuffer results = new StringBuffer(); results.append("<div class=\"path\"><span>"); StringTokenizer tok = new StringTokenizer(fsf.getPath(), "/"); String currentPath = tok.nextToken(); // Important: skip the file store // we only remove the second entry if the first one is the store, else we are straight into the proper paths. if (currentPath.equals("fs")) { currentPath = tok.nextToken(); // Important: skip the file store type } while (tok.hasMoreTokens()) { String element = tok.nextToken(); currentPath += "/" + element; results.append("<a href=\"fileSystem.do?actionTarget=list&" + LaunchSession.LAUNCH_ID + "=" + launchSession.getId() + "&path=" + URLUTF8Encoder.encode(currentPath, false) + "\">" + element + "</a> / "); } results.append(" </span></div>"); paths = results.toString(); return (SKIP_BODY); }