List of usage examples for org.apache.commons.lang3 StringUtils join
public static String join(final Iterable<?> iterable, final String separator)
Joins the elements of the provided Iterable into a single String containing the provided elements.
No delimiter is added before or after the list.
From source file:com.izforge.izpack.installer.requirement.JavaVersionCheckerTest.java
/** * Tests the {@link JavaVersionChecker}. *///www .ja v a2s . c om @Test public void testJavaVersion() { JavaVersionChecker checker = new JavaVersionChecker(installData, prompt); installData.getInfo().setJavaVersion(null); assertTrue(checker.check()); String currentVersion = System.getProperty("java.version"); installData.getInfo().setJavaVersion("9" + currentVersion); assertFalse(checker.check()); installData.getInfo().setJavaVersion(currentVersion); assertTrue(checker.check()); // in case of OpenJDK, version number is e.g 1.8.0_102-redhat // therefore the version must increased to // 1.8.0_1029 instead of 1.8.0_102-redhat9 String[] parts = currentVersion.split("-|_|\\."); int pos = 0; // find the last part of version with numeric parts for (int i = 0; i < parts.length; i++) { if (isNumeric(parts[i])) { pos = i; } else { break; } } // and add the "9" on it parts[pos] = parts[pos].concat("9"); installData.getInfo().setJavaVersion(StringUtils.join(parts, ".")); assertFalse(checker.check()); String[] splitCurrentVersion = currentVersion.split("_"); installData.getInfo().setJavaVersion(splitCurrentVersion[0]); assertTrue(checker.check()); }
From source file:com.nesscomputing.migratory.migration.sql.SqlScriptSmallTest.java
@Test public void stripSqlCommentsMultiLineCommentSingleLine() { lines.add("/*comment line*/"); sqlScript = new SqlScript(StringUtils.join(lines, "\n")); final Collection<SqlStatement> statements = sqlScript.getSqlStatements(); Assert.assertNotNull(statements);//w ww . j a v a2 s .co m Assert.assertEquals(0, statements.size()); }
From source file:net.sf.appstatus.core.check.impl.ServicesFailureCheck.java
@Override public ICheckResult checkStatus() { List<IService> services = appStatus.getServiceManager().getServices(); List<String> warns = new ArrayList<String>(); List<String> errors = new ArrayList<String>(); for (IService s : services) { if (s.getHits() == 0) { continue; }/*from ww w. j a va 2s. c o m*/ long failureRatio = (s.getFailures() * 100) / s.getHits(); if (failureRatio > limitError) { errors.add("Service <b>" + s.getGroup() + "#" + s.getName() + "</b> failure ratio (" + failureRatio + "%) is over error limit (" + limitError + "%)"); } else if (failureRatio > limitWarn) { warns.add("Service <b>" + s.getGroup() + "#" + s.getName() + "</b> failure ratio (" + failureRatio + "%) is over warn limit (" + limitWarn + "%)"); } } ICheckResult result = null; if (errors.size() > 0) { String description = StringUtils.join(errors, "<br/>"); if (warns.size() > 0) { description = description + " <br/>Additional warnings: " + StringUtils.join(warns, "<br/>"); } result = result(this).code(ICheckResult.ERROR).fatal().description(description).build(); } else if (warns.size() > 0) { result = result(this).code(ICheckResult.ERROR).description(StringUtils.join(warns, "<br/>")).build(); } else { result = result(this).code(ICheckResult.OK).description("All failure ratios under " + limitWarn + "%") .build(); } return result; }
From source file:net.cloudkit.enterprises.infrastructure.utilities.Collections3Utility.java
/** * ????(Getter), ??./*from w w w. j a va2 s.co m*/ * * @param collection ???. * @param propertyName ??????. * @param separator . */ public static String extractToString(final Collection<?> collection, final String propertyName, final String separator) { List<?> list = extractToList(collection, propertyName); return StringUtils.join(list, separator); }
From source file:dev.maisentito.suca.commands.AdminCommandHandler.java
@Override public void handleCommand(MessageEvent event, String[] args) throws Throwable { if ((!Main.config.verifyOwner || event.getUser().isVerified()) && event.getUser().getNick().equals(getStringGlobal(Main.GLOBAL_OWNER, ""))) { if (args.length < 2) { if (args.length == 1) { if (getGlobals().has(args[0], Object.class)) { event.respond(/*from w ww .jav a2 s. c om*/ String.format("!admin: %s = %s", args[0], getGlobals().get(args[0]).toString())); } else { event.respond(String.format("!admin: %s = null", args[0])); } return; } else { event.respond("!admin: not enough arguments"); return; } } else if (args[1].length() < 3) { event.respond("!admin: invalid value"); return; } String key = args[0]; String full = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), ' '); Object value; switch (args[1].charAt(0)) { case 'c': value = args[1].charAt(2); break; case 'b': value = Byte.parseByte(args[1].substring(2)); break; case 's': value = Short.parseShort(args[1].substring(2)); break; case 'i': value = Integer.parseInt(args[1].substring(2)); break; case 'l': value = Long.parseLong(args[1].substring(2)); break; case 'f': value = Float.parseFloat(args[1].substring(2)); break; case 'd': value = Double.parseDouble(args[1].substring(2)); break; case 'z': value = Boolean.parseBoolean(args[1].substring(2)); break; case 'a': value = full.substring(2); break; default: event.respond("!admin: invalid type"); return; } getGlobals().put(key, value); event.respond("success"); } else { event.respond("nope"); } }
From source file:com.evolveum.midpoint.model.impl.ExtensionSchemaRestService.java
@GET @Produces(MediaType.TEXT_PLAIN)/*from w ww . j ava 2 s. c o m*/ public Response listSchemas() { SchemaRegistry registry = prismContext.getSchemaRegistry(); Collection<SchemaDescription> descriptions = registry.getSchemaDescriptions(); List<String> names = new ArrayList<>(); for (SchemaDescription description : descriptions) { String name = computeName(MIDPOINT_HOME, description); if (name == null) { continue; } names.add(name); } String result = StringUtils.join(names, "\n"); return Response.ok(result).build(); }
From source file:com.microsoft.azure.shortcuts.resources.samples.PublicIpAddressesSample.java
public static void test(Subscription subscription) throws Exception { String newPublicIpAddressName = "pip" + String.valueOf(System.currentTimeMillis()); // Listing all public IP addresses Map<String, PublicIpAddress> pips = subscription.publicIpAddresses().asMap(); System.out.println("Public IP addresses:"); for (PublicIpAddress pip : pips.values()) { printPIP(pip);//from w ww . java 2 s .co m } // Create a public IP address in a default new group PublicIpAddress pipMinimal = subscription.publicIpAddresses().define(newPublicIpAddressName) .withRegion(Region.US_WEST).withNewResourceGroup().create(); // Get info about a specific PIP using its group and name pipMinimal = subscription.publicIpAddresses(pipMinimal.id()); pipMinimal = subscription.publicIpAddresses().get(pipMinimal.id()); String groupNameCreated = pipMinimal.resourceGroup(); printPIP(pipMinimal); // More detailed PIP definition PublicIpAddress pip = subscription.publicIpAddresses().define(newPublicIpAddressName + "2") .withRegion(Region.US_WEST).withExistingResourceGroup(pipMinimal.resourceGroup()) .withLeafDomainLabel("hellomarcins").withStaticIp().withTag("hello", "world").create(); // Listing PIPs in a specific resource group pips = subscription.publicIpAddresses().asMap(pipMinimal.resourceGroup()); System.out.println(String.format("PIP ids in group '%s': \n\t%s", pipMinimal.resourceGroup(), StringUtils.join(pips.keySet(), ",\n\t"))); // Get info about a specific PIP using its resource ID pip = subscription.publicIpAddresses(pip.resourceGroup(), pip.name()); printPIP(pip); // Delete the PIP pipMinimal.delete(); pip.delete(); // Delete the auto-created group subscription.resourceGroups(groupNameCreated).delete(); }
From source file:com.thoughtworks.go.config.BuildTask.java
@Override public String describe() { List<String> description = new ArrayList<>(); description.add(command());/*from w w w .j a v a 2 s . c o m*/ if (!"".equals(arguments())) { description.add(arguments()); } if (null != workingDirectory()) { description.add(String.format("(workingDirectory: %s)", workingDirectory())); } return StringUtils.join(description, " "); }
From source file:co.foxdev.foxbot.commands.CommandSay.java
@Override public void execute(final MessageEvent event, final String[] args) { User sender = event.getUser();/* w w w .ja va 2 s .com*/ Channel channel = event.getChannel(); if (args.length > 0) { if (args[0].startsWith("#") && args.length > 1) { String targetChan = args[0]; channel = foxbot.bot().getUserChannelDao().getChannel(targetChan); if (!foxbot.bot().getUserBot().getChannels().contains(channel)) { sender.send().notice("I'm not in " + channel.getName()); return; } StringBuilder message = new StringBuilder(args[1]); for (int arg = 2; arg < args.length; arg++) { message.append(" ").append(args[arg]); } channel.send().message(message.toString()); sender.send().notice(String.format("Message sent to %s", targetChan)); return; } channel.send().message(StringUtils.join(args, " ")); return; } sender.send().notice(String.format("Wrong number of args! Use %ssay [#channel] <message>", foxbot.getConfig().getCommandPrefix())); }
From source file:annis.sqlgen.extensions.AnnotateQueryData.java
@Override public String toString() { List<String> fields = new ArrayList<>(); if (left > 0) { fields.add("left = " + left); }/*ww w.ja va 2 s . c o m*/ if (right > 0) { fields.add("right = " + right); } if (segmentationLayer != null) { fields.add("segLayer = " + segmentationLayer); } if (filter != null) { fields.add("filter = " + filter.name()); } return StringUtils.join(fields, ", "); }