List of usage examples for org.apache.commons.lang StringUtils split
public static String[] split(String str, String separatorChars)
Splits the provided text into an array, separators specified.
From source file:com.mirth.connect.model.converters.XMLEncodedHL7Handler.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { logger.trace("starting element: " + localName); inElement = true;/*from w ww .j a v a 2 s . c o m*/ String[] localNameArray = StringUtils.split(localName, ID_DELIMETER); if (rootLevel == -1) { rootLevel = localNameArray.length; } /* * Skip the root element, MSH.1, and MSH.2 since those don't have any * data that we care about. */ if ((localNameArray.length == 1) && (localNameArray[0].equals(ER7Reader.MESSAGE_ROOT_ID))) { rootLevel = 0; return; } else if (localNameArray.length == 2) { if (isHeaderSegment(localNameArray[0])) { if ((localNameArray[1].length() == 1) && (localNameArray[1].charAt(0) == '1' || localNameArray[1].charAt(0) == '2')) { previousFieldNameArray = localNameArray; return; } } } /* * If the element that we've found is the same as the last, then we have * a repetition, so we remove the last separator that was added and * append to repetition separator. */ if (ArrayUtils.isEquals(localNameArray, previousFieldNameArray)) { output.deleteCharAt(output.length() - 1); output.append(repetitionSeparator); return; } /* * To find the delimeter count we are splitting the element name by the * ID delimeter. */ int currentDelimeterCount = localNameArray.length - 1; /* * MIRTH-2078: Don't add missing fields/components/subcomponents if the * current level was the starting level. This only pertains to partial * XML messages where the root is a field or component. */ if (currentDelimeterCount == 1 && rootLevel <= 1) { /* * This will add missing fields if any (ex. between OBX.1 and * OBX.5). */ int previousFieldId = 0; if (previousFieldNameArray != null) { previousFieldId = NumberUtils.toInt(previousFieldNameArray[1]); } int currentFieldId = NumberUtils.toInt(localNameArray[1]); for (int i = 1; i < (currentFieldId - previousFieldId); i++) { output.append(fieldSeparator); } previousFieldNameArray = localNameArray; } else if (currentDelimeterCount == 2 && rootLevel <= 2) { /* * This will add missing components if any (ex. between OBX.1.1 and * OBX.1.5). */ int previousComponentId = 0; if (previousComponentNameArray != null) { previousComponentId = NumberUtils.toInt(previousComponentNameArray[2]); } int currentComponentId = NumberUtils.toInt(localNameArray[2]); for (int i = 1; i < (currentComponentId - previousComponentId); i++) { output.append(componentSeparator); } previousComponentNameArray = localNameArray; } else if (currentDelimeterCount == 3 && rootLevel <= 3) { /* * This will add missing subcomponents if any (ex. between OBX.1.1.1 * and OBX.1.1.5). */ int previousSubcomponentId = 0; if (previousSubcomponentNameArray != null) { previousSubcomponentId = NumberUtils.toInt(previousSubcomponentNameArray[3]); } int currentSubcomponentId = NumberUtils.toInt(localNameArray[3]); for (int i = 1; i < (currentSubcomponentId - previousSubcomponentId); i++) { output.append(subcomponentSeparator); } previousSubcomponentNameArray = localNameArray; } /* * If we have an element with no periods, then we know its the name of * the segment, so write it to the output buffer followed by the field * separator. */ if (currentDelimeterCount == 0) { output.append(localName); output.append(fieldSeparator); /* * Also set previousFieldName to null so that multiple segments in a * row with only one field don't trigger a repetition character. * (i.e. NTE|1<CR>NTE|2) */ previousFieldNameArray = null; } else if (currentDelimeterCount == 1) { previousComponentNameArray = null; } }
From source file:com.goosby.virgo.utils.PageRequest.java
/** * ??.//w w w . j av a 2 s .c o m */ public List<Sort> getSort() { final String[] orderBys = StringUtils.split(this.orderBy, ','); final String[] orderDirs = StringUtils.split(this.orderDir, ','); final List<Sort> orders = new ArrayList<Sort>(); for (int i = 0; i < orderBys.length; i++) { orders.add(new Sort(orderBys[i], orderDirs[i])); } return orders; }
From source file:com.adobe.acs.tools.csv.impl.Column.java
public T[] getMultiData(String data) { final String[] vals = StringUtils.split(data, this.multiDelimiter); final List<T> list = new ArrayList<T>(); for (String val : vals) { T obj = (T) this.toObjectType(val, this.getDataType()); list.add(obj);//from w w w .java 2 s .c o m } return list.toArray((T[]) Array.newInstance((this.getDataType()), 0)); }
From source file:edu.cornell.kfs.module.receiptProcessing.batch.ReceiptProcessingCSVInputFileType.java
public String getAuthorPrincipalName(File file) { String[] fileNameParts = StringUtils.split(file.getName(), FILE_NAME_DELIM); if (fileNameParts.length > 3) { return fileNameParts[2]; }//ww w . j a va 2s. co m return null; }
From source file:ml.shifu.shifu.udf.EvalScoreUDFTest.java
public void testBelowScore() throws IOException { String data = "B|13.87|20.7|89.77|584.8|0.09578|0.1018|0.03688|0.02369|0.162|0.06688|0.272|1.047|2.076|23.12|0.006298|0.02172|0.02615|0.009061|0.0149|0.003599|15.05|24.75|99.17|688.6|0.1264|0.2037|0.1377|0.06845|0.2249|0.08492"; String[] fields = data.split("\\|"); Tuple input = TupleFactory.getInstance().newTuple(fields.length); for (int i = 0; i < fields.length; i++) { input.set(i, fields[i]);/*from w w w.java 2 s .c o m*/ } check(instance.exec(input), StringUtils.split("B,1.0,7,11,3,8,6,8,11,3,8", ",")); }
From source file:com.netflix.simianarmy.aws.janitor.rule.asg.DiscoveryASGInstanceValidator.java
/** {@inheritDoc} */ @Override//from w w w . j a va2 s. c o m public boolean hasActiveInstance(Resource resource) { String instanceIds = resource.getAdditionalField(ASGJanitorCrawler.ASG_FIELD_INSTANCES); String maxSizeStr = resource.getAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE); if (StringUtils.isBlank(instanceIds)) { if (maxSizeStr != null && Integer.parseInt(maxSizeStr) == 0) { // The ASG is empty when it has no instance and the max size of the ASG is 0. // If the max size is not 0, the ASG could probably be in the process of starting new instances. LOGGER.info(String.format("ASG %s is empty.", resource.getId())); return false; } else { LOGGER.info(String.format("ASG %s does not have instances but the max size is %s", resource.getId(), maxSizeStr)); return true; } } String[] instances = StringUtils.split(instanceIds, ","); LOGGER.debug(String.format("Checking if the %d instances in ASG %s are active.", instances.length, resource.getId())); for (String instanceId : instances) { if (isActiveInstance(instanceId)) { LOGGER.info(String.format("ASG %s has active instance.", resource.getId())); return true; } } LOGGER.info(String.format("ASG %s has no active instance.", resource.getId())); return false; }
From source file:com.jaxio.celerio.support.AbstractNamer.java
/** * Get node of the package name./*from w w w . j av a 2 s . c om*/ * <p> * Ex: Assuming the package name is<code>com.jaxio.toto.tutu</code> you get <br> * <code>getPackageNode(0) -> tutu</code> <br> * <code>getPackageNode(1) = toto</code> etc. */ public String getPackageNode(int index) { if (packageNodes == null) { packageNodes = StringUtils.split(getPackageName(), '.'); } int i = packageNodes.length - 1 - index; if (i >= 0 && i < packageNodes.length) { return packageNodes[i]; } return ""; }
From source file:com.alibaba.otter.shared.common.utils.zookeeper.ZooKeeperx.java
public ZooKeeperx(String zkServers, int sessionTimeOut) { _servers = Arrays.asList(StringUtils.split(zkServers, SERVER_COMMA)); _sessionTimeOut = sessionTimeOut; }
From source file:com.netflix.explorers.AbstractExplorerModule.java
@Override public void initialize() { LOG.info("Initialize " + name); loadPropertiesFileFromForms();/*from w w w.j av a2s .c om*/ String prefix = "com.netflix.explorers." + name + "."; config = getConfigInstance(); title = config.getString(prefix + "title", name + " (MissingTitle)"); description = config.getString(prefix + "description", name + " (MissingDescription)"); layoutName = config.getString(prefix + "pageLayout"); isCmcEnabled = config.getBoolean(prefix + "cmcEnabled", false); isSecure = config.getBoolean(prefix + "secure", false); rolesAllowed = Sets.newHashSet(StringUtils.split(config.getString(prefix + "rolesAllowed", ""), ",")); String items = config.getString(prefix + "menu"); Map<String, String> menuLayout = getMenuLayout(); if (menuLayout != null) { rootMenu = new MenuItem().setName("root").setTitle("root"); for (Entry<String, String> item : menuLayout.entrySet()) { // Parse the menu hierarchy and build it if necessary String[] nameComponents = StringUtils.split(item.getKey(), "/"); String[] pathComponents = StringUtils.split(item.getValue(), "/"); if (nameComponents.length == 1) { rootMenu.addChild( new MenuItem().setName(item.getKey()).setHref(item.getValue()).setTitle(item.getKey())); } else { if (nameComponents.length != pathComponents.length) LOG.error("Name and path must have same number of components: " + item.getKey() + " -> " + item.getValue()); MenuItem node = rootMenu; for (int i = 0; i < nameComponents.length - 1; i++) { MenuItem next = node.getChild(pathComponents[i]); if (next == null) { next = new MenuItem().setName(pathComponents[i]).setTitle(nameComponents[i]); node.addChild(next); } node = next; } MenuItem leaf = new MenuItem().setName(pathComponents[pathComponents.length - 1]) .setHref(item.getValue()).setTitle(nameComponents[nameComponents.length - 1]); // Add the menu item to the leaf node.addChild(leaf); } } } else if (items != null) { rootMenu = new MenuItem().setName("root").setTitle("root"); for (String item : StringUtils.split(items, ",")) { String[] parts = StringUtils.splitByWholeSeparator(item, "->"); try { String[] nameComponents = StringUtils.split(parts[0].trim(), "/"); MenuItem node = rootMenu; for (int i = 0; i < nameComponents.length; i++) { MenuItem next = node.getChild(nameComponents[i]); if (next == null) { next = new MenuItem().setName(nameComponents[i]).setTitle(nameComponents[i]); node.addChild(next); } node = next; } node.setHref(parts[1].trim()); } catch (Exception e) { LOG.error("Failed to load menu for explorer " + name, e); } } } LOG.info(toString()); }
From source file:com.googlecode.fascinator.messaging.ConveyerBelt.java
/** * Find out what transformers are required to run for a particular render * step.//from ww w . ja v a 2 s . c om * * @param object The digital object to transform. * @param config The configuration for the particular harvester. * @param thisType The type of render chain (step). * @param routing Flag if query is for routing. Set this value will force a * check for user priority, and then clear the flag if found. * @return List<String> A list of names for instantiated transformers. */ public static List<String> getTransformList(DigitalObject object, JsonSimpleConfig config, String thisType, boolean routing) throws StorageException { List<String> plugins = new ArrayList<String>(); Properties props = object.getMetadata(); // User initiated event if (routing) { String user = props.getProperty("userPriority"); if (user != null && user.equals("true")) { log.info("User priority flag set: '{}'", object.getId()); plugins.add(CRITICAL_USER_SELECTOR); props.remove("userPriority"); object.close(); } } // Property data, highest priority String pluginList = props.getProperty(thisType); if (pluginList != null) { // Turn the string into a real list for (String plugin : StringUtils.split(pluginList, ",")) { plugins.add(StringUtils.trim(plugin)); } } else { // The harvester specified none, fallback to the // default list for this harvest source. List<String> transformerList = config.getStringList("transformer", thisType); if (transformerList != null) { for (String entry : transformerList) { plugins.add(StringUtils.trim(entry)); } } else { log.info("No transformers configured!"); } } return plugins; }