List of usage examples for org.apache.commons.lang ArrayUtils toString
public static String toString(Object array)
Outputs an array as a String, treating null
as an empty array.
From source file:com.exoplatform.social.activity.storage.cache.CachedActivityStorage.java
private String[] add(String[] mentionerIds, String mentionStr, List<String> addedOrRemovedIds) { if (ArrayUtils.toString(mentionerIds).indexOf(mentionStr) == -1) { // the first mention addedOrRemovedIds.add(mentionStr.replace(MENTION_CHAR, "")); return (String[]) ArrayUtils.add(mentionerIds, mentionStr + 1); }/* www.j av a2 s . c o m*/ String storedId = null; for (String mentionerId : mentionerIds) { if (mentionerId.indexOf(mentionStr) != -1) { mentionerIds = (String[]) ArrayUtils.removeElement(mentionerIds, mentionerId); storedId = mentionStr + (Integer.parseInt(mentionerId.split(MENTION_CHAR)[1]) + 1); break; } } addedOrRemovedIds.add(mentionStr.replace(MENTION_CHAR, "")); mentionerIds = (String[]) ArrayUtils.add(mentionerIds, storedId); return mentionerIds; }
From source file:net.sf.reportengine.util.TestCoefficients.java
/** * Test method for {@link net.sf.reportengine.util.CrossTabCoefficients#Coefficients(java.lang.String[][], boolean)}. *//*w w w. j a v a2 s . c o m*/ public void testCoefficientsWithTotals2() { String[][] distinctValues = new String[][] { new String[] { "North", "South", "East", "West" }, new String[] { "M", "F" }, new String[] { "20", "50", "80" } }; classUnderTest = new CrossTabCoefficients(distinctValues, true); assertNotNull(classUnderTest); //test colcount and rowcount assertEquals(classUnderTest.getTemplateColumnCount(), 37); assertEquals(classUnderTest.getTemplateRowCount(), 3); //test number of distinct values per row int[] result = classUnderTest.getDistValuesCntInHeaderRow(); assertNotNull(result); System.out.println("Distinct Values : " + ArrayUtils.toString(result)); assertTrue(ArrayUtils.isEquals(result, new int[] { 4, 2, 3 })); //test number of spaces result = classUnderTest.getSpacesCntInHeaderRow(); assertNotNull(result); System.out.println("Spaces Cnt (if totals were displayed): " + ArrayUtils.toString(result)); assertTrue(ArrayUtils.isEquals(result, new int[] { 0, 1, 5 })); //test number of totals result = classUnderTest.getTotalsCntInHeaderRow(); assertNotNull(result); System.out.println("Totals Cnt : " + ArrayUtils.toString(result)); assertTrue(ArrayUtils.isEquals(result, new int[] { 1, 4, 8 })); //test number of totals result = classUnderTest.getColspanPerRow(); assertNotNull(result); System.out.println("Distance between distinct header values : " + ArrayUtils.toString(result)); assertTrue(ArrayUtils.isEquals(result, new int[] { 9, 4, 1 })); }
From source file:com.jfaker.framework.config.model.Form.java
public void submit(Form model, List<Field> fields, Map<String, String[]> paraMap, String orderId, String taskId) {/*from w w w.j a v a 2 s. co m*/ String tableName = getTableName(model); StringBuilder beforeSql = new StringBuilder(); StringBuilder afterSql = new StringBuilder(); beforeSql.append("INSERT INTO ").append(tableName); beforeSql.append(" (FORMID, UPDATETIME, ORDERID, TASKID "); afterSql.append(") values (?,?,?,?"); List<Object> datas = new ArrayList<Object>(); datas.add(model.getInt("id")); datas.add(DateUtils.getCurrentTime()); datas.add(orderId); datas.add(taskId); if (fields != null) { StringBuilder fieldSql = new StringBuilder(); StringBuilder valueSql = new StringBuilder(); for (Field field : fields) { String[] data = paraMap.get(field.get("name")); if (data == null) { continue; } fieldSql.append(",").append(field.get("name")); valueSql.append(",?"); if (data.length == 1) { datas.add(data[0]); } else { String dataArr = ArrayUtils.toString(data); if (dataArr.length() > 1) { datas.add(dataArr.substring(1, dataArr.length() - 1)); } } } if (fieldSql.length() > 0) { beforeSql.append(fieldSql.toString()); afterSql.append(valueSql.toString()); } } afterSql.append(")"); beforeSql.append(afterSql.toString()); String sql = beforeSql.toString(); log.info("dynamic sql is:" + sql); log.info(datas.toString()); Db.update(sql, datas.toArray()); }
From source file:it.govpay.web.handler.MessageLoggingHandlerUtils.java
public static boolean logToSystemOut(UriInfo uriInfo, HttpHeaders rsHttpHeaders, HttpServletRequest request, byte[] bytes, String nomeOperazione, String nomeServizio, String tipoServizio, int versioneServizio, Logger log, boolean outbound, Integer responseCode) { GpContext ctx = null;/*from w w w .j a v a2 s . com*/ Message msg = new Message(); try { msg.setContent(bytes); } catch (Exception e) { log.error("Exception in handler: " + e); } Map<String, List<String>> httpHeaders = null; if (outbound) { ctx = GpThreadLocal.get(); //httpHeaders = (Map<String, List<String>>) smc.get(MessageContext.HTTP_RESPONSE_HEADERS); msg.setType(MessageType.RESPONSE_OUT); if (rsHttpHeaders.getMediaType() != null) msg.setContentType( rsHttpHeaders.getMediaType().getType() + "/" + rsHttpHeaders.getMediaType().getSubtype()); ctx.getContext().getResponse().setOutDate(new Date()); ctx.getContext().getResponse().setOutSize(Long.valueOf(bytes.length)); if (responseCode != null) ctx.getTransaction().getServer().setTransportCode(responseCode.intValue() + ""); } else { try { ctx = new GpContext(uriInfo, rsHttpHeaders, request, nomeOperazione, nomeServizio, tipoServizio, versioneServizio); ThreadContext.put("op", ctx.getTransactionId()); GpThreadLocal.set(ctx); } catch (Exception e) { log.error(e.getMessage(), e); return false; } httpHeaders = rsHttpHeaders.getRequestHeaders(); msg.setType(MessageType.REQUEST_IN); if (rsHttpHeaders.getMediaType() != null) msg.setContentType( rsHttpHeaders.getMediaType().getType() + "/" + rsHttpHeaders.getMediaType().getSubtype()); ctx.getContext().getRequest().setInDate(new Date()); ctx.getContext().getRequest().setInSize(Long.valueOf(bytes.length)); } if (httpHeaders != null) { for (String key : httpHeaders.keySet()) { if (httpHeaders.get(key) != null) { if (key == null) msg.addHeader(new Property("Status-line", httpHeaders.get(key).get(0))); else if (httpHeaders.get(key).size() == 1) msg.addHeader(new Property(key, httpHeaders.get(key).get(0))); else msg.addHeader(new Property(key, ArrayUtils.toString(httpHeaders.get(key)))); } } } ctx.log(msg); return true; }
From source file:info.magnolia.cms.beans.config.PropertiesInitializer.java
public void loadPropertiesFiles(String propertiesLocationString, String rootPath) { String[] propertiesLocation = StringUtils.split(propertiesLocationString, ','); boolean found = false; // attempt to load each properties file at the given locations in reverse order: first files in the list // override the later ones for (int j = propertiesLocation.length - 1; j >= 0; j--) { String location = StringUtils.trim(propertiesLocation[j]); if (loadPropertiesFile(rootPath, location)) { found = true;//from w w w. j ava 2s . co m } } if (!found) { final String msg = MessageFormat.format( "No configuration found using location list {0}. Base path is [{1}]", //$NON-NLS-1$ ArrayUtils.toString(propertiesLocation), rootPath); log.error(msg); throw new ConfigurationException(msg); } }
From source file:com.tesora.dve.common.PEBaseTest.java
/** * Assert that two objects are equal. If the objects are arrays compare * them element-wise, using equals(), handling multi-dimensional arrays * correctly.// w ww. j a va 2s. co m */ protected static void assertEqualData(final Object expected, final Object actual) { if ((expected != null) && expected.getClass().isArray()) { assertTrue("expected: <" + ArrayUtils.toString(expected) + "> but was: <" + ArrayUtils.toString(actual) + ">", ArrayUtils.isEquals(expected, actual)); } else { assertEquals(expected, actual); } }
From source file:com.aol.advertising.qiao.util.CommonUtils.java
public static String objectToString(Object o) { if (o.getClass().isArray()) return ArrayUtils.toString(o); else//from w ww . ja v a 2 s .co m return o.toString(); }
From source file:net.sourceforge.atunes.kernel.modules.player.PlayerHandler.java
/** * Gets the single instance of PlayerHandler. This method returns player * engine configured by user or default if it's available on the system * //from www . j a v a 2s . com * @return single instance of PlayerHandler */ public static final synchronized PlayerHandler getInstance() { if (instance == null) { instance = new PlayerHandler(); // Get engines list List<PlayerEngine> engines = getEngines(); // Remove unsupported engines Iterator<PlayerEngine> it = engines.iterator(); while (it.hasNext()) { if (!it.next().isEngineAvailable()) { it.remove(); } } // Update engine names engineNames = new String[engines.size()]; for (int i = 0; i < engines.size(); i++) { engineNames[i] = engines.get(i).getEngineName(); } Arrays.sort(engineNames); getLogger().info(LogCategories.PLAYER, "List of availables engines : " + ArrayUtils.toString(engineNames)); if (engines.isEmpty()) { handlePlayerError(new IllegalStateException(LanguageTool.getString("NO_PLAYER_ENGINE"))); } else { // Get engine of application state (default or selected by user) String selectedEngine = ApplicationState.getInstance().getPlayerEngine(); // If selected engine is not available then try default engine or another one if (!ArrayUtils.contains(engineNames, selectedEngine)) { getLogger().info(LogCategories.PLAYER, selectedEngine + " is not availaible"); if (ArrayUtils.contains(engineNames, DEFAULT_ENGINE)) { selectedEngine = DEFAULT_ENGINE; } else { // If default engine is not available, then get the first engine of map returned selectedEngine = engines.iterator().next().getEngineName(); } // Update application state with this engine ApplicationState.getInstance().setPlayerEngine(selectedEngine); } for (PlayerEngine engine : engines) { if (engine.getEngineName().equals(selectedEngine)) { instance.playerEngine = engine; getLogger().info(LogCategories.PLAYER, "Engine initialized : " + selectedEngine); } } if (instance.playerEngine == null) { handlePlayerError(new IllegalStateException(LanguageTool.getString("NO_PLAYER_ENGINE"))); } // Init engine instance.playerEngine.initializePlayerEngine(); Kernel.getInstance().addFinishListener(instance); // Add core playback listeners instance.playerEngine.addPlaybackStateListener(instance.playerEngine); instance.playerEngine.addPlaybackStateListener(VisualHandler.getInstance()); instance.playerEngine.addPlaybackStateListener(NotifyHandler.getInstance()); } // Add a shutdown hook to perform some actions before killing the JVM Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { getLogger().debug(LogCategories.SHUTDOWN_HOOK, "Final check for Zombie player engines"); instance.playerEngine.killPlayer(); getLogger().debug(LogCategories.SHUTDOWN_HOOK, "Closing player ..."); } })); } return instance; }
From source file:com.agimatec.validation.jsr303.DefaultMessageInterpolator.java
private String replaceAnnotationAttributes(String message, Map<String, Object> annotationParameters) { Matcher matcher = messageParameterPattern.matcher(message); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String resolvedParameterValue; String parameter = matcher.group(1); Object variable = annotationParameters.get(removeCurlyBrace(parameter)); if (variable != null) { if (variable.getClass().isArray()) { resolvedParameterValue = ArrayUtils.toString(variable); } else { resolvedParameterValue = variable.toString(); }/* w ww. j av a2 s.co m*/ } else { resolvedParameterValue = message; } matcher.appendReplacement(sb, resolvedParameterValue); } matcher.appendTail(sb); return sb.toString(); }
From source file:edu.cornell.med.icb.util.TestICBStringUtils.java
private void checkStringArray(final String testname, final String[] expected, final String[] found) { if (expected == null && found == null) { return;//from w ww. j a v a2 s .co m } if (expected == null) { // Expected is null but source is not fail("Source should have been null, but it was " + ArrayUtils.toString(found)); return; } if (found == null) { // Found is null but expected is not fail("Test: " + testname + ". Expected to find " + ArrayUtils.toString(expected) + " but found null"); return; } if (expected.length != found.length) { fail("Test: " + testname + ". Incorrect length. Expected was " + ArrayUtils.toString(expected) + " and found was " + ArrayUtils.toString(found)); return; } for (int i = 0; i < expected.length; i++) { if (!(expected[i].equals(found[i]))) { fail("Test: " + testname + ". Arrays differ. Expected was " + ArrayUtils.toString(expected) + " and found was " + ArrayUtils.toString(found)); return; } } }