List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:org.alfresco.repo.admin.SysAdminParamsImpl.java
/** * Sets the list of users who are allowed to log in. * //w ww .java 2 s .c o m * @param allowedUsers * a comma-separated list of users who are allowed to log in or <code>null</code> if all users are * allowed to log in */ public void setAllowedUsers(String allowedUsers) { StringTokenizer tkn = new StringTokenizer(allowedUsers, ","); int length = tkn.countTokens(); if (length > 0) { this.allowedUsers = new ArrayList<String>(length); while (tkn.hasMoreTokens()) { this.allowedUsers.add(tkn.nextToken().trim()); } } }
From source file:com.impetus.client.cassandra.config.CassandraPropertyReaderTest.java
/** * Test method for/*from w w w . ja v a 2 s. c o m*/ * {@link com.impetus.client.cassandra.config.CassandraPropertyReader#readProperty()} * . * * @throws IOException */ @Test public void testReadProperty() throws IOException { log.info("running CassandraPropertyReaderTest"); // reader = new CassandraPropertyReader(); // reader.read("CassandraCounterTest"); EntityManagerFactory emf = Persistence.createEntityManagerFactory(pu); PersistenceUnitMetadata puMetadata = KunderaMetadataManager.getPersistenceUnitMetadata(pu); // metadata = CassandraPropertyReader.csmd; Properties properties = new Properties(); InputStream inStream = ClassLoader .getSystemResourceAsStream(puMetadata.getProperty(PersistenceProperties.KUNDERA_CLIENT_PROPERTY)); if (inStream != null) { properties.load(inStream); replication = properties.getProperty(Constants.REPLICATION_FACTOR); strategy = properties.getProperty(Constants.PLACEMENT_STRATEGY); String dataCenters = properties.getProperty(Constants.DATA_CENTERS); if (dataCenters != null) { StringTokenizer stk = new StringTokenizer(dataCenters, ","); while (stk.hasMoreTokens()) { StringTokenizer tokenizer = new StringTokenizer(stk.nextToken(), ":"); if (tokenizer.countTokens() == 2) { dataCenterToNode.put(tokenizer.nextToken(), tokenizer.nextToken()); } } } String cf_defs = properties.getProperty(Constants.CF_DEFS); if (cf_defs != null) { StringTokenizer stk = new StringTokenizer(cf_defs, ","); while (stk.hasMoreTokens()) { CassandraColumnFamilyProperties familyProperties = new CassandraColumnFamilyProperties(); StringTokenizer tokenizer = new StringTokenizer(stk.nextToken(), "|"); if (tokenizer.countTokens() != 0 && tokenizer.countTokens() >= 2) { String columnFamilyName = tokenizer.nextToken(); String defaultValidationClass = tokenizer.nextToken(); familyProperties.setDefault_validation_class(defaultValidationClass); if (tokenizer.countTokens() != 0) { String comparator = tokenizer.nextToken(); familyProperties.setComparator(comparator); } familyToProperties.put(columnFamilyName, familyProperties); } } } metadata = CassandraPropertyReader.csmd; if (replication != null) { Assert.assertNotNull(replication); Assert.assertNotNull(metadata.getReplication_factor()); } else { Assert.assertNull(replication); Assert.assertNull(metadata.getReplication_factor()); } Assert.assertEquals(replication, metadata.getReplication_factor()); if (strategy != null) { Assert.assertNotNull(strategy); Assert.assertNotNull(metadata.getPlacement_strategy()); } else { Assert.assertNull(strategy); Assert.assertNull(metadata.getPlacement_strategy()); } Assert.assertEquals(strategy, metadata.getPlacement_strategy()); if (!familyToProperties.isEmpty()) { Assert.assertNotNull(familyToProperties); Assert.assertNotNull(metadata.getColumnFamilyProperties()); Assert.assertFalse(metadata.getColumnFamilyProperties().isEmpty()); } else { Assert.assertTrue(metadata.getColumnFamilyProperties().isEmpty()); } Assert.assertEquals(familyToProperties.size(), metadata.getColumnFamilyProperties().size()); if (!dataCenterToNode.isEmpty()) { Assert.assertNotNull(dataCenterToNode); Assert.assertNotNull(metadata.getDataCenters()); Assert.assertFalse(metadata.getDataCenters().isEmpty()); } else { Assert.assertTrue(metadata.getDataCenters().isEmpty()); } Assert.assertEquals(dataCenterToNode.size(), metadata.getDataCenters().size()); } else { Assert.assertEquals("1", metadata.getReplication_factor()); Assert.assertEquals(SimpleStrategy.class.getName(), metadata.getPlacement_strategy()); Assert.assertEquals(0, metadata.getDataCenters().size()); Assert.assertEquals(0, metadata.getColumnFamilyProperties().size()); } }
From source file:op.tools.SYSCalendar.java
public static Date parseDate(String input) throws NumberFormatException { if (input == null || input.equals("")) { throw new NumberFormatException("empty"); }/*from www.j a v a2 s. c o m*/ if (input.indexOf(".") + input.indexOf(",") + input.indexOf("-") + input.indexOf("/") == -4) { input += "."; // er war zu faul auch nur einen punkt anzuhngen. } StringTokenizer st = new StringTokenizer(input, "/,.-"); if (st.countTokens() == 1) { // Vielleicht fehlen ja nur die Monats- und Jahresangaben. Dann hngen wir sie einach an. input += (SYSCalendar.today().get(GregorianCalendar.MONTH) + 1) + "." + SYSCalendar.today().get(GregorianCalendar.YEAR); st = new StringTokenizer(input, "/,.-"); // dann nochmal aufteilen... } if (st.countTokens() == 2) { // Vielleicht fehlt ja nur die Jahresangabe. Dann hngen wir es einfach an. if (!input.trim().substring(input.length() - 1).equals(".") && !input.trim().substring(input.length() - 1).equals(",")) { input += "."; // er war zu faul den letzten Punkt anzuhngen. } input += SYSCalendar.today().get(GregorianCalendar.YEAR); st = new StringTokenizer(input, "/,.-"); // dann nochmal aufteilen... } if (st.countTokens() != 3) { throw new NumberFormatException("wrong format"); } String sTag = st.nextToken(); String sMonat = st.nextToken(); String sJahr = st.nextToken(); int tag, monat, jahr; // Year 2010 Problem GregorianCalendar now = new GregorianCalendar(); int decade = (now.get(GregorianCalendar.YEAR) / 10) * 10; int century = (now.get(GregorianCalendar.YEAR) / 100) * 100; try { tag = Integer.parseInt(sTag); } catch (NumberFormatException nfe) { throw new NumberFormatException("day"); } try { monat = Integer.parseInt(sMonat); } catch (NumberFormatException nfe) { throw new NumberFormatException("month"); } try { jahr = Integer.parseInt(sJahr); } catch (NumberFormatException nfe) { throw new NumberFormatException("year"); } if (jahr < 0) { throw new NumberFormatException("year"); } if (jahr > 9999) { throw new NumberFormatException("year"); } if (jahr < 10) { jahr += decade; } if (jahr < 100) { jahr += century; } if (monat < 1 || monat > 12) { throw new NumberFormatException("month"); } if (tag < 1 || tag > eom(new GregorianCalendar(jahr, monat - 1, 1))) { throw new NumberFormatException("month"); } return new DateMidnight(jahr, monat, tag).toDate(); }
From source file:calculadora.controlador.ControladorCLI.java
/** * Compongo la linea de comandos en un array de String para poder poder leer * los comandos./*from w ww . java2 s . c om*/ * * En un momento dado se iba a utilizar para separar por espacios una cadena * para poder leer los comandos. * * Pero se quedo obsoleta porque se hizo con un metodo de java. * * @see VistaCLI#mostrarLineaCalculadora() * @see String#split(java.lang.String) * * @see StringTokenizer * @param arg Linea de comandos en una cadena * @return arg String[] un array con los comandos * @deprecated Mejorado usando {@link String#split(java.lang.String)} */ private String[] montarLineaComando(String arg) { StringTokenizer st = new StringTokenizer(arg); String[] args = new String[st.countTokens()]; int cont = 0; while (st.hasMoreTokens()) { args[cont] = st.nextToken(); cont++; } return args; }
From source file:org.inbio.ait.model.SystemUser.java
@Override public GrantedAuthority[] getAuthorities() { StringTokenizer st = new StringTokenizer(this.getRoles(), ROLE_DELIMITER); GrantedAuthorityImpl[] grantedAuthorityImplArray = new GrantedAuthorityImpl[st.countTokens()]; for (int i = 0; st.hasMoreElements(); i++) grantedAuthorityImplArray[i] = new GrantedAuthorityImpl(st.nextToken()); return grantedAuthorityImplArray; }
From source file:com.sinosoft.one.mvc.web.var.FlashImpl.java
protected synchronized void readLastMessages() { if (lastRead) { return;/*from ww w. jav a 2 s. c om*/ } lastRead = true; if (logger.isDebugEnabled()) { logger.debug("readLastMessages"); } Cookie[] cookies = invocation.getRequest().getCookies(); for (int i = 0; cookies != null && i < cookies.length; i++) { if (logger.isDebugEnabled()) { logger.debug("cookie " + cookies[i].getName() + "=" + cookies[i].getValue() + "; age=" + cookies[i].getMaxAge()); } if (cookies[i].getValue() == null) { if (logger.isDebugEnabled()) { logger.debug("ignore cookie: " + cookies[i].getName()); } continue; } if (cookies[i].getName().startsWith(cookiePrefix)) { StringTokenizer st = new StringTokenizer(cookies[i].getName(), DELIM); String[] splits = new String[st.countTokens()]; for (int j = 0; j < splits.length; j++) { splits[j] = st.nextToken(); } if (splits.length < 2) { if (logger.isInfoEnabled()) { logger.info("ignore flash cookie: " + cookies[i].getName()); } continue; } String name = splits[1]; String cookieValue = cookies[i].getValue(); String flashMessage; if (cookieValue.length() == 0) { flashMessage = ""; } else { try { flashMessage = new String(base64.decodeFromString(cookieValue), "UTF-8"); } catch (Exception e) { logger.error("failed to decode '" + cookieValue + "' as" + " a base64 string", e); flashMessage = cookieValue; } } if (last.size() == 0) { last = new LinkedHashMap<String, String>(); } this.last.put(name, flashMessage); Cookie cookie = new Cookie(cookies[i].getName(), ""); cookie.setPath("/"); cookie.setMaxAge(0); invocation.getResponse().addCookie(cookie); if (logger.isDebugEnabled()) { logger.debug("found flash message:" + name + "=" + flashMessage); } } } }
From source file:com.laxser.blitz.web.var.FlashImpl.java
protected synchronized void readLastMessages() { if (lastRead) { return;/*from ww w . j a v a2 s.c o m*/ } lastRead = true; if (logger.isDebugEnabled()) { logger.debug("readLastMessages"); } Cookie[] cookies = invocation.getRequest().getCookies(); for (int i = 0; cookies != null && i < cookies.length; i++) { if (logger.isDebugEnabled()) { logger.debug("cookie " + cookies[i].getName() + "=" + cookies[i].getValue() + "; age=" + cookies[i].getMaxAge()); } if (cookies[i].getValue() == null) { if (logger.isDebugEnabled()) { logger.debug("ignore cookie: " + cookies[i].getName()); } continue; } if (cookies[i].getName().startsWith(cookiePrefix)) { StringTokenizer st = new StringTokenizer(cookies[i].getName(), DELIM); String[] splits = new String[st.countTokens()]; for (int j = 0; j < splits.length; j++) { splits[j] = st.nextToken(); } if (splits.length < 2) { if (logger.isInfoEnabled()) { logger.info("ignore flash cookie: " + cookies[i].getName()); } continue; } String name = splits[1]; String cookieValue = cookies[i].getValue(); String flashMessage; if (cookieValue.length() == 0) { flashMessage = ""; } else { try { flashMessage = new String(base64.decodeFromString(cookieValue), "UTF-8"); } catch (Exception e) { logger.error("failed to decode '" + cookieValue + "' as" + " a base64 string", e); flashMessage = cookieValue; } } if (last.size() == 0) { last = new LinkedHashMap<String, String>(); } this.last.put(name, flashMessage); if (logger.isDebugEnabled()) { logger.debug("found flash message:" + name + "=" + flashMessage); } } } }
From source file:ancat.visualizers.EdgeTransformers.java
/** * Configuration of the Stroke used for drawing edges. It processes the * following values:/*from w w w.j a v a 2 s . c o m*/ * * <code> edge:style </code> may be set to solid, dashed or dotted. By default * the edge style is set to dashed. * * <code> edge:stroke-width </code> The width of the stroke used for * rendering. * * <code> edge:dash-pattern</code> Contains an array of float values * describing the dash pattern. See documentation of Java Stroke class to * understand the pattern style</code> */ protected void setupStroke() { String style = "solid"; float width = 0.5f; float dash[] = null; Map<String, String> edgeConfig = _renderConfig.edgeConfiguration(); if (edgeConfig.containsKey("edge:style")) { style = edgeConfig.get("edge:style"); if (!style.equalsIgnoreCase("solid") && !style.equalsIgnoreCase("dashed") && !style.equalsIgnoreCase("dotted")) { _logger.error("unsupported edge style attribute: " + style + " allowed is solid, dashed, dotted"); style = "solid"; } } if (edgeConfig.containsKey("edge:stroke-width")) { try { width = Float.parseFloat(edgeConfig.get("edge:stroke-width")); } catch (Exception e) { _logger.error("unsupported specification of float value for edge width, changing to default"); } } if (edgeConfig.containsKey("edge:dash-pattern")) { try { StringTokenizer tokenizer = new StringTokenizer(edgeConfig.get("edge:dash-pattern"), ","); dash = new float[tokenizer.countTokens()]; int counter = 0; while (tokenizer.hasMoreElements()) { dash[counter] = Float.parseFloat(tokenizer.nextToken().trim()); counter += 1; } } catch (Exception e) { _logger.error("Error while parsing dash style, changing to default"); dash = new float[] { 10.0f }; } } if (style.equalsIgnoreCase("dashed")) { _edgeStroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f); } else if (style.equalsIgnoreCase("dotted")) { dash = new float[] { 2.0f, 2.0f }; _edgeStroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f); } else if (style.equalsIgnoreCase("solid")) { _edgeStroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); } }
From source file:com.hihframework.core.utils.DateUtils.java
public static String[] SplitString(String szSource, String token) { if ((szSource == null) || (token == null)) { return null; }//from www . ja va 2s. com StringTokenizer st1 = new StringTokenizer(szSource, token); String[] d1 = new String[st1.countTokens()]; for (int x = 0; x < d1.length; x++) if (st1.hasMoreTokens()) { d1[x] = st1.nextToken(); } return d1; }
From source file:edu.ucla.stat.SOCR.chart.demo.XYBarChartDemo2.java
public void setDataTable(String input) { hasExample = true;// w ww . ja v a 2s .com StringTokenizer lnTkns = new StringTokenizer(input, "#"); String line; int lineCt = lnTkns.countTokens(); resetTableRows(lineCt); int r = 0; while (lnTkns.hasMoreTokens()) { line = lnTkns.nextToken(); // String tb[] =line.split("\t"); StringTokenizer serieTkns = new StringTokenizer(line, ";");// IE use "space" Mac use tab as cell separator int serieCnt = serieTkns.countTokens(); String tb[] = new String[serieCnt]; int r1 = 0; while (serieTkns.hasMoreTokens()) { tb[r1] = serieTkns.nextToken(); r1++; } //System.out.println("tb.length="+tb.length); int colCt = tb.length * 2; resetTableColumns(colCt); for (int i = 0; i < tb.length; i++) { StringTokenizer cellTkns = new StringTokenizer(tb[i], ","); dataTable.setValueAt(cellTkns.nextToken(), r, 2 * i); dataTable.setValueAt(cellTkns.nextToken(), r, 2 * i + 1); } r++; } // this will update the mapping panel resetTableColumns(dataTable.getColumnCount()); }