List of usage examples for org.apache.commons.lang StringUtils splitByWholeSeparatorPreserveAllTokens
public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator, int max)
Splits the provided text into an array, separator string specified.
From source file:com.livinglogic.ul4.BoundStringMethodSplit.java
public static List<String> call(String object, String separator, int maxsplit) { if (separator == null) return Arrays.asList(StringUtils.splitByWholeSeparator(object, null, maxsplit + 1)); return Arrays.asList(StringUtils.splitByWholeSeparatorPreserveAllTokens(object, separator, maxsplit + 1)); }
From source file:org.apache.tajo.engine.function.string.SplitPart.java
@Override public Datum eval(Tuple params) { if (params.isBlankOrNull(0) || params.isBlankOrNull(2)) { return NullDatum.get(); }// ww w . ja v a2s . co m String[] split = StringUtils.splitByWholeSeparatorPreserveAllTokens(params.getText(0), params.getText(1), -1); int idx = params.getInt4(2) - 1; if (split.length > idx) { return DatumFactory.createText(split[idx]); } else { // If part is larger than the number of string portions, it will returns NULL. return NullDatum.get(); } }
From source file:org.eclipse.jubula.client.cmd.utils.VersionStringUtils.java
/** * There are different formats possible<br> * [majNum]<br>//from w ww . j a v a 2 s .c om * [majNum].[minNum]<br> * [majNum].[minNum].[micNum]<br> * [majNum].[minNum].[micNum]_[qualifier]<br> * [qualifier]<br> * @param version a string representation of a project version * @return the {@link ProjectVersion} for the corresponding string * @throws MalformedVersionException when the version is not of the wanted format */ public static ProjectVersion createProjectVersion(String version) throws MalformedVersionException { String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(version, "_", 2); //$NON-NLS-1$ if (tokens.length == 1) { try { return createVersionsNumbers(tokens[0]); } catch (NumberFormatException nfe) { // It is only given a qualifier return new ProjectVersion(tokens[0]); } catch (MalformedVersionException nfe) { // It is only given a qualifier return new ProjectVersion(tokens[0]); } } else if (tokens.length == 2) { ProjectVersion projectNumbers = new ProjectVersion(null); if (StringUtils.isNotBlank(tokens[0])) { try { projectNumbers = createVersionsNumbers(tokens[0]); } catch (NumberFormatException e) { throw new MalformedVersionException("parsing the version:" //$NON-NLS-1$ + tokens[0] + " as numbers, was not possible"); //$NON-NLS-1$ } } String qualifier = tokens[1]; return new ProjectVersion(projectNumbers.getMajorNumber(), projectNumbers.getMinorNumber(), projectNumbers.getMicroNumber(), qualifier); } throw new MalformedVersionException("No version Token found"); //$NON-NLS-1$ }
From source file:org.kiji.schema.layout.ColumnNameTranslator.java
/** * Translates an HBase column name to a Kiji column name. * * @param hbaseColumnName The HBase column name. * @return The Kiji column name.// www . j a v a2 s. com * @throws NoSuchColumnException If the column name cannot be found. */ public KijiColumnName toKijiColumnName(HBaseColumnName hbaseColumnName) throws NoSuchColumnException { LOG.debug(String.format("Translating HBase column name '%s' to Kiji column name...", hbaseColumnName)); final ColumnId lgId = ColumnId.fromByteArray(hbaseColumnName.getFamily()); final LocalityGroupLayout localityGroup = mLocalityGroups.get(lgId); if (null == localityGroup) { throw new NoSuchColumnException(String.format("No locality group with ID/HBase family: '%s'.", hbaseColumnName.getFamilyAsString())); } final String[] parts = StringUtils .splitByWholeSeparatorPreserveAllTokens(hbaseColumnName.getQualifierAsString(), SEPARATOR, 2); if (2 != parts.length) { throw new NoSuchColumnException("Missing separator (" + SEPARATOR + ") from HBase qualifier (" + hbaseColumnName.getQualifierAsString() + "). Unable to parse Kiji family/qualifier pair."); } final ColumnId familyId = ColumnId.fromString(parts[0]); final FamilyLayout kijiFamily = getKijiFamilyById(localityGroup, familyId); if (null == kijiFamily) { throw new NoSuchColumnException(String.format("No family with ColumnId '%s' in locality group '%s'.", familyId, localityGroup.getDesc().getName())); } if (kijiFamily.isGroupType()) { // Group type family. final ColumnId columnId = ColumnId.fromString(parts[1]); final ColumnLayout kijiColumn = getKijiColumnById(kijiFamily, columnId); if (null == kijiColumn) { throw new NoSuchColumnException(String.format("No column with ColumnId '%s' in family '%s'.", columnId, kijiFamily.getDesc().getName())); } final KijiColumnName result = new KijiColumnName(kijiFamily.getDesc().getName(), kijiColumn.getDesc().getName()); LOG.debug(String.format("Translated to Kiji group column '%s'.", result)); return result; } // Map type family. assert kijiFamily.isMapType(); final KijiColumnName result = new KijiColumnName(kijiFamily.getDesc().getName(), parts[1]); LOG.debug(String.format("Translated to Kiji map column '%s'.", result)); return result; }
From source file:org.kiji.schema.layout.impl.IdentityColumnNameTranslator.java
/** {@inheritDoc} */ @Override//from w ww .ja v a 2s . c om public KijiColumnName toKijiColumnName(HBaseColumnName hbaseColumnName) throws NoSuchColumnException { LOG.debug("Translating HBase column name '{}' to Kiji column name...", hbaseColumnName); final LocalityGroupLayout localityGroup = mTableLayout.getLocalityGroupMap() .get(hbaseColumnName.getFamilyAsString()); if (null == localityGroup) { throw new NoSuchColumnException(String.format("No locality group with ID/HBase family: '%s'.", hbaseColumnName.getFamilyAsString())); } final String[] parts = StringUtils .splitByWholeSeparatorPreserveAllTokens(hbaseColumnName.getQualifierAsString(), SEPARATOR, 2); if (2 != parts.length) { throw new NoSuchColumnException("Missing separator (" + SEPARATOR + ") from HBase qualifier (" + hbaseColumnName.getQualifierAsString() + "). Unable to parse Kiji family/qualifier pair."); } String family = parts[0]; final FamilyLayout kijiFamily = mTableLayout.getFamilyMap().get(family); if (null == kijiFamily) { throw new NoSuchColumnException(String.format("No family with ColumnId '%s' in locality group '%s'.", family, localityGroup.getDesc().getName())); } if (kijiFamily.isGroupType()) { // Group type family. String column = parts[1]; final ColumnLayout kijiColumn = kijiFamily.getColumnMap().get(column); if (null == kijiColumn) { throw new NoSuchColumnException(String.format("No column with ColumnId '%s' in family '%s'.", column, kijiFamily.getDesc().getName())); } final KijiColumnName result = new KijiColumnName(kijiFamily.getDesc().getName(), kijiColumn.getDesc().getName()); LOG.debug("Translated to Kiji group column '{}'.", result); return result; } // Map type family. assert kijiFamily.isMapType(); final KijiColumnName result = new KijiColumnName(kijiFamily.getDesc().getName(), parts[1]); LOG.debug("Translated to Kiji map column '{}'.", result); return result; }
From source file:org.kiji.schema.layout.impl.ShortColumnNameTranslator.java
/** {@inheritDoc} */ @Override//from ww w . j a v a 2 s . c o m public KijiColumnName toKijiColumnName(HBaseColumnName hbaseColumnName) throws NoSuchColumnException { LOG.debug("Translating HBase column name '{}' to Kiji column name...", hbaseColumnName); final ColumnId lgId = ColumnId.fromByteArray(hbaseColumnName.getFamily()); final LocalityGroupLayout localityGroup = mLocalityGroups.get(lgId); if (null == localityGroup) { throw new NoSuchColumnException(String.format("No locality group with ID/HBase family: '%s'.", hbaseColumnName.getFamilyAsString())); } final String[] parts = StringUtils .splitByWholeSeparatorPreserveAllTokens(hbaseColumnName.getQualifierAsString(), SEPARATOR, 2); if (2 != parts.length) { throw new NoSuchColumnException("Missing separator (" + SEPARATOR + ") from HBase qualifier (" + hbaseColumnName.getQualifierAsString() + "). Unable to parse Kiji family/qualifier pair."); } final ColumnId familyId = ColumnId.fromString(parts[0]); final FamilyLayout kijiFamily = getKijiFamilyById(localityGroup, familyId); if (null == kijiFamily) { throw new NoSuchColumnException(String.format("No family with ColumnId '%s' in locality group '%s'.", familyId, localityGroup.getDesc().getName())); } if (kijiFamily.isGroupType()) { // Group type family. final ColumnId columnId = ColumnId.fromString(parts[1]); final ColumnLayout kijiColumn = getKijiColumnById(kijiFamily, columnId); if (null == kijiColumn) { throw new NoSuchColumnException(String.format("No column with ColumnId '%s' in family '%s'.", columnId, kijiFamily.getDesc().getName())); } final KijiColumnName result = new KijiColumnName(kijiFamily.getDesc().getName(), kijiColumn.getDesc().getName()); LOG.debug("Translated to Kiji group column '{}'.", result); return result; } // Map type family. assert kijiFamily.isMapType(); final KijiColumnName result = new KijiColumnName(kijiFamily.getDesc().getName(), parts[1]); LOG.debug("Translated to Kiji map column '{}'.", result); return result; }
From source file:org.openmrs.module.emrmonitor.metric.ConfigurableMetricProducer.java
/** * If multiple lines of output are returned and each is in the format of key=value, then the key will be considered part of the metric, and the value the value * Otherwise, the full contents of output will be the value of a single metric *//*w w w . j a v a 2s.co m*/ protected void handleShellScript(Map<String, String> metrics, String namespace, File f) throws IOException { Process process = Runtime.getRuntime().exec(f.getAbsolutePath()); StringBuilder singleValueMetric = new StringBuilder(); Map<String, String> keyValueMetrics = new LinkedHashMap<String, String>(); LineIterator successIterator = null; try { successIterator = IOUtils.lineIterator(process.getInputStream(), "UTF-8"); while (successIterator.hasNext()) { String line = successIterator.nextLine(); String[] split = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, "=", 2); if (split.length == 2) { keyValueMetrics.put(namespace + "." + split[0], split[1]); } else { singleValueMetric.append(line).append(System.getProperty("line.separator")); } } if (singleValueMetric.length() > 0) { metrics.put(namespace, singleValueMetric.toString()); } else { metrics.putAll(keyValueMetrics); } } finally { successIterator.close(); } StringBuilder error = new StringBuilder(); LineIterator errorIterator = null; try { errorIterator = IOUtils.lineIterator(process.getErrorStream(), "UTF-8"); while (errorIterator.hasNext()) { String line = errorIterator.nextLine(); error.append(System.getProperty("line.separator")).append(line); } } finally { errorIterator.close(); } if (error.length() > 0) { throw new RuntimeException( "An error occurred while executing shell script " + f.getName() + ": " + error); } }