use of org.apache.commons.lang3.StringUtils.split in project RFToolsDimensions by McJty.
the class DimensionDescriptor method getDimletsWithModifiers.
public List<Pair<DimletKey, List<DimletKey>>> getDimletsWithModifiers() {
List<Pair<DimletKey, List<DimletKey>>> result = new ArrayList<>();
String ds = descriptionString;
if (ds.startsWith("@")) {
ds = ds.substring(1);
}
if (!ds.isEmpty()) {
List<DimletKey> modifiers = new ArrayList<>();
String[] opcodes = StringUtils.split(ds, ",");
for (String oc : opcodes) {
DimletKey key;
if (oc.startsWith("#")) {
// First comes '#', then the type of the actual dimlet.
key = DimletKey.parseKey(oc.substring(1));
modifiers.add(key);
} else if (oc.startsWith("?")) {
} else {
key = DimletKey.parseKey(oc);
result.add(Pair.of(key, modifiers));
modifiers = new ArrayList<>();
}
}
}
return result;
}
use of org.apache.commons.lang3.StringUtils.split in project blue by kunstmusik.
the class CSDRender method createAllNotesOffInstrument.
protected Instrument createAllNotesOffInstrument(String[] instrIds) {
GenericInstrument instr = new GenericInstrument();
StrBuilder buffer = new StrBuilder();
buffer.append("koff init 0\n" + "if (koff == 0) then\n");
for (int i = 0; i < instrIds.length; i++) {
String id = instrIds[i];
String[] parts = StringUtils.split(id, ",");
for (int j = 0; j < parts.length; j++) {
String tempId = parts[j];
try {
int instrIdNum = Integer.parseInt(tempId.trim());
buffer.append("turnoff2 ").append(instrIdNum);
buffer.append(", 0, 1\n");
} catch (NumberFormatException nfe) {
buffer.append("insno").append(i).append(j);
buffer.append(" nstrnum \"").append(tempId).append("\"\n");
buffer.append("turnoff2 insno").append(i).append(j);
buffer.append(", 0, 1\n");
}
}
}
buffer.append("koff = 1\nelse\nturnoff\nendif\n");
instr.setText(buffer.toString());
return instr;
}
use of org.apache.commons.lang3.StringUtils.split in project nuxeo-drive-server by nuxeo.
the class RootDefinitionsHelper method parseRootDefinitions.
/**
* Parses the given synchronization root definitions string.
*/
public static Map<String, Set<IdRef>> parseRootDefinitions(String rootDefinitions) {
Map<String, Set<IdRef>> lastActiveRootRefs = new LinkedHashMap<>();
if (rootDefinitions != null) {
String[] rootDefinitionComponents = StringUtils.split(rootDefinitions, ",");
for (String rootDefinition : rootDefinitionComponents) {
String[] rootComponents = StringUtils.split(rootDefinition, ":");
String repoName = rootComponents[0].trim();
lastActiveRootRefs.computeIfAbsent(repoName, k -> new HashSet<>()).add(new IdRef(rootComponents[1].trim()));
}
}
return lastActiveRootRefs;
}
use of org.apache.commons.lang3.StringUtils.split in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResource method installInstancesTerm.
private void installInstancesTerm(final UpdateContext context, final ProvInstancePriceTerm term, final ProvInstancePriceTerm termLow, Entry<String, AzureVmPrice> azPrice) {
final String[] parts = StringUtils.split(azPrice.getKey(), '-');
final VmOs os = VmOs.valueOf(parts[0].replace("redhat", "RHEL").replace("sles", "SUSE").toUpperCase());
// Basic, Low Priority, Standard
final String tier = parts[2];
final boolean isBasic = "basic".equals(tier);
final AzureVmPrice azType = azPrice.getValue();
// Get the right term : "lowpriority" within "PayGo" or the current term
final ProvInstancePriceTerm termU = tier.equals("lowpriority") ? termLow : term;
final String globalCode = termU.getName() + "-" + azPrice.getKey();
final ProvInstanceType type = installInstancePriceType(context, parts, isBasic, azType);
// Iterate over regions enabling this instance type
azType.getPrices().entrySet().stream().filter(pl -> isEnabledRegion(pl.getKey())).forEach(pl -> {
final ProvInstancePrice price = installInstancePrice(context, termU, os, globalCode, type, pl.getKey());
// Update the cost
price.setCost(round3Decimals(pl.getValue().getValue() * 24 * 30.5));
price.setCostPeriod(pl.getValue().getValue());
ipRepository.save(price);
});
}
use of org.apache.commons.lang3.StringUtils.split in project sponge by softelnet.
the class StandaloneEngineBuilder method build.
/**
* Returns a new StandaloneEngine or {@code null} if help or version option is specified so the application should exit.
*/
@Override
public StandaloneSpongeEngine build() {
try {
if (commandLineArgs == null) {
return super.build();
}
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, commandLineArgs);
if (commandLine.hasOption(OPTION_HELP)) {
printHelp();
return null;
}
if (commandLine.hasOption(OPTION_VERSION)) {
System.out.println(getDescription());
return null;
}
if (commandLine.hasOption(OPTION_CONFIG)) {
config(commandLine.getOptionValue(OPTION_CONFIG));
}
if (Stream.of(commandLine.getOptions()).filter(option -> option.getOpt().equals(OPTION_CONFIG)).count() > 1) {
throw new StandaloneInitializationException("Only one Sponge XML configuration file may be provided.");
}
Stream.of(commandLine.getOptions()).filter(option -> option.getOpt().equals(OPTION_KNOWLEDGE_BASE)).forEachOrdered(option -> {
String value = option.getValue();
if (value == null || StringUtils.isBlank(value)) {
throw new StandaloneInitializationException("Empty knowledge base specification.");
}
String[] values = StringUtils.split(value, ARGUMENT_VALUE_SEPARATOR);
String kbName = values.length == 2 ? values[0] : DEFAULT_KNOWLEDGE_BASE_NAME;
String kbFilesString = values.length == 2 ? values[1] : values[0];
if (StringUtils.isBlank(kbName)) {
throw new StandaloneInitializationException("Empty knowledge base name.");
}
List<String> kbFiles = SpongeUtils.split(kbFilesString, KB_FILES_SEPARATOR);
knowledgeBase(kbName, kbFiles.toArray(new String[kbFiles.size()]));
});
if (!commandLine.hasOption(OPTION_CONFIG) && !commandLine.hasOption(OPTION_KNOWLEDGE_BASE)) {
throw new StandaloneInitializationException("An Sponge XML configuration file or a knowledge base file(s) should be provided.");
}
// Apply standard parameters.
super.build();
applyDefaultParameters();
if (commandLine.hasOption(OPTION_INTERACTIVE)) {
InteractiveMode interactiveMode = new DefaultInteractiveMode(engine, commandLine.getOptionValue(OPTION_INTERACTIVE), interactiveModeConsoleSupplier);
ExceptionHandler interactiveExceptionHandler = new SystemErrExceptionHandler();
interactiveMode.setExceptionHandler(interactiveExceptionHandler);
engine.setInteractiveMode(interactiveMode);
if (commandLine.hasOption(OPTION_PRINT_ALL_EXCEPTIONS)) {
engine.setExceptionHandler(new CombinedExceptionHandler(interactiveExceptionHandler, new LoggingExceptionHandler()));
} else {
LoggingUtils.logToConsole(false);
}
} else {
if (commandLine.hasOption(OPTION_PRINT_ALL_EXCEPTIONS)) {
throw new StandaloneInitializationException("'" + OPTION_PRINT_ALL_EXCEPTIONS + "' option may be used only if '" + OPTION_INTERACTIVE + "' is also used.");
}
}
StandaloneEngineListener standaloneListener = new StandaloneEngineListener(engine);
List<String> springConfigurationFiles = Stream.of(commandLine.getOptions()).filter(option -> option.getOpt().equals(OPTION_SPRING)).map(option -> {
String[] values = option.getValues();
if (values == null || values.length == 0) {
throw new StandaloneInitializationException("No Spring configuration file provided.");
}
return option.getValue(0);
}).collect(Collectors.toList());
if (!springConfigurationFiles.isEmpty()) {
standaloneListener.setSpringConfigurations(springConfigurationFiles);
}
if (commandLine.hasOption(OPTION_CAMEL)) {
standaloneListener.setCamel(true);
}
engine.addOnStartupListener(standaloneListener);
engine.addOnShutdownListener(standaloneListener);
} catch (ParseException e) {
throw new StandaloneInitializationException(e.getMessage(), e);
}
return engine;
}
Aggregations