List of usage examples for org.apache.commons.lang3 StringUtils splitByWholeSeparator
public static String[] splitByWholeSeparator(final String str, final String separator)
Splits the provided text into an array, separator string specified.
The separator(s) will not be included in the returned String array.
From source file:com.github.dactiv.common.utils.ServletUtils.java
/** * ????ServletRequest?// w w w .j a va2 s . co m * * @param request ServletRequest * @param name ??? * * @return List */ public static List<String> getParameterValues(ServletRequest request, String name) { List<String> list = new ArrayList<String>(); if (request == null || StringUtils.isEmpty(name)) { return list; } String[] values = request.getParameterValues(name); if (ArrayUtils.isNotEmpty(values)) { CollectionUtils.addAll(list, values); } else { String value = request.getParameter(name); if (StringUtils.isNotEmpty(value)) { values = StringUtils.splitByWholeSeparator(value, ","); } } if (values != null && values.length > 0) { CollectionUtils.addAll(list, values); } return list; }
From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java
/** * Bring up Stop groups per interval as String array * @param data//www . j a v a2 s .c o m * @return */ public static String[] getStopGroups(String data) { String[] stops = null; if (data != null && data.length() > 0) { String start = StringUtils.stripStart(data, "[["); String end = StringUtils.stripEnd(start, "]]"); stops = StringUtils.splitByWholeSeparator(end, "],["); } return stops; }
From source file:com.thoughtworks.go.server.cache.GoCache.java
public void removeAssociations(String key, Element element) { if (element.getObjectValue() instanceof KeyList) { synchronized (key.intern()) { for (String subkey : (KeyList) element.getObjectValue()) { remove(compositeKey(key, subkey)); }// ww w . j av a 2 s . co m } } else if (key.contains(SUB_KEY_DELIMITER)) { String[] parts = StringUtils.splitByWholeSeparator(key, SUB_KEY_DELIMITER); String parentKey = parts[0]; String childKey = parts[1]; synchronized (parentKey.intern()) { Element parent = ehCache.get(parentKey); if (parent == null) { return; } KeyList subKeys = (KeyList) parent.getObjectValue(); subKeys.remove(childKey); } } }
From source file:com.netflix.genie.web.services.impl.JobCoordinatorServiceImpl.java
/** * {@inheritDoc}// w w w . j a v a 2 s. c o m */ @Override public String coordinateJob( @Valid @NotNull(message = "No job request provided. Unable to execute.") final JobRequest jobRequest, @Valid @NotNull(message = "No job metadata provided. Unable to execute.") final JobMetadata jobMetadata) throws GenieException { final long coordinationStart = System.nanoTime(); final Set<Tag> tags = Sets.newHashSet(); final String jobId = jobRequest.getId() .orElseThrow(() -> new GenieServerException("Id of the jobRequest cannot be null")); JobStatus jobStatus = JobStatus.FAILED; try { log.info("Called to schedule job launch for job {}", jobId); // create the job object in the database with status INIT final Job.Builder jobBuilder = new Job.Builder(jobRequest.getName(), jobRequest.getUser(), jobRequest.getVersion()).withId(jobId).withTags(jobRequest.getTags()).withStatus(JobStatus.INIT) .withStatusMsg("Job Accepted and in initialization phase."); jobRequest.getCommandArgs().ifPresent(commandArgs -> jobBuilder.withCommandArgs( Lists.newArrayList(StringUtils.splitByWholeSeparator(commandArgs, StringUtils.SPACE)))); jobRequest.getDescription().ifPresent(jobBuilder::withDescription); if (!jobRequest.isDisableLogArchival()) { jobBuilder.withArchiveLocation(this.jobsProperties.getLocations().getArchives() + JobConstants.FILE_PATH_DELIMITER + jobId + ".tar.gz"); } final JobExecution jobExecution = new JobExecution.Builder(this.hostname).withId(jobId).build(); // Log all the job initial job information this.jobPersistenceService.createJob(jobRequest, jobMetadata, jobBuilder.build(), jobExecution); this.jobStateService.init(jobId); log.info("Finding possible clusters and commands for job {}", jobRequest.getId().orElse(NO_ID_FOUND)); final JobSpecification jobSpecification; try { jobSpecification = this.specificationService.resolveJobSpecification(jobId, DtoConverters.toV4JobRequest(jobRequest)); } catch (final RuntimeException re) { //TODO: Here for now as we figure out what to do with exceptions for JobSpecificationServiceImpl throw new GeniePreconditionException(re.getMessage(), re); } final Cluster cluster = this.clusterPersistenceService .getCluster(jobSpecification.getCluster().getId()); final Command command = this.commandPersistenceService .getCommand(jobSpecification.getCommand().getId()); // Now that we have command how much memory should the job use? final int memory = jobRequest.getMemory() .orElse(command.getMemory().orElse(this.jobsProperties.getMemory().getDefaultJobMemory())); final ImmutableList.Builder<Application> applicationsBuilder = ImmutableList.builder(); for (final JobSpecification.ExecutionResource applicationResource : jobSpecification .getApplications()) { applicationsBuilder .add(this.applicationPersistenceService.getApplication(applicationResource.getId())); } final ImmutableList<Application> applications = applicationsBuilder.build(); // Save all the runtime information this.setRuntimeEnvironment(jobId, cluster, command, applications, memory); final int maxJobMemory = this.jobsProperties.getMemory().getMaxJobMemory(); if (memory > maxJobMemory) { jobStatus = JobStatus.INVALID; throw new GeniePreconditionException("Requested " + memory + " MB to run job which is more than the " + maxJobMemory + " MB allowed"); } log.info("Checking if can run job {} from user {}", jobRequest.getId(), jobRequest.getUser()); final JobsUsersActiveLimitProperties activeLimit = this.jobsProperties.getUsers().getActiveLimit(); if (activeLimit.isEnabled()) { final long activeJobsLimit = activeLimit.getCount(); final long activeJobsCount = this.jobSearchService.getActiveJobCountForUser(jobRequest.getUser()); if (activeJobsCount >= activeJobsLimit) { throw GenieUserLimitExceededException.createForActiveJobsLimit(jobRequest.getUser(), activeJobsCount, activeJobsLimit); } } synchronized (this) { log.info("Checking if can run job {} on this node", jobRequest.getId()); final int maxSystemMemory = this.jobsProperties.getMemory().getMaxSystemMemory(); final int usedMemory = this.jobStateService.getUsedMemory(); if (usedMemory + memory <= maxSystemMemory) { log.info("Job {} can run on this node as only {}/{} MB are used and requested {} MB", jobId, usedMemory, maxSystemMemory, memory); // Tell the system a new job has been scheduled so any actions can be taken log.info("Publishing job scheduled event for job {}", jobId); this.jobStateService.schedule(jobId, jobRequest, cluster, command, applications, memory); MetricsUtils.addSuccessTags(tags); return jobId; } else { throw new GenieServerUnavailableException("Job " + jobId + " can't run on this node " + usedMemory + "/" + maxSystemMemory + " MB are used and requested " + memory + " MB"); } } } catch (final GenieConflictException e) { MetricsUtils.addFailureTagsWithException(tags, e); // Job has not been initiated so we don't have to call JobStateService.done() throw e; } catch (final GenieException e) { MetricsUtils.addFailureTagsWithException(tags, e); // // Need to check if the job exists in the JobStateService // because this error can happen before the job is initiated. // if (this.jobStateService.jobExists(jobId)) { this.jobStateService.done(jobId); this.jobPersistenceService.updateJobStatus(jobId, jobStatus, e.getMessage()); } throw e; } catch (final Exception e) { MetricsUtils.addFailureTagsWithException(tags, e); // // Need to check if the job exists in the JobStateService // because this error can happen before the job is initiated. // if (this.jobStateService.jobExists(jobId)) { this.jobStateService.done(jobId); this.jobPersistenceService.updateJobStatus(jobId, jobStatus, e.getMessage()); } throw new GenieServerException("Failed to coordinate job launch", e); } catch (final Throwable t) { MetricsUtils.addFailureTagsWithException(tags, t); throw t; } finally { this.registry.timer(OVERALL_COORDINATION_TIMER_NAME, tags).record(System.nanoTime() - coordinationStart, TimeUnit.NANOSECONDS); } }
From source file:edu.umich.flowfence.common.QMDescriptor.java
public static QMDescriptor parse(String descriptorString) { Matcher matcher = NAME_PATTERN.matcher(Objects.requireNonNull(descriptorString, "descriptorString")); Validate.isTrue(matcher.matches(), "Can't parse QMDescriptor '%s'", descriptorString); ComponentName component = ComponentName.unflattenFromString(matcher.group(1)); String indicator = matcher.group(2); int kind = (indicator == null) ? KIND_CTOR : indicator.equals("#") ? KIND_INSTANCE : KIND_STATIC; String methodName = matcher.group(3); String[] typeNameArray = StringUtils.splitByWholeSeparator(matcher.group(4), ", "); List<String> typeNames = Arrays.asList(ArrayUtils.nullToEmpty(typeNameArray)); return new QMDescriptor(kind, component, methodName, typeNames, false); }
From source file:edu.umich.oasis.common.SodaDescriptor.java
public static SodaDescriptor parse(String descriptorString) { Matcher matcher = NAME_PATTERN.matcher(Objects.requireNonNull(descriptorString, "descriptorString")); Validate.isTrue(matcher.matches(), "Can't parse SodaDescriptor '%s'", descriptorString); ComponentName component = ComponentName.unflattenFromString(matcher.group(1)); String indicator = matcher.group(2); int kind = (indicator == null) ? KIND_CTOR : indicator.equals("#") ? KIND_INSTANCE : KIND_STATIC; String methodName = matcher.group(3); String[] typeNameArray = StringUtils.splitByWholeSeparator(matcher.group(4), ", "); List<String> typeNames = Arrays.asList(ArrayUtils.nullToEmpty(typeNameArray)); return new SodaDescriptor(kind, component, methodName, typeNames, false); }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableRuntimeContext.java
public static SortedSetMultimap<TableContext, TableRuntimeContext> buildPartitionsFromStoredV2Offsets( Map<String, TableContext> tableContextMap, Map<String, String> offsets, Set<TableContext> excludeTables, Map<String, String> newCommitOffsets) throws StageException { SortedSetMultimap<TableContext, TableRuntimeContext> returnMap = buildSortedPartitionMap(); for (Map.Entry<String, String> offsetEntry : offsets.entrySet()) { final String offsetKey = offsetEntry.getKey(); final String offsetValue = offsetEntry.getValue(); LOG.debug("Parsing offset with key {}", offsetKey); final String[] parts = StringUtils.splitByWholeSeparator(offsetKey, OFFSET_TERM_SEPARATOR); if (parts.length < 5 || parts.length > 6) { throw new IllegalStateException(String.format( "Offset was not in correct format. Expected 5 or 6 parts separated by %s to represent" + " %s, %s, %s, %s, %s, and - optionally - %s, respectively. Invalid offset key: %s", OFFSET_TERM_SEPARATOR, TABLE_NAME_KEY, PARTITIONED_KEY, PARTITION_SEQUENCE_KEY, PARTITION_START_OFFSETS_KEY, PARTITION_MAX_OFFSETS_KEY, USING_NON_INCREMENTAL_LOAD_KEY, offsetKey));//from w w w.j a v a2 s . c o m } final String qualifiedTableName = checkAndReturnOffsetTermValue(parts[0], TABLE_NAME_KEY, 1, offsetKey); final String partitionedStr = checkAndReturnOffsetTermValue(parts[1], PARTITIONED_KEY, 2, offsetKey); final boolean partitioned = Boolean.valueOf(partitionedStr); final String partitionSequenceStr = checkAndReturnOffsetTermValue(parts[2], PARTITION_SEQUENCE_KEY, 3, offsetKey); int partSeq; try { partSeq = Integer.parseInt(partitionSequenceStr); } catch (NumberFormatException e) { throw new IllegalStateException(String.format( "Illegal partitionSequence value (3rd term separated by %s) in stored offset key; should be integer: %s", OFFSET_TERM_SEPARATOR, offsetKey), e); } final String partitionStartOffsetsStr = checkAndReturnOffsetTermValue(parts[3], PARTITION_START_OFFSETS_KEY, 4, offsetKey); final Map<String, String> startOffsets = OffsetQueryUtil .getOffsetsFromSourceKeyRepresentation(partitionStartOffsetsStr); final String partitionMaxOffsetsStr = checkAndReturnOffsetTermValue(parts[4], PARTITION_MAX_OFFSETS_KEY, 5, offsetKey); final Map<String, String> maxOffsets = OffsetQueryUtil .getOffsetsFromSourceKeyRepresentation(partitionMaxOffsetsStr); boolean usingNonIncrementalLoad = false; if (parts.length == 6) { // contains the non-incremental load key as well final String usingNonIncrementalLoadStr = checkAndReturnOffsetTermValue(parts[5], USING_NON_INCREMENTAL_LOAD_KEY, 6, offsetKey); usingNonIncrementalLoad = BooleanUtils.toBoolean(usingNonIncrementalLoadStr); } // TODO: change code to read offset properly for non-incremental (finished=true) and NOT re-add if finished if (!tableContextMap.containsKey(qualifiedTableName)) { // TODO: something stronger here? basically we will throw away an offset for a no-longer-configured table LOG.warn(String.format("Ignoring offset for table (partitioned=%b) %s with sequence %d", partitioned, qualifiedTableName, partSeq)); } else { final TableContext tableContext = tableContextMap.get(qualifiedTableName); TableRuntimeContext partition = null; if (usingNonIncrementalLoad) { boolean completed = false; final Map<String, String> offsetMap = OffsetQueryUtil .getOffsetsFromSourceKeyRepresentation(offsetValue); final String checkStateMsg = String.format( "offset value for table using non-incremental load (key \"%s\") should be a map with at most a" + " single key called %s (which has a boolean value), but was: %s", offsetKey, NON_INCREMENTAL_LOAD_OFFSET_COMPLETED_KEY, offsetValue); Utils.checkState(offsetMap.size() <= 1, checkStateMsg); if (!offsetMap.isEmpty()) { Utils.checkState(offsetMap.containsKey(NON_INCREMENTAL_LOAD_OFFSET_COMPLETED_KEY), checkStateMsg); completed = Boolean.valueOf(offsetMap.get(NON_INCREMENTAL_LOAD_OFFSET_COMPLETED_KEY)); } if (completed) { LOG.info( "Table {} was marked completed by a non-incremental load, so it will not be added again unless the" + " origin is reset", qualifiedTableName); excludeTables.add(tableContext); } else { partition = new TableRuntimeContext(tableContext, usingNonIncrementalLoad, partitioned, partSeq, startOffsets, maxOffsets, Collections.emptyMap()); } } else { final Map<String, String> initialStoredOffsets = OffsetQueryUtil .validateStoredAndSpecifiedOffset(tableContext, offsetValue); partition = new TableRuntimeContext(tableContext, usingNonIncrementalLoad, partitioned, partSeq, startOffsets, maxOffsets, initialStoredOffsets); } if (partition != null) { newCommitOffsets.put(partition.getOffsetKey(), offsetValue); returnMap.put(tableContext, partition); } } } return returnMap; }
From source file:com.zhumeng.dream.orm.PropertyFilter.java
private void init(final String filterName, final Object value, String propertyNameStr) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try {/*from w ww . j ava2s . c o m*/ matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } // String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); }
From source file:com.gs.obevo.db.impl.core.reader.TextMarkupDocumentReader.java
Pair<ImmutableMap<String, String>, ImmutableSet<String>> parseAttrsAndToggles(String line) { MutableMap<String, String> attrs = Maps.mutable.empty(); MutableSet<String> toggles = Sets.mutable.empty(); if (!legacyMode) { List<Token> tokens = TextMarkupParser.parseTokens(line); Token curToken = !tokens.isEmpty() ? tokens.get(0) : null; while (curToken != null && curToken.kind != TextMarkupLineSyntaxParserConstants.EOF) { switch (curToken.kind) { case TextMarkupLineSyntaxParserConstants.WHITESPACE: // skip whitespace if encountered break; case TextMarkupLineSyntaxParserConstants.QUOTED_LITERAL: case TextMarkupLineSyntaxParserConstants.STRING_LITERAL: // let's check if this is a toggle or an attribute if (curToken.next.kind == TextMarkupLineSyntaxParserConstants.ASSIGN) { Token keyToken = curToken; curToken = curToken.next; // to ASSIGN curToken = curToken.next; // to the following token switch (curToken.kind) { case TextMarkupLineSyntaxParserConstants.QUOTED_LITERAL: case TextMarkupLineSyntaxParserConstants.STRING_LITERAL: // in this case, we have an attribute value String value = curToken.image; if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') { value = curToken.image.substring(1, curToken.image.length() - 1); }// ww w . jav a 2s . co m value = value.replaceAll("\\\\\"", "\""); attrs.put(keyToken.image, value); break; case TextMarkupLineSyntaxParserConstants.WHITESPACE: case TextMarkupLineSyntaxParserConstants.EOF: // in this case, we will assume a blank value attrs.put(keyToken.image, ""); break; case TextMarkupLineSyntaxParserConstants.ASSIGN: default: throw new IllegalStateException("Not allowed here"); } } else { toggles.add(curToken.image); } break; case TextMarkupLineSyntaxParserConstants.ASSIGN: toggles.add(curToken.image); break; case TextMarkupLineSyntaxParserConstants.EOF: default: throw new IllegalStateException("Should not arise"); } curToken = curToken.next; } } else { // keeping this mode for backwards-compatibility until we can guarantee all clients are fine without it // This way cannot handle spaces in quotes String[] args = StringUtils.splitByWholeSeparator(line, " "); for (String arg : args) { if (arg.contains("=")) { String[] attr = arg.split("="); if (attr.length > 2) { throw new IllegalArgumentException("Cannot mark = multiple times in a parameter - " + line); } String attrVal = attr[1]; if (attrVal.startsWith("\"") && attrVal.endsWith("\"")) { attrVal = attrVal.substring(1, attrVal.length() - 1); } attrs.put(attr[0], attrVal); } else if (StringUtils.isNotBlank(arg)) { toggles.add(arg); } } } return Tuples.pair(attrs.toImmutable(), toggles.toImmutable()); }
From source file:com.norconex.importer.handler.splitter.impl.TranslatorSplitter.java
private ImporterMetadata translateFields(SplittableDocument doc, Translator translator, String sourceLang, String targetLang) throws Exception { ImporterMetadata childMeta = new ImporterMetadata(); if (ignoreNonTranslatedFields) { if (fieldsToTranslate == null) { return childMeta; }//from w ww.j a va 2 s. c om for (String key : fieldsToTranslate) { List<String> values = doc.getMetadata().get(key); if (values != null) { childMeta.put(key, values); } } } else { childMeta.load(doc.getMetadata()); if (fieldsToTranslate == null) { return childMeta; } } StringBuilder b = new StringBuilder(); for (int i = 0; i < fieldsToTranslate.length; i++) { List<String> values = doc.getMetadata().get(fieldsToTranslate[i]); for (String value : values) { b.append("[" + value.replaceAll("[\n\\[\\]]", " ") + "]"); } b.append("\n"); } if (b.length() == 0) { return childMeta; } String txt = translator.translate(b.toString(), sourceLang, targetLang); List<String> lines = IOUtils.readLines(new StringReader(txt)); int index = 0; for (String line : lines) { line = StringUtils.removeStart(line, "["); line = StringUtils.removeEnd(line, "]"); String[] values = StringUtils.splitByWholeSeparator(line, "]["); childMeta.setString(fieldsToTranslate[index], values); index++; } return childMeta; }