List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.zuoxiaolong.niubi.job.persistent.hibernate.HibernateNamingStrategy.java
private static String[] splitName(String someName) { StringTokenizer tokenizer = new StringTokenizer(someName, SEPARATOR); String[] tokens = new String[tokenizer.countTokens()]; int i = 0;/*w w w. j a va 2 s. c o m*/ while (tokenizer.hasMoreTokens()) { tokens[i] = tokenizer.nextToken(); i++; } return tokens; }
From source file:Main.java
private static String convertStringToTime(String oldTime) { if (oldTime == null || oldTime.length() == 0) { return "00h00m00s"; }/* www . j a v a 2 s . c o m*/ boolean hasHours = (oldTime.indexOf('h') != -1); boolean hasMinutes = (oldTime.indexOf('m') != -1); StringBuffer rtn = new StringBuffer(oldTime); // Delete the seconds fields and replace other chars with colons rtn.deleteCharAt(oldTime.indexOf('s')); if (hasMinutes) { rtn.setCharAt(oldTime.indexOf('m'), ':'); } else { rtn.insert(0, "00:"); } if (hasHours) { rtn.setCharAt(oldTime.indexOf('h'), ':'); } else { rtn.insert(0, "00:"); } StringTokenizer st = new StringTokenizer(rtn.toString(), ":"); int index = 1; String hh = "00"; String mm = "00"; String ss = "00"; while (st.hasMoreTokens()) { String toke = st.nextToken(); switch (index) { case 1: if (toke.length() < 2) { hh = "0" + toke; } else { hh = toke; } break; case 2: if (toke.length() < 2) { mm = "0" + toke; } else { mm = toke; } break; case 3: if (toke.length() < 2) { ss = "0" + toke; } else { ss = toke; } break; } index++; } return hh + "h" + mm + "m" + ss + "s"; }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureMapperFeatures(final ObjectMapper objectMapper, final String features) { final StringTokenizer st = new StringTokenizer(features, ","); while (st.hasMoreTokens()) { final String[] pair = NoMappingJsonFactoryObjectFactory.parseSingleFeatureValue(st.nextToken().trim()); final String key = pair[0]; final String value = pair[1]; final MapperFeature feature; try {/* w w w . j a v a2 s . co m*/ feature = MapperFeature.valueOf(key); } catch (final Exception e1) { throw SupportMessages.MESSAGES.unrecognizedReaderWriterProperty(key, value); } if ("true".equals(value)) { if (!feature.enabledByDefault()) { objectMapper.configure(feature, true); } } else if ("false".equals(value)) { if (feature.enabledByDefault()) { objectMapper.configure(feature, false); } } else { throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, value, key); } } }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureSerializationFeatures(final ObjectMapper objectMapper, final String features) { final StringTokenizer st = new StringTokenizer(features, ","); while (st.hasMoreTokens()) { final String[] pair = NoMappingJsonFactoryObjectFactory.parseSingleFeatureValue(st.nextToken().trim()); final String key = pair[0]; final String value = pair[1]; final SerializationFeature feature; try {//from w ww.j a v a2 s . c om feature = SerializationFeature.valueOf(key); } catch (final Exception e1) { throw SupportMessages.MESSAGES.unrecognizedReaderWriterProperty(key, value); } if ("true".equals(value)) { if (!feature.enabledByDefault()) { objectMapper.configure(feature, true); } } else if ("false".equals(value)) { if (feature.enabledByDefault()) { objectMapper.configure(feature, false); } } else { throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, value, key); } } }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureDeserializationFeatures(final ObjectMapper objectMapper, final String features) { final StringTokenizer st = new StringTokenizer(features, ","); while (st.hasMoreTokens()) { final String[] pair = NoMappingJsonFactoryObjectFactory.parseSingleFeatureValue(st.nextToken().trim()); final String key = pair[0]; final String value = pair[1]; final DeserializationFeature feature; try {//ww w . ja v a2 s. c o m feature = DeserializationFeature.valueOf(key); } catch (final Exception e1) { throw SupportMessages.MESSAGES.unrecognizedReaderWriterProperty(key, value); } if ("true".equals(value)) { if (!feature.enabledByDefault()) { objectMapper.configure(feature, true); } } else if ("false".equals(value)) { if (feature.enabledByDefault()) { objectMapper.configure(feature, false); } } else { throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, value, key); } } }
From source file:Main.java
/** * //from w ww. j a va 2 s . c o m * @param value * @return double[][] */ public static double[][] to2dDoubleArray(final String value) { final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG, EMPTY_STRING); final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ARRAY_SEPARATOR); final double[][] array = new double[tokenizer.countTokens()][]; int i = 0; while (tokenizer.hasMoreTokens()) { array[i++] = toDoubleArray(tokenizer.nextToken()); } return array; }
From source file:LauncherBootstrap.java
/** * Convert a ":" separated list of URL file fragments into an array of URL * objects. Note that any all URL file fragments must conform to the format * required by the "file" parameter in the * {@link URL(String, String, String)} constructor. * * @param fileList the ":" delimited list of URL file fragments to be * converted// w ww .j a v a 2s . c om * @return an array of URL objects * @throws MalformedURLException if the fileList parameter contains any * malformed URLs */ private static URL[] fileListToURLs(String fileList) throws MalformedURLException { if (fileList == null || "".equals(fileList)) return new URL[0]; // Parse the path string ArrayList list = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(fileList, ":"); URL bootstrapURL = LauncherBootstrap.class.getResource("/" + LauncherBootstrap.class.getName() + ".class"); while (tokenizer.hasMoreTokens()) list.add(new URL(bootstrapURL, tokenizer.nextToken())); return (URL[]) list.toArray(new URL[list.size()]); }
From source file:esg.node.core.Resource.java
@SuppressWarnings("unchecked") private static String[] split(String str, String delim) { // Use a Vector to hold the split strings. Vector v = new Vector(); // Use a StringTokenizer to do the splitting. StringTokenizer tokenizer = new StringTokenizer(str, delim); while (tokenizer.hasMoreTokens()) { v.addElement(tokenizer.nextToken()); }//from w w w .ja va 2 s . co m String[] ret = new String[v.size()]; v.copyInto(ret); return ret; }
From source file:eu.crisis_economics.utilities.EnumDistribution.java
public static <T extends Enum<T>> EnumDistribution<T> // Immutable create(Class<T> token, String sourceFile) throws IOException { if (token == null) throw new NullArgumentException(); if (!token.isEnum()) throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is not an enum."); if (token.getEnumConstants().length == 0) throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is an empty enum."); EnumDistribution<T> result = new EnumDistribution<T>(); result.values = token.getEnumConstants(); result.probabilities = new EnumMap<T, Double>(token); Map<String, T> converter = new HashMap<String, T>(); final int numberOfValues = result.values.length; int[] valueIndices = new int[numberOfValues]; double[] valueProbabilities = new double[numberOfValues]; BitSet valueIsComitted = new BitSet(numberOfValues); {/*from ww w .j ava2s . co m*/ int counter = 0; for (T value : result.values) { valueIndices[counter] = counter++; result.probabilities.put(value, 0.); converter.put(value.name(), value); } } BufferedReader reader = new BufferedReader(new FileReader(sourceFile)); try { String newLine; while ((newLine = reader.readLine()) != null) { if (newLine.isEmpty()) continue; StringTokenizer tokenizer = new StringTokenizer(newLine); final String name = tokenizer.nextToken(" ,:\t"), pStr = tokenizer.nextToken(" ,:\t"); if (tokenizer.hasMoreTokens()) throw new ParseException( "EnumDistribution: " + newLine + " is not a valid entry in " + sourceFile + ".", 0); final double p = Double.parseDouble(pStr); if (p < 0. || p > 1.) throw new IOException(pStr + " is not a valid probability for the value " + name); result.probabilities.put(converter.get(name), p); final int ordinal = converter.get(name).ordinal(); if (valueIsComitted.get(ordinal)) throw new ParseException("The value " + name + " appears twice in " + sourceFile, 0); valueProbabilities[converter.get(name).ordinal()] = p; valueIsComitted.set(ordinal, true); } { // Check sum of probabilities double sum = 0.; for (double p : valueProbabilities) sum += p; if (Math.abs(sum - 1.) > 1e2 * Math.ulp(1.)) throw new IllegalStateException("EnumDistribution: parser has succeeded, but the resulting " + "probaility sum (value " + sum + ") is not equal to 1."); } } catch (Exception e) { throw new IOException(e.getMessage()); } finally { reader.close(); } result.dice = new EnumeratedIntegerDistribution(valueIndices, valueProbabilities); return result; }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureDeserializationProblemHandlers(final ObjectMapper objectMapper, final String deserializationProblemHandlers, final ClassLoader classLoader) throws Exception { final StringTokenizer st = new StringTokenizer(deserializationProblemHandlers, ", "); while (st.hasMoreTokens()) { final Class<?> c = classLoader.loadClass(st.nextToken()); objectMapper.addHandler((DeserializationProblemHandler) c.newInstance()); }//from w w w. j a v a2 s . co m }