List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:com.alvermont.terraj.fracplanet.io.ColourFile.java
private static FloatRGBA parseColour(String line) throws IOException { final StringTokenizer tok = new StringTokenizer(line, ","); if (tok.countTokens() != 3) { throw new IOException("Line should be in the form x,y,z: " + line); }/*from ww w . j a v a2 s .com*/ final float[] floats = new float[3]; for (int b = 0; b < 3; ++b) floats[b] = Float.parseFloat(tok.nextToken().trim()); return new FloatRGBA(floats[0], floats[1], floats[2]); }
From source file:de.pawlidi.openaletheia.utils.AletheiaUtils.java
/** * //w ww .jav a 2 s. co m * @return */ public static String getLinuxMacAddress() { String ipConfigResponse = executeCommand("ifconfig"); if (ipConfigResponse == null) { ipConfigResponse = executeCommand("/sbin/ifconfig"); if (ipConfigResponse == null) { return null; } } String localHost = getLocalhostAddress(); if (localHost == null) { return null; } StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); String lastMacAddress = null; while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); boolean containsLocalHost = line.indexOf(localHost) >= 0; if ((containsLocalHost) && (lastMacAddress != null)) { return lastMacAddress; } int macAddressPosition = line.indexOf("HWaddr"); if (macAddressPosition > 0) { String macAddressCandidate = line.substring(macAddressPosition + 6).trim(); if (isMacAddressCandidate(macAddressCandidate)) { lastMacAddress = normalizeMacAddress(macAddressCandidate); } } } return null; }
From source file:SocketFetcher.java
/** * Parse a string into whitespace separated tokens and return the tokens in an * array.//from w ww . j a v a 2 s . c o m */ private static String[] stringArray(String s) { StringTokenizer st = new StringTokenizer(s); List tokens = new ArrayList(); while (st.hasMoreTokens()) tokens.add(st.nextToken()); return (String[]) tokens.toArray(new String[tokens.size()]); }
From source file:com.l2jfree.gameserver.datatables.DoorTable.java
public static L2DoorInstance parseLine(String line) { L2DoorInstance door = null;// ww w . ja v a2 s . c o m try { StringTokenizer st = new StringTokenizer(line, ";"); String name = st.nextToken(); 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 rangeXMin = Integer.parseInt(st.nextToken()); int rangeYMin = Integer.parseInt(st.nextToken()); int rangeZMin = Integer.parseInt(st.nextToken()); int rangeXMax = Integer.parseInt(st.nextToken()); int rangeYMax = Integer.parseInt(st.nextToken()); int rangeZMax = Integer.parseInt(st.nextToken()); int hp = Integer.parseInt(st.nextToken()); int pdef = Integer.parseInt(st.nextToken()); int mdef = Integer.parseInt(st.nextToken()); boolean unlockable = false; if (st.hasMoreTokens()) unlockable = Boolean.parseBoolean(st.nextToken()); boolean startOpen = false; if (st.hasMoreTokens()) startOpen = Boolean.parseBoolean(st.nextToken()); if (rangeXMin > rangeXMax) _log.fatal("Error in door data, XMin > XMax, ID:" + id); if (rangeYMin > rangeYMax) _log.fatal("Error in door data, YMin > YMax, ID:" + id); if (rangeZMin > rangeZMax) _log.fatal("Error in door data, ZMin > ZMax, ID:" + id); int collisionRadius; // (max) radius for movement checks if (rangeXMax - rangeXMin > rangeYMax - rangeYMin) collisionRadius = rangeYMax - rangeYMin; else collisionRadius = rangeXMax - rangeXMin; StatsSet npcDat = new StatsSet(); npcDat.set("npcId", id); npcDat.set("level", 0); npcDat.set("jClass", "door"); 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", collisionRadius); npcDat.set("collision_height", rangeZMax - rangeZMin & 0xfff0); npcDat.set("fcollision_radius", collisionRadius); npcDat.set("fcollision_height", rangeZMax - rangeZMin & 0xfff0); 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", name); npcDat.set("baseHpMax", hp); npcDat.set("baseHpReg", 3.e-3f); npcDat.set("baseMpReg", 3.e-3f); npcDat.set("basePDef", pdef); npcDat.set("baseMDef", mdef); L2CreatureTemplate template = new L2CreatureTemplate(npcDat); door = new L2DoorInstance(IdFactory.getInstance().getNextId(), template, id, name, unlockable); door.setRange(rangeXMin, rangeYMin, rangeZMin, rangeXMax, rangeYMax, rangeZMax); door.setMapRegion(MapRegionManager.getInstance().getRegion(x, y, z)); door.getStatus().setCurrentHpMp(door.getMaxHp(), door.getMaxMp()); door.setOpen(startOpen); door.getPosition().setXYZInvisible(x, y, z); door.setMapRegion(MapRegionManager.getInstance().getRegion(x, y)); } catch (Exception e) { _log.error("Error in door data at line: " + line, e); } return door; }
From source file:fit.Fixture.java
public static String camel(String name) { StringBuilder b = new StringBuilder(name.length()); StringTokenizer t = new StringTokenizer(name); b.append(t.nextToken()); while (t.hasMoreTokens()) { String token = t.nextToken(); b.append(token.substring(0, 1).toUpperCase()); // replace spaces with // camelCase b.append(token.substring(1));//from w w w. jav a 2 s .co m } return b.toString(); }
From source file:Main.java
@NonNull private static List<String> parseGradientValues(String image) { if (TextUtils.isEmpty(image)) { return null; }//from w ww .j av a 2 s .co m image.trim(); if (image.startsWith("linear-gradient")) { String valueStr = image.substring(image.indexOf("(") + 1, image.lastIndexOf(")")); StringTokenizer tokenizer = new StringTokenizer(valueStr, ","); List<String> values = new ArrayList<>(); String temp = null; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.contains("(")) { temp = token + ","; continue; } if (token.contains(")")) { temp += token; values.add(temp); temp = null; continue; } if (temp != null) { temp += (token + ","); continue; } values.add(token); } return values; } return null; }
From source file:AnimatedMetadataGraph.java
public static String getParentPath(String childPath) { if (!childPath.equals("/")) { Vector<String> pathElements = new Vector<String>(); StringTokenizer tokenizer = new StringTokenizer(childPath, "/"); while (tokenizer.hasMoreTokens()) pathElements.add(tokenizer.nextToken()); StringBuffer parentPath = new StringBuffer().append("/"); for (int i = 0; i < pathElements.size() - 1; i++) parentPath.append(pathElements.get(i)).append("/"); return parentPath.toString(); }//www. j a v a 2 s .co m return null; }
From source file:modula.parser.io.ModelUpdater.java
/** * transition// www . jav a 2 s . c o m */ private static void updateTransition(final SimpleTransition transition, final Map<String, TransitionTarget> targets) throws ModelException { String next = transition.getNext(); if (next == null) { // stay transition return; } Set<TransitionTarget> tts = transition.getTargets(); if (tts.isEmpty()) { // 'next' is a space separated list of transition target IDs StringTokenizer ids = new StringTokenizer(next); while (ids.hasMoreTokens()) { String id = ids.nextToken(); TransitionTarget tt = targets.get(id); if (tt == null) { logAndThrowModelError(ERR_TARGET_NOT_FOUND, new Object[] { id }); } tts.add(tt); } if (tts.size() > 1) { boolean legal = verifyTransitionTargets(tts); if (!legal) { logAndThrowModelError(ERR_ILLEGAL_TARGETS, new Object[] { next }); } } } }
From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java
public static ProcessPuzzleLocale parse(String localeSpecifier) { if (localeSpecifier == null) throw new LocaleParseException(localeSpecifier); String language = null;/*w ww .jav a 2 s . c o m*/ String country = null; String variant = null; StringTokenizer tokenizer = new StringTokenizer(localeSpecifier, SPECIFIER_DELIMITERS); int index = 0; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (index == 0) language = token.trim(); if (index == 1) country = token.trim(); if (index == 2) variant = token.trim(); index++; } ProcessPuzzleLocale locale = null; try { if (country == null) locale = new ProcessPuzzleLocale(language); else if (variant == null) locale = new ProcessPuzzleLocale(language, country); else locale = new ProcessPuzzleLocale(language, country, variant); } catch (UnsupportedLocaleException e) { throw new LocaleParseException(localeSpecifier); } return locale; }
From source file:com.concursive.connect.web.utils.PermissionUtils.java
public static boolean hasPermissionToAction(ServletRequest request, HttpSession session, String permission, String includeIf, String objectName) { // Use the object name specified, or use the default here String thisObjectName = objectName; if (thisObjectName == null) { thisObjectName = "project"; }// w ww . j a v a 2 s. co m try { // Find the project to check for permissions... Project thisProject = null; // Check the current portlet first PortletRequest renderRequest = (PortletRequest) request .getAttribute(org.apache.pluto.tags.Constants.PORTLET_REQUEST); if (renderRequest != null) { // Get the requested object Object object = null; int dotPos = thisObjectName.indexOf("."); if (dotPos > -1) { // Get the base object from the request String currentObject = thisObjectName.substring(0, dotPos); object = renderRequest.getAttribute(currentObject); // Get the parsed object currentObject = thisObjectName.substring(dotPos + 1); object = ObjectUtils.getObject(object, currentObject); thisProject = (Project) object; } else { thisProject = (Project) renderRequest.getAttribute(thisObjectName); } if (thisProject == null && objectName == null) { thisProject = PortalUtils.getProject(renderRequest); } } // Check the request object if (thisProject == null) { // Get the requested object Object object = null; int dotPos = thisObjectName.indexOf("."); if (dotPos > -1) { // Get the base object from the request String currentObject = thisObjectName.substring(0, dotPos); object = request.getAttribute(currentObject); // Get the parsed object currentObject = thisObjectName.substring(dotPos + 1); object = ObjectUtils.getObject(object, currentObject); thisProject = (Project) object; } else { thisProject = (Project) request.getAttribute(thisObjectName); } } // Deny if not found if (thisProject == null) { LOG.debug("Project is null"); return false; } // Check this user's permissions User thisUser = null; // Check the portlet if (thisUser == null && renderRequest != null) { thisUser = PortalUtils.getUser(renderRequest); } // Check the session object if (thisUser == null) { thisUser = (User) session.getAttribute(Constants.SESSION_USER); } // Deny if not found if (thisUser == null) { return false; } // Multiple permissions to check boolean doCheck = true; String thisPermission = null; StringTokenizer st = new StringTokenizer(permission, ","); while (st.hasMoreTokens() || doCheck) { doCheck = false; if (st.hasMoreTokens()) { thisPermission = st.nextToken(); } else { thisPermission = permission; } if (NONE.equals(includeIf)) { if (ProjectUtils.hasAccess(thisProject.getId(), thisUser, thisPermission)) { return false; } } else if (ANY.equals(includeIf)) { if (ProjectUtils.hasAccess(thisProject.getId(), thisUser, thisPermission)) { return true; } } else { if (!ProjectUtils.hasAccess(thisProject.getId(), thisUser, thisPermission)) { return false; } } } // If the above didn't trigger, then go with the default if (NONE.equals(includeIf)) { return true; } else if (ANY.equals(includeIf)) { return false; } else { return true; } } catch (Exception e) { LOG.error("hasPermissionToAction", e); return false; } }