List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:com.glaf.jbpm.assignment.AssignableHelper.java
public void setActors(Assignable assignable, String actorId) { if (StringUtils.isEmpty(actorId)) { throw new RuntimeException(" actorId is null "); }/*from w w w. j a v a 2 s.c om*/ if (actorId.indexOf(",") > 0) { Set<String> actorIds = new HashSet<String>(); StringTokenizer token = new StringTokenizer(actorId, ","); while (token.hasMoreTokens()) { String elem = token.nextToken(); if (StringUtils.isNotEmpty(elem)) { actorIds.add(elem); } } if (actorIds.size() > 0) { int i = 0; String[] users = new String[actorIds.size()]; Iterator<String> iterator = actorIds.iterator(); while (iterator.hasNext()) { users[i++] = iterator.next(); } assignable.setPooledActors(users); } } else { assignable.setActorId(actorId); } }
From source file:com.yanzhenjie.andserver.util.HttpRequestParser.java
/** * Split http params.// w ww.j a v a 2 s . com * * @param content target content. * @param lowerCaseNames Whether to put all keys are converted to lowercase. * @return parameter key-value pairs. */ public static Map<String, String> splitHttpParams(String content, boolean lowerCaseNames) { Map<String, String> paramMap = new HashMap<String, String>(); StringTokenizer tokenizer = new StringTokenizer(content, "&"); while (tokenizer.hasMoreElements()) { String keyValue = tokenizer.nextToken(); int index = keyValue.indexOf("="); if (index > 0) { String key = keyValue.substring(0, index); if (lowerCaseNames) key = key.toLowerCase(Locale.ENGLISH); paramMap.put(key, keyValue.substring(index + 1)); } } return paramMap; }
From source file:Utils.java
/** * Wrap multi-line strings (and get the individual lines). * //from w w w.j a v a2s. com * @param original * the original string to wrap * @param width * the maximum width of lines * @param breakIterator * breaks original to chars, words, sentences, depending on what * instance you provide. * @param removeNewLines * if <code>true</code>, any newlines in the original string are * ignored * @return the lines after wrapping */ public static String[] wrapStringToArray(String original, int width, BreakIterator breakIterator, boolean removeNewLines) { if (original.length() == 0) { return new String[] { original }; } String[] workingSet; // substitute original newlines with spaces, // remove newlines from head and tail if (removeNewLines) { original = trimString(original); original = original.replace('\n', ' '); workingSet = new String[] { original }; } else { StringTokenizer tokens = new StringTokenizer(original, "\n"); // NOI18N int len = tokens.countTokens(); workingSet = new String[len]; for (int i = 0; i < len; i++) { workingSet[i] = tokens.nextToken(); } } if (width < 1) { width = 1; } if (original.length() <= width) { return workingSet; } widthcheck: { boolean ok = true; for (int i = 0; i < workingSet.length; i++) { ok = ok && (workingSet[i].length() < width); if (!ok) { break widthcheck; } } return workingSet; } java.util.ArrayList<String> lines = new java.util.ArrayList<String>(); int lineStart = 0; // the position of start of currently processed line in // the original string for (int i = 0; i < workingSet.length; i++) { if (workingSet[i].length() < width) { lines.add(workingSet[i]); } else { breakIterator.setText(workingSet[i]); int nextStart = breakIterator.next(); int prevStart = 0; do { while (((nextStart - lineStart) < width) && (nextStart != BreakIterator.DONE)) { prevStart = nextStart; nextStart = breakIterator.next(); } if (nextStart == BreakIterator.DONE) { nextStart = prevStart = workingSet[i].length(); } if (prevStart == 0) { prevStart = nextStart; } lines.add(workingSet[i].substring(lineStart, prevStart)); lineStart = prevStart; prevStart = 0; } while (lineStart < workingSet[i].length()); lineStart = 0; } } String[] s = new String[lines.size()]; return (String[]) lines.toArray(s); }
From source file:com.whizzosoftware.hobson.lifx.api.message.HSBK.java
public HSBK(String s) { if (s.startsWith("hsb(") && s.endsWith(")")) { StringTokenizer tok = new StringTokenizer(s.substring(4, s.length() - 1), ","); hue = (int) (Integer.parseInt(tok.nextToken().trim()) * 182.0416666667); saturation = (int) (Integer.parseInt(tok.nextToken().trim()) * 655.35); brightness = (int) (Integer.parseInt(tok.nextToken().trim()) * 655.35); kelvin = DEFAULT_KELVIN;//from w ww. j a v a 2s. co m } else if (s.startsWith("kb(") && s.endsWith(")")) { StringTokenizer tok = new StringTokenizer(s.substring(3, s.length() - 1), ","); hue = 0; saturation = 0; kelvin = Integer.parseInt(tok.nextToken().trim()); brightness = (int) (Integer.parseInt(tok.nextToken().trim()) * 655.35); } else { throw new IllegalArgumentException("Not a valid color string"); } }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminInvul.java
@Override public boolean useAdminCommand(String command0, L2Player activeChar) { StringTokenizer st = new StringTokenizer(command0, " "); String command = st.nextToken(); String param = st.hasMoreTokens() ? st.nextToken() : ""; final Boolean isInvul; if (param.equalsIgnoreCase("on") || param.equalsIgnoreCase("true") || param.equalsIgnoreCase("1")) isInvul = true;/*w w w . j a v a 2s .co m*/ else if (param.equalsIgnoreCase("off") || param.equalsIgnoreCase("false") || param.equalsIgnoreCase("0")) isInvul = false; else isInvul = null; if (command.equals("admin_invul")) handleInvul(activeChar, isInvul); if (command.equals("admin_setinvul")) { L2Object target = activeChar.getTarget(); if (target instanceof L2Player) { handleInvul((L2Player) target, isInvul); } } return true; }
From source file:io.github.bonigarcia.wdm.Downloader.java
public static Proxy createProxy() { String proxyString = System.getenv("HTTPS_PROXY"); if (proxyString == null || proxyString.length() < 1) proxyString = System.getenv("HTTP_PROXY"); if (proxyString == null || proxyString.length() < 1) { return null; }/*w w w.j av a2 s . c o m*/ proxyString = proxyString.replace("http://", ""); proxyString = proxyString.replace("https://", ""); StringTokenizer st = new StringTokenizer(proxyString, ":"); if (st.countTokens() != 2) return null; String host = st.nextToken(); String portString = st.nextToken(); try { int port = Integer.parseInt(portString); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); } catch (NumberFormatException e) { return null; } }
From source file:sg.edu.ntu.hrms.service.EmployeeListService.java
public String getEmpJSONFormat(String dtRange) { SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); StringTokenizer st = new StringTokenizer(dtRange, "-"); String stDate = st.nextToken().trim(); String edDate = st.nextToken().trim(); Session session = sessionFactory.openSession(); session.beginTransaction();//from w ww . j a v a 2s . co m userDAO.setSession(session); try { Date fromDate = formatter.parse(stDate); Date toDate = formatter.parse(edDate); List<UserDTO> userList = userDAO.getAllUsers(fromDate, toDate); //convert to json array String json = convertToJson(userList, new BeanHelper().getUserTab(userDAO)); /* response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.write(json); out.flush(); */ return json; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:org.wso2.carbon.clustering.azure.domain.NetworkSecurityGroupProperties.java
public List getNetworkInterfaceNames() { StringTokenizer[] st = new StringTokenizer[networkInterfaces.size()]; String[] NICname = new String[networkInterfaces.size()]; List names = new ArrayList(); for (int i = 0; i < networkInterfaces.size(); i++) { st[i] = new StringTokenizer(networkInterfaces.get(i).toString(), "/"); while (st[i].hasMoreTokens()) { NICname[i] = st[i].nextToken(); }/*w ww .java 2s. c o m*/ NICname[i] = NICname[i].substring(0, NICname[i].length() - 1); names.add(NICname[i]); } return names; }
From source file:com.terradue.jcatalogue.client.internal.converters.LocaleConverter.java
public Object convert(@SuppressWarnings("rawtypes") Class type, Object value) { if (value == null) { throw new ConversionException("Null values not supported in this version."); }//w ww . j a va 2 s.com if (String.class == type) { if (value instanceof Locale) { Locale locale = (Locale) value; return locale.getLanguage() + SEPARATOR + locale.getCountry(); } } else if (Locale.class == type) { if (value instanceof String) { StringTokenizer tokenizer = new StringTokenizer((String) value, SEPARATOR); return new Locale(tokenizer.nextToken(), tokenizer.nextToken()); } } throw new ConversionException(format("type %s and value %s not supported", type, value)); }
From source file:net.sf.jasperreports.engine.xml.TextLineBreakOffsetsRule.java
@Override public void body(String namespace, String name, String text) throws Exception { if (text != null) { StringTokenizer tokenizer = new StringTokenizer(text, JRXmlConstants.LINE_BREAK_OFFSET_SEPARATOR); int tokenCount = tokenizer.countTokens(); short[] offsets; if (tokenCount == 0) { //use the zero length array singleton offsets = JRPrintText.ZERO_LINE_BREAK_OFFSETS; } else {//from w w w. j ava 2 s. c o m offsets = new short[tokenCount]; for (int i = 0; i < offsets.length; i++) { String token = tokenizer.nextToken(); offsets[i] = Short.parseShort(token); } } JRPrintText printText = (JRPrintText) getDigester().peek(); printText.setLineBreakOffsets(offsets); } }