List of usage examples for org.apache.commons.lang StringUtils substring
public static String substring(String str, int start)
Gets a substring from the specified String avoiding exceptions.
From source file:org.onosproject.influxdbmetrics.DefaultInfluxDbMetricsRetriever.java
/** * Returns metric name from full name.// ww w . j a v a2s.c om * The elements in full name is split by using '.'; * We assume that the metric name always comes after the last three '.' * * @param fullName full name * @return metric name */ private String getMetricName(String fullName) { int index = StringUtils.lastOrdinalIndexOf(fullName, METRIC_DELIMITER, NUB_OF_DELIMITER); if (index != -1) { return StringUtils.substring(fullName, index + 1); } else { log.warn("Database {} contains malformed metric name.", database); return null; } }
From source file:org.openhab.io.neeo.internal.models.NeeoThingUID.java
/** * Construct the {@link NeeoThingUID} from the string representation of a UID. If the string representation includes * {@link NeeoConstants#NEEO_ADAPTER_PREFIX}, that prefix will be removed. * * @param thingId the thing ID//ww w . ja v a 2 s.c o m */ public NeeoThingUID(String thingId) { super(StringUtils.startsWith(thingId, NeeoConstants.NEEO_ADAPTER_PREFIX) ? StringUtils.substring(thingId, NeeoConstants.NEEO_ADAPTER_PREFIX.length()) : thingId); }
From source file:org.opentestsystem.authoring.testauth.publish.BasePublisherHelper.java
protected List<TestBlueprintElement> setupBlueprintData(final Assessment assessment, final List<Item> itemList, final List<Segment> segmentList, final List<BlueprintElement> blueprintElementList, final List<AffinityGroup> affinityGroupList) { final List<TestBlueprintElement> blueprintList = Lists.newArrayList(); int testLevelOpMin = 0, testLevelOpMax = 0, testLevelFtMin = 0, testLevelFtMax = 0, testLevelOpItemCount = 0, testLevelFtItemCount = 0; // roll up all totals per segment final Map<String, ItemCountSummary> masterItemCounts = new HashMap<String, ItemCountSummary>(); final List<TestBlueprintElement> segmentBlueprintList = Lists.newArrayList(); for (final Segment segment : segmentList) { final boolean isFixedFormSegment = segment.getItemSelectionAlgorithm().getItemSelectionAlgorithmType() .equals(ItemSelectionAlgorithmType.FIXEDFORM); final Map<String, ItemCountSummary> blueprintItemCountsBySegment = getBlueprintItemCounts(assessment, itemList, segment.getId(), blueprintElementList, isFixedFormSegment); // in order to avoid multiple adding int segmentLevelOpItemCount = 0, segmentLevelFtItemCount = 0; final Map<String, ItemCountSummary> blueprintItemCountsBySegmentByStrands = getBlueprintItemCountsByStrands( assessment, itemList, segment.getId(), blueprintElementList, isFixedFormSegment); for (final Entry<String, ItemCountSummary> blueprintElementCount : blueprintItemCountsBySegmentByStrands .entrySet()) {/*from w w w . j ava 2 s .co m*/ segmentLevelOpItemCount = segmentLevelOpItemCount + blueprintElementCount.getValue().getOpCount(); segmentLevelFtItemCount = segmentLevelFtItemCount + blueprintElementCount.getValue().getFtCount(); } for (final Entry<String, ItemCountSummary> blueprintElementCount : blueprintItemCountsBySegment .entrySet()) { // roll up totals by blueprint standard for master level ItemCountSummary masterBpElementItemCounts = masterItemCounts.get(blueprintElementCount.getKey()); if (masterBpElementItemCounts == null) { masterBpElementItemCounts = new ItemCountSummary(); masterItemCounts.put(blueprintElementCount.getKey(), masterBpElementItemCounts); } final int newOpCount = TestAuthUtil.safeParseInt(masterBpElementItemCounts.getOpCount()) + blueprintElementCount.getValue().getOpCount(); masterBpElementItemCounts.setOpCount(newOpCount); final int newFtCount = TestAuthUtil.safeParseInt(masterBpElementItemCounts.getFtCount()) + blueprintElementCount.getValue().getFtCount(); masterBpElementItemCounts.setFtCount(newFtCount); } // segment level // AK: if there is only one segment segment uniqueid must be equal test(assessment) uniqueid segmentBlueprintList.add(new TestBlueprintElement( new Identifier( (segmentList.size() == 1) ? buildIdentifier(assessment.getName(), assessment.getLabel(), assessment.getVersion()).getUniqueId() : segment.getId(), segment.getLabel(), segment.getLabel(), DEFAULT_VERSION), "segment", buildIdentifier(assessment.getName(), assessment.getLabel(), assessment.getVersion()) .getUniqueId(), segment.getMinOpItems(), segment.getMaxOpItems(), segment.getMinFtItems(), segment.getMaxFtItems(), segmentLevelOpItemCount, segmentLevelFtItemCount)); testLevelOpMin = testLevelOpMin + segment.getMinOpItems(); testLevelOpMax = testLevelOpMax + segment.getMaxOpItems(); testLevelFtMin = testLevelFtMin + segment.getMinFtItems(); testLevelFtMax = testLevelFtMax + segment.getMaxFtItems(); testLevelOpItemCount = testLevelOpItemCount + segmentLevelOpItemCount; testLevelFtItemCount = testLevelFtItemCount + segmentLevelFtItemCount; } // master bp elemenets String name = null; final List<TestBlueprintElement> masterBlueprintList = Lists.newArrayList(); for (final BlueprintElement blueprintElement : blueprintElementList) { // StandardKey at this point has 'client' as prefix; 'name' element does not need this prefix int pubEndPos = StringUtils.indexOf(blueprintElement.getStandardKey(), "-"); if (pubEndPos > 0) name = StringUtils.substring(blueprintElement.getStandardKey(), pubEndPos + 1); masterBlueprintList.add(new TestBlueprintElement( new Identifier(blueprintElement.getStandardKey(), name, null, DEFAULT_VERSION), blueprintElement.getElementTypeName(), blueprintElement.getParentKey(), blueprintElement.getMasterValue().getOperationalItemMinValue(), blueprintElement.getMasterValue().getOperationalItemMaxValue(), blueprintElement.getMasterValue().getFieldTestItemMinValue(), blueprintElement.getMasterValue().getFieldTestItemMaxValue(), masterItemCounts.get(blueprintElement.getStandardKey()).getOpCount(), masterItemCounts.get(blueprintElement.getStandardKey()).getFtCount())); } // top/test level final List<TestBlueprintElement> testBlueprintList = Lists.newArrayList(); // this change has to fix null -> uniqueid for bpelement with type = 'test' // this uniqueid must be the same as testspecificationUniqueid TestBlueprintElement tbp = new TestBlueprintElement( buildIdentifier(assessment.getName(), assessment.getLabel(), assessment.getVersion()), "test", null, testLevelOpMin, testLevelOpMax, testLevelFtMin, testLevelFtMax, testLevelOpItemCount, testLevelFtItemCount); tbp.getIdentifier().setName(assessment.getName() + '-' + assessment.getVersion()); testBlueprintList.add(tbp); final List<TestBlueprintElement> affinityGroupBlueprintList = Lists.newArrayList(); for (final AffinityGroup affinityGroup : affinityGroupList) { affinityGroupBlueprintList.add(new TestBlueprintElement( buildIdentifier(affinityGroup.getGroupName(), null, DEFAULT_VERSION), "affinitygroup", buildIdentifier(assessment.getName(), assessment.getLabel(), assessment.getVersion()) .getUniqueId())); } blueprintList.addAll(testBlueprintList); blueprintList.addAll(segmentBlueprintList); blueprintList.addAll(masterBlueprintList); blueprintList.addAll(affinityGroupBlueprintList); return blueprintList; }
From source file:org.opentestsystem.authoring.testauth.publish.PublisherUtil.java
protected static final Integer versionTransformer(final String version) { try {// ww w .j av a2s . c o m int decimalSeparatorPosition = StringUtils.indexOf(version, DECIMALSEPARATOR); String fraction = StringUtils.substring(version, decimalSeparatorPosition + 1); String integerPart = version.substring(0, decimalSeparatorPosition); Integer fracPart = Integer.valueOf(fraction); Integer intPart = Integer.valueOf(integerPart); return intPart * MAXIMUMMINORVERSIONS + fracPart; } catch (Exception e) { return 0; } }
From source file:org.opentestsystem.authoring.testauth.service.impl.BlueprintElementServiceImpl.java
private String convertIntoBlueprintCompatible(String client, String standardKey) { //EF: we have CoreStandards as "SBAC-ELA-v1:2-W" and need to transform to "SBAC-2-W" to match // what we store in BlueprintElement collection int pubEndPos = StringUtils.indexOf(standardKey, ":"); if (pubEndPos > 0) return (client.concat("-").concat(StringUtils.substring(standardKey, pubEndPos + 1))); else//ww w .j a v a 2 s. com return (client.concat("-").concat(standardKey)); }
From source file:org.pentaho.platform.plugin.services.importexport.legacy.FileSolutionRepositoryImportSource.java
protected String getRepositoryPath(final File currentFile) { String repositoryPath = ""; if (recursive) { final String parentFilePath = currentFile.getAbsoluteFile().getParent(); repositoryPath = StringUtils.substring(parentFilePath, sourceParentFilePath.length()); }//from www . ja va 2 s.c om return repositoryPath; }
From source file:org.sakaiproject.lap.util.FileUtils.java
/** * Method to parse a directory for sub-directories * /*from ww w .j a v a 2s.c om*/ * @param directory the directory to parse * @param type the type of extraction (manual, scheduled, "" = get all) * @return a listing of the sub-directory names */ public static List<String> parseDirectory(String directory, String type) { if (StringUtils.isBlank(directory)) { throw new NullArgumentException("Directory"); } // if type extension passed in does not match a configured type, get all sub-directories if (!Constants.EXTRACTION_TYPE_MAP.containsKey(type)) { type = ""; } boolean getAll = StringUtils.isBlank(type); List<String> directories = new ArrayList<String>(); try { File fileDirectory = new File(directory); File[] files = fileDirectory.listFiles(); if (files != null) { for (File subDirectory : files) { // only store sub-directory names if (subDirectory.isDirectory()) { String directoryExtractionType = StringUtils.substring(subDirectory.getName(), subDirectory.getName().length() - 2); if (getAll || StringUtils.equalsIgnoreCase(directoryExtractionType, type)) { directories.add(subDirectory.getName()); } } } } // sort the list, newest directories first Collections.sort(directories, new DateComparatorLatestToEarliest()); } catch (Exception e) { // swallow exception (for now...) } return directories; }
From source file:org.sipfoundry.sipxconfig.admin.dialplan.AutoAttendant.java
public static Integer getIdFromSystemId(String attendantId) { if (StringUtils.startsWith(attendantId, SYSTEM_NAME_PREFIX)) { return Integer.parseInt(StringUtils.substring(attendantId, SYSTEM_NAME_PREFIX.length() + 1)); }/*from w w w . j a va 2 s. co m*/ return null; }
From source file:org.sipfoundry.sipxconfig.gateway.GatewayCallerAliasInfo.java
/** * Transforms user extension into from header * * @param user for which we are transforming extension * @return transformed extension which should be used, or null if there is nothing to * transform//w w w .j a v a 2 s.c om */ public String getTransformedNumber(User user) { if (!m_transformUserExtension) { return null; } String extension = user.getExtension(true); if (extension == null) { // nothing to transform return null; } if (m_keepDigits > 0) { extension = StringUtils.substring(extension, -m_keepDigits); } if (m_addPrefix != null) { extension = m_addPrefix + extension; } return extension; }
From source file:org.sonar.api.batch.fs.internal.PathPattern.java
public static PathPattern create(String s) { String trimmed = StringUtils.trim(s); if (StringUtils.startsWithIgnoreCase(trimmed, "file:")) { return new AbsolutePathPattern(StringUtils.substring(trimmed, "file:".length())); }/*from ww w. ja v a2 s .c om*/ return new RelativePathPattern(trimmed); }