public static List<URL> parseURLs(String address, Map<String, String> defaults) { if (address == null || address.length() == 0) { return null; } String[] addresses = Constants.REGISTRY_SPLIT_PATTERN.split(address); if (addresses == null || addresses.length == 0) { return null; //here won't be empty } List<URL> registries = new ArrayList<URL>(); for (String addr : addresses) { registries.add(parseURL(addr, defaults)); } return registries; }
/** * Splits a newline (\n) delimited string into an array of strings * * @param str the string to split up * @param delimiter the delimiter to use in splitting * @return an array of String objects equivalent to str */ public String[] splitDelimitedStr(String str, String delimiter) { Pattern pttn = Pattern.compile(delimiter); return pttn.split(str); }
public static Map<String, String> parseQueryParams(String rawRefer) { Map<String, String> map = new HashMap<String, String>(); String refer = StringTools.urlDecode(rawRefer); String[] kvs = MotanConstants.QUERY_PARAM_PATTERN.split(refer); for (String kv : kvs) { if (kv != null && kv.contains(MotanConstants.EQUAL_SIGN_SEPERATOR)) { String[] kvArr = MotanConstants.EQUAL_SIGN_PATTERN.split(kv); if (kvArr.length == 2) { map.put(kvArr[0].trim(), kvArr[1].trim()); } } } return map; }
public static List<UnitPrefix> loadPrefixes(String filename) throws IOException { Pattern commaPattern = Pattern.compile("\\s*,\\s*"); BufferedReader br = IOUtils.getBufferedFileReader(filename); String headerString = br.readLine(); String[] header = commaPattern.split(headerString); Map<String,Integer> headerIndex = new HashMap<>(); for (int i = 0; i < header.length; i++) { headerIndex.put(header[i], i); } int iName = headerIndex.get("name"); int iPrefix = headerIndex.get("prefix"); int iBase = headerIndex.get("base"); int iExp = headerIndex.get("exp"); int iSystem = headerIndex.get("system"); String line; List<UnitPrefix> list = new ArrayList<>(); while ((line = br.readLine()) != null) { String[] fields = commaPattern.split(line); double base = Double.parseDouble(fields[iBase]); double exp = Double.parseDouble(fields[iExp]); double scale = Math.pow(base, exp); UnitPrefix unitPrefix = new UnitPrefix(fields[iName], fields[iPrefix], scale, fields[iSystem]); list.add(unitPrefix); } br.close(); return list; } }
String[] names = NAME_SEPARATOR.split(name); if (names != null && names.length > 0) { Activate activate = clazz.getAnnotation(Activate.class); if (activate != null) { cachedActivates.put(names[0], activate); } else { cachedActivates.put(names[0], oldActivate); cachedNames.put(clazz, n); Class<?> c = extensionClasses.get(n); if (c == null) { extensionClasses.put(n, clazz); } else if (c != clazz) { throw new IllegalStateException("Duplicate extension " + type.getName() + " name " + n + " on " + c.getName() + " and " + clazz.getName());
if (skillRequirements.get(taskBuffer + " " + rowText) != null) if (skillRequirements.get(taskBuffer) != null) String levelRequirement = skillRequirements.get(taskBuffer); String task = originalAchievements.get(i); newRequirements.add(i + (++offset), strike + levelRequirement); b.append(task); int runningWidth = font.getTextWidth(b.toString()); for (String word : AND_JOINER_PATTERN.split(levelRequirement)) newRequirements.add(i + (offset++), b.toString()); b.delete(0, b.length()); runningWidth = wordWidth;
stat = new Status(Status.Level.ERROR, t.getMessage()); statuses.put(name, stat); if (stat.getLevel() != null && stat.getLevel() != Status.Level.UNKNOWN) { List<String> row = new ArrayList<String>(); row.add(name); row.add(String.valueOf(stat.getLevel())); row.add(stat.getMessage() == null ? "" : stat.getMessage()); table.add(row); Map<String, Status> statuses = new HashMap<String, Status>(); if (CollectionUtils.isNotEmptyMap(statuses)) { String[] ss = Constants.COMMA_SPLIT_PATTERN.split(status); for (String s : ss) { StatusChecker handler = extensionLoader.getExtension(s); stat = new Status(Status.Level.ERROR, t.getMessage()); statuses.put(s, stat);
for (String name : def) { if (ExtensionLoader.getExtensionLoader(type).hasExtension(name)) { defaults.add(name); String[] configs = (cfg == null || cfg.trim().length() == 0) ? new String[0] : Constants.COMMA_SPLIT_PATTERN.split(cfg); for (String config : configs) { if (config != null && config.trim().length() > 0) { names.add(config);
boolean validPosPatternSet = false; boolean headerSet = false; String[] allOptions = COMMA_DELIMITERS_PATTERN.split(mappings[index].trim()); Integer numOptions = allOptions.length; String filePath = allOptions[allOptions.length - 1]; if (numOptions > 1) { // there are some per file options here for (int i = 0; i < numOptions-1; i++) { String[] optionAndValue = EQUALS_DELIMITERS_PATTERN.split(allOptions[i].trim()); if (optionAndValue.length != 2) { throw new IllegalArgumentException("TokensRegexNERAnnotator " + annotatorName switch (optionAndValue[0].trim().toLowerCase()) { case "ignorecase": ignoreCaseList.add(Boolean.parseBoolean(optionAndValue[1].trim())); ignoreCaseSet = true; break; String validPosRegex = optionAndValue[1].trim(); if ( ! StringUtils.isNullOrEmpty(validPosRegex)) { validPosPatternList.add(Pattern.compile(validPosRegex)); } else { validPosPatternList.add(validPosPattern); String headerLine = br.readLine(); headerItems = headerLine.split("\\t"); } catch (IOException e) {
/** * <p> * Resolves a class file locator for the class path that reads class files directly from the file system. * </p> * <p> * <b>Note</b>: The resulting class file locator does not include classes of the bootstrap class loader. * </p> * * @param classPath The class path to scan with the elements separated by {@code path.separator}. * @return A class file locator for the class path. * @throws IOException If an I/O exception occurs. */ public static ClassFileLocator ofClassPath(String classPath) throws IOException { List<ClassFileLocator> classFileLocators = new ArrayList<ClassFileLocator>(); for (String element : Pattern.compile(System.getProperty("path.separator"), Pattern.LITERAL).split(classPath)) { File file = new File(element); if (file.isDirectory()) { classFileLocators.add(new ForFolder(file)); } else if (file.isFile()) { classFileLocators.add(of(file)); } } return new Compound(classFileLocators); }
Double score = null; List<ScoredObject<Tree>> curParses = null; while ((line = br.readLine()) != null) { line = line.trim(); if ( ! line.isEmpty()) { if (parsesExpected == 0) { String[] fields = wsDelimiter.split(line, 2); parsesExpected = Integer.parseInt(fields[0]); sentenceId = Integer.parseInt(fields[1]); if (score == null) { score = Double.parseDouble(wsDelimiter.split(line, 2)[0]); } else { curParses.add(curParse); curParse = null; score = null;
public static Map<String,String> readMap(String filename) throws IOException { Map<String,String> map = Generics.newHashMap(); try { BufferedReader br = IOUtils.getBufferedFileReader(filename); for (String line; (line = br.readLine()) != null; ) { String[] fields = tab.split(line,2); map.put(fields[0], fields[1]); } br.close(); } catch (IOException ex) { throw new RuntimeException(ex); } return map; }
String[] fields = wsPattern.split(str); Number[] numFields = new Number[fields.length]; int numWords = fields.length; curNum = word2NumMap.get(curPart); } else if (ordWord2NumMap.containsKey(curPart)) { if (curIndex == numWords-1){ curNum = ordWord2NumMap.get(curPart); } else { throw new NumberFormatException("Error in wordToNumber function."); curNum = ordWord2NumMap.get(curPart.substring(0, curPart.length()-1)); if (curNum != null) { curNum = 1/curNum.doubleValue();
lexicon = Generics.newHashMap(); boolean terryKoo = "terryKoo".equals(flags.distSimFileFormat); Pattern p = Pattern.compile(terryKoo ? "\\t" : "\\s+"); for (String line : ObjectBank.getLineIterator(flags.distSimLexicon, flags.inputEncoding)) { String wordClass; if (terryKoo) { String[] bits = p.split(line); word = bits[1]; wordClass = bits[0]; String[] bits = p.split(line); word = bits[0]; wordClass = bits[1]; word = WordShapeClassifier.wordShape(word, WordShapeClassifier.WORDSHAPEDIGITS); lexicon.put(word, wordClass);
public static void checkOddEvenResult(BufferedReader result) throws IOException { Pattern split = Pattern.compile(" "); String line; while ((line = result.readLine()) != null) { String[] res = split.split(line); Assert.assertEquals("Malformed result: Wrong number of tokens in line.", 2, res.length); try { int from = Integer.parseInt(res[0]); int to = Integer.parseInt(res[1]); Assert.assertEquals("Vertex should not be reachable.", from % 2, to % 2); } catch (NumberFormatException e) { Assert.fail("Malformed result."); } } }
/** * Read column as set * @param infile - filename * @param field index of field to read * @return a set of the entries in column field * @throws IOException */ public static Set<String> readColumnSet(String infile, int field) throws IOException { BufferedReader br = IOUtils.getBufferedFileReader(infile); Set<String> set = Generics.newHashSet(); for (String line; (line = br.readLine()) != null; ) { line = line.trim(); if (line.length() > 0) { if (field < 0) { set.add(line); } else { String[] fields = tab.split(line); if (field < fields.length) { set.add(fields[field]); } } } } br.close(); return set; }
Map<String, Inet6Address> ipv6Entries = new HashMap<String, Inet6Address>(); String line; while ((line = buff.readLine()) != null) { for (String s: WHITESPACES.split(line)) { if (!s.isEmpty()) { lineParts.add(s); InetAddress address = InetAddress.getByAddress(hostname, ipBytes); if (address instanceof Inet4Address) { Inet4Address previous = ipv4Entries.put(hostnameLower, (Inet4Address) address); if (previous != null) { ipv4Entries.put(hostnameLower, previous); Inet6Address previous = ipv6Entries.put(hostnameLower, (Inet6Address) address); if (previous != null) {
String[] names = NAME_SEPARATOR.split(name); if (names != null && names.length > 0) { Activate activate = clazz.getAnnotation(Activate.class); if (activate != null) { cachedActivates.put(names[0], activate); } else { cachedActivates.put(names[0], oldActivate); cachedNames.put(clazz, n); Class<?> c = extensionClasses.get(n); if (c == null) { extensionClasses.put(n, clazz); } else if (c != clazz) { throw new IllegalStateException("Duplicate extension " + type.getName() + " name " + n + " on " + c.getName() + " and " + clazz.getName());
public static List<URL> parseURLs(String address, Map<String, String> defaults) { if (address == null || address.length() == 0) { return null; } String[] addresses = Constants.REGISTRY_SPLIT_PATTERN.split(address); if (addresses == null || addresses.length == 0) { return null; //here won't be empty } List<URL> registries = new ArrayList<URL>(); for (String addr : addresses) { registries.add(parseURL(addr, defaults)); } return registries; }
List<RegistryConfig> registryConfigs = new ArrayList<>(); if (StringUtils.isNotEmpty(registryIds)) { Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> { if (registryConfigMap.containsKey(id)) { registryConfigs.add(registryConfigMap.get(id)); for (RegistryConfig config : registryConfigMap.values()) { if (StringUtils.isEmpty(registryIds)) { registryConfigs.add(config);