List of usage examples for org.springframework.util StringUtils arrayToDelimitedString
public static String arrayToDelimitedString(@Nullable Object[] arr, String delim)
From source file:org.opennms.ng.dao.support.DefaultRrdDao.java
/** * <p>getPrintValues</p>//from ww w.jav a2 s.c o m * * @param attribute a {@link org.opennms.netmgt.model.OnmsAttribute} object. * @param rraConsolidationFunction a {@link String} object. * @param startTimeInMillis a long. * @param endTimeInMillis a long. * @param printFunctions a {@link String} object. * @return an array of double. */ @Override public double[] getPrintValues(OnmsAttribute attribute, String rraConsolidationFunction, long startTimeInMillis, long endTimeInMillis, String... printFunctions) { Assert.notNull(attribute, "attribute argument must not be null"); Assert.notNull(rraConsolidationFunction, "rraConsolicationFunction argument must not be null"); Assert.isTrue(endTimeInMillis > startTimeInMillis, "end argument must be after start argument"); Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class, "attribute argument must be assignable to RrdGraphAttribute"); // if no printFunctions are given just use the rraConsolidationFunction if (printFunctions.length < 1) { printFunctions = new String[] { rraConsolidationFunction }; } RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute; String[] command = new String[] { m_rrdBinaryPath, "graph", "-", "--start=" + (startTimeInMillis / 1000), "--end=" + (endTimeInMillis / 1000), "DEF:ds=" + RrdFileConstants.escapeForGraphing(rrdAttribute.getRrdRelativePath()) + ":" + attribute.getName() + ":" + rraConsolidationFunction, }; String[] printDefs = new String[printFunctions.length]; for (int i = 0; i < printFunctions.length; i++) { printDefs[i] = "PRINT:ds:" + printFunctions[i] + ":\"%le\""; } String commandString = StringUtils.arrayToDelimitedString(command, " ") + ' ' + StringUtils.arrayToDelimitedString(printDefs, " "); LOG.debug("commandString: {}", commandString); RrdGraphDetails graphDetails; try { graphDetails = m_rrdStrategy.createGraphReturnDetails(commandString, m_rrdBaseDirectory); } catch (Throwable e) { throw new DataAccessResourceFailureException( "Failure when generating graph to get data with command '" + commandString + "'", e); } String[] printLines; try { printLines = graphDetails.getPrintLines(); } catch (Throwable e) { throw new DataAccessResourceFailureException( "Failure to get print lines from graph after graphing with command '" + commandString + "'", e); } if (printLines.length != printFunctions.length) { throw new DataAccessResourceFailureException("Returned number of print lines should be " + printFunctions.length + ", but was " + printLines.length + " from command: " + commandString); } double[] values = new double[printLines.length]; for (int i = 0; i < printLines.length; i++) { if (printLines[i].endsWith("nan")) { values[i] = Double.NaN; } else { try { values[i] = Double.parseDouble(printLines[i]); } catch (NumberFormatException e) { throw new DataAccessResourceFailureException("Value of line " + (i + 1) + " of output from RRD is not a valid floating point number: '" + printLines[i] + "'"); } } } return values; }
From source file:com.devnexus.ting.repository.jpa.RegistrationRepositoryImpl.java
@Override public List<RegistrationDetails> findOrdersWithContactName(String[] namesA, EventSignup signUp) { String fullName = StringUtils.arrayToDelimitedString(namesA, " "); List<String> names = Arrays.asList(namesA); List<RegistrationDetails> resultList = entityManager.createQuery( "select details from RegistrationDetails details inner join details.orderDetails orderDetails where details.event.id = :event_id and (details.contactName LIKE :name or orderDetails.firstName in (:first_names) or orderDetails.lastName in (:last_names))", RegistrationDetails.class).setParameter("event_id", signUp.getEvent().getId()) .setParameter("name", "%" + fullName + "%").setParameter("first_names", names) .setParameter("last_names", names).getResultList(); List<RegistrationDetails> detailsFromEmail = new ArrayList<>(); resultList.stream().forEach(objects -> { detailsFromEmail.addAll(Arrays.asList(objects)); });/*from w w w. j av a2s . com*/ return detailsFromEmail; }
From source file:cyrille.xml.xsd.XsomXsdParserSample.java
/** * Dump/*from w w w . j a va 2s .co m*/ * * @param dataSourceElementDecl * @param indentation */ private void dumpDbcpDatasource(XSElementDecl dataSourceElementDecl) { XSType dataSourceElementType = dataSourceElementDecl.getType(); Assert.isTrue(dataSourceElementType.isComplexType()); XSComplexType dataSourceComplexType = dataSourceElementType.asComplexType(); XSContentType dataSourceContentType = dataSourceComplexType.getContentType(); Assert.isTrue(dataSourceContentType instanceof XSParticle); XSParticle dataSourceParticle = dataSourceContentType.asParticle(); XSTerm dataSourceTerm = dataSourceParticle.getTerm(); Assert.isTrue(dataSourceTerm.isModelGroup()); XSModelGroup dataSourceModelGroup = dataSourceTerm.asModelGroup(); for (XSParticle configurationElementParticle : dataSourceModelGroup.getChildren()) { XSTerm configurationElementTerm = configurationElementParticle.getTerm(); Assert.isTrue(configurationElementTerm.isElementDecl()); XSElementDecl configurationElementDecl = configurationElementTerm.asElementDecl(); XSType configurationElementType = configurationElementDecl.getType(); Assert.isTrue(configurationElementType.isComplexType()); XSComplexType configurationElementComplexType = configurationElementType.asComplexType(); XSAttributeUse valueAttributeUse = configurationElementComplexType.getAttributeUse("", "value"); Assert.notNull(valueAttributeUse, "'value' attribute not found for " + configurationElementDecl); XSAttributeDecl valueAttributeDeclaration = valueAttributeUse.getDecl(); String valueType = valueAttributeDeclaration.getType().getName(); boolean required = configurationElementParticle.getMinOccurs() == 1; String defaultValue = valueAttributeUse.getDefaultValue() == null ? "" : valueAttributeUse.getDefaultValue().toString(); String documentation = getDocumentation(configurationElementDecl); documentation = documentation.trim(); String[] splittedDocumentation = org.apache.commons.lang.StringUtils.split(documentation, "\n"); splittedDocumentation = StringUtils.trimArrayElements(splittedDocumentation); documentation = StringUtils.arrayToDelimitedString(splittedDocumentation, "<br/>"); System.out.println("|| *{{{" + configurationElementDecl.getName() + "}}}* || " + valueType + " || " + required + " || " + defaultValue + " || " + documentation + " ||"); } }
From source file:com.test.RestApplicationTests.java
private String sse(String... values) { return "data:" + StringUtils.arrayToDelimitedString(values, "\n\ndata:") + "\n\n"; }
From source file:io.cloudslang.dependency.impl.services.DependencyServiceImpl.java
private void invokeMavenLauncher(String[] args) throws Exception { ClassLoader origCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(mavenClassLoader); try {/*from w w w . jav a2s . c o m*/ int exitCode = (Integer) MAVEN_EXECUTE_METHOD.invoke(null, new Object[] { args }); if (exitCode != 0) { throw new RuntimeException("mvn " + StringUtils.arrayToDelimitedString(args, " ") + " returned " + exitCode + ", see log for details"); } } finally { Thread.currentThread().setContextClassLoader(origCL); } }
From source file:com.bigtobster.pgnextractalt.chess.ChessEvaluatorTest.java
/** * Tests that the output on the name tag is as expected * * @throws chesspresso.move.IllegalMoveException Thrown on an illegal move being found in one of the test games * @throws java.io.IOException Thrown on difficulties communicating with engine * @throws java.net.URISyntaxException Thrown on difficulties finding engine * @throws javax.naming.OperationNotSupportedException Thrown on testing on unsupported OS *//*from w ww . java 2 s.c o m*/ @SuppressWarnings({ "InstanceMethodNamingConvention", "MethodWithTooExceptionsDeclared" }) @Test public void evaluateMachineCorrelationOutputTest() throws URISyntaxException, IllegalMoveException, OperationNotSupportedException, IOException { final TestChessContext testChessContext = new TestChessContext(); testChessContext.loadPGN(TestContext.SINGLE_PGN); final Game unmodifiedSingleGame = testChessContext.getChessIO().getGames().get(0); testChessContext.getChessIO().reset(); testChessContext.loadPGN(TestContext.SINGLE_PGN); final ArrayList<Game> games = testChessContext.getChessIO().getGames(); ChessEvaluator.evaluateMachineCorrelation(games, 13, 10, false); final Game modifiedSingleGame = testChessContext.getChessIO().getGames().get(0); final String unmodifiedWhite = unmodifiedSingleGame.getWhite(); final String unmodifiedBlack = unmodifiedSingleGame.getBlack(); String modifiedWhite = modifiedSingleGame.getWhite(); String modifiedBlack = modifiedSingleGame.getBlack(); final String[] modifiedWhiteArr = ChessEvaluatorTest.SPACE_SPLITTER.split(modifiedWhite); final String[] modifiedBlackArr = ChessEvaluatorTest.SPACE_SPLITTER.split(modifiedBlack); final int wantedWhiteChars = modifiedWhite.length() - modifiedWhiteArr[modifiedWhiteArr.length - 1].length(); final int wantedBlackChars = modifiedBlack.length() - modifiedBlackArr[modifiedBlackArr.length - 1].length(); modifiedWhite = StringUtils.arrayToDelimitedString(modifiedWhiteArr, " ").substring(0, wantedWhiteChars) .trim(); modifiedBlack = StringUtils.arrayToDelimitedString(modifiedBlackArr, " ").substring(0, wantedBlackChars) .trim(); modifiedWhite = modifiedWhite.replace(ChessPresso.MC_TAG_PREFIX, "").trim(); modifiedBlack = modifiedBlack.replace(ChessPresso.MC_TAG_PREFIX, "").trim(); modifiedWhite = modifiedWhite.substring(0, modifiedWhite.length() - 1).trim(); modifiedBlack = modifiedBlack.substring(0, modifiedBlack.length() - 1).trim(); Assert.assertEquals(ChessEvaluatorTest.UNEXPECTED_MOD_TO_PLAYER_NAME, unmodifiedWhite, modifiedWhite); Assert.assertEquals(ChessEvaluatorTest.UNEXPECTED_MOD_TO_PLAYER_NAME, unmodifiedBlack, modifiedBlack); }
From source file:org.obiba.mica.search.csvexport.SpecificStudyReportGenerator.java
private String arrayField(final Callable<List<String>> field) { return field(() -> { List<String> fields = field.call(); return StringUtils.arrayToDelimitedString(fields.toArray(new String[fields.size()]), ", "); });// w ww . j a v a 2 s.com }
From source file:io.cloudslang.dependency.impl.services.DependencyServiceImpl.java
private String getResourceString(String[] gav, boolean transitive) { //if not transitive, use type "pom" String[] newGav = new String[Math.max(4, gav.length)]; System.arraycopy(gav, 0, newGav, 0, gav.length); if (!transitive) { newGav[3] = "pom"; } else {/* w w w .j av a 2s . co m*/ if (newGav[3] == null) { newGav[3] = "jar"; } } return StringUtils.arrayToDelimitedString(newGav, GAV_DELIMITER); }
From source file:ch.rasc.wampspring.security.WampMessageSecurityMetadataSourceRegistry.java
private static String hasAnyRole(String... authorities) { String anyAuthorities = StringUtils.arrayToDelimitedString(authorities, "','ROLE_"); return "hasAnyRole('ROLE_" + anyAuthorities + "')"; }
From source file:net.solarnetwork.node.dao.jdbc.AbstractJdbcDao.java
/** * Load a classpath SQL resource into a String. * /*www. j a v a2s. c o m*/ * <p> * The classpath resource is taken as the {@link #getSqlResourcePrefix()} * value and {@code -} and the {@code classPathResource} combined with a * {@code .sql} suffix. If that resoruce is not found, then the prefix is * split into components separated by a {@code -} character, and the last * component is dropped and then combined with {@code -} and * {@code classPathResource} again to try to find a match, until there is no * prefix left and just the {@code classPathResource} itself is tried. * </p> * * <p> * This method will cache the SQL resource in-memory for quick future * access. * </p> * * @param string * the classpath resource to load as a SQL string * @return the String */ protected String getSqlResource(String classPathResource) { Class<?> myClass = getClass(); String resourceName = getSqlResourcePrefix() + "-" + classPathResource + ".sql"; String key = myClass.getName() + ";" + classPathResource; if (sqlResourceCache.containsKey(key)) { return sqlResourceCache.get(key); } String[] prefixes = getSqlResourcePrefix().split("-"); int prefixEndIndex = prefixes.length - 1; try { Resource r = new ClassPathResource(resourceName, myClass); while (!r.exists() && prefixEndIndex >= 0) { // try by chopping down prefix, which we split on a dash character String subName; if (prefixEndIndex > 0) { String[] subPrefixes = new String[prefixEndIndex]; System.arraycopy(prefixes, prefixEndIndex, subPrefixes, 0, prefixEndIndex); subName = StringUtils.arrayToDelimitedString(subPrefixes, "-") + "-" + classPathResource; } else { subName = classPathResource; } subName += ".sql"; r = new ClassPathResource(subName, myClass); prefixEndIndex--; } if (!r.exists()) { throw new RuntimeException("SQL resource " + resourceName + " not found"); } String result = FileCopyUtils.copyToString(new InputStreamReader(r.getInputStream())); if (result != null && result.length() > 0) { sqlResourceCache.put(key, result); } return result; } catch (IOException e) { throw new RuntimeException(e); } }