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:mitm.common.mail.MailUtilsTest.java
@Test public void testSaveNewMessageRaw() throws IOException, MessagingException { File outputFile = File.createTempFile("mailUtilsTestRaw", ".eml"); outputFile.deleteOnExit();//from w w w . j a v a2 s . c o m MimeMessage message = new MimeMessage(MailSession.getDefaultSession()); message.addFrom(new InternetAddress[] { new InternetAddress("test@example.com") }); message.addRecipients(RecipientType.TO, "recipient@example.com"); message.setContent("test body", "text/plain"); message.saveChanges(); MailUtils.writeMessageRaw(message, new FileOutputStream(outputFile)); MimeMessage loadedMessage = MailUtils.loadMessage(outputFile); String recipients = ArrayUtils.toString(loadedMessage.getRecipients(RecipientType.TO)); assertEquals("{recipient@example.com}", recipients); String from = ArrayUtils.toString(loadedMessage.getFrom()); assertEquals("{test@example.com}", from); }
From source file:com.talent.nio.communicate.receive.DecodeRunnable.java
@Override public void run() { while (getMsgQueue().size() > 0) { ByteBuf queuedatas = null;//from ww w . j av a 2 s .c om CompositeByteBuf datas = Unpooled.compositeBuffer(); if (lastDatas != null) { channelContext.getStatVo().setCurrentOgnzTimestamp(SystemTimer.currentTimeMillis()); lastDatas.readerIndex(0); datas.addComponents(lastDatas); lastDatas = null; } int count = 0; label_2: while ((queuedatas = getMsgQueue().poll()) != null) { queuedatas = queuedatas.order(channelContext.getByteOrder()); if (DebugUtils.isNeedDebug(channelContext)) { // long xx = 999999999999999999L; log.error("queuedatas:" + ArrayUtils.toString(queuedatas)); } datas.addComponents(queuedatas); channelContext.getStatVo().setCurrentOgnzTimestamp(SystemTimer.currentTimeMillis()); count++; if (needLength != -1) // ???? { if (datas.capacity() < needLength) // ?? { // log.error("??----capacity:{}, needLength:{}", datas.capacity(), needLength); continue; } else { // log.error("?----capacity:{}, needLength:{}", datas.capacity(), needLength); break label_2; } } else // ??? { if (count == 50) { log.warn( "???{}???{}", count, getMsgQueue().size()); break label_2; } } } channelContext.getStatVo().setCurrentOgnzTimestamp(SystemTimer.currentTimeMillis()); PacketWithMeta packetWithMeta = null; try { // ByteBuffer buffer = ByteBuffer.wrap(datas); datas.writerIndex(datas.capacity()); datas.readerIndex(0); packetWithMeta = channelContext.getDecoder().decode(datas, channelContext); needLength = -1; if (packetWithMeta == null) { // ??? lastDatas = datas; lastDatas.readerIndex(0); if (DebugUtils.isNeedDebug(channelContext)) { log.error("???:{}", lastDatas); } } else if (packetWithMeta.getPackets() == null || packetWithMeta.getPackets().size() == 0) { // ??? lastDatas = datas; lastDatas.readerIndex(0); needLength = packetWithMeta.getNeedLength(); if (DebugUtils.isNeedDebug(channelContext)) { log.error("????:{}", needLength); } } else { int len = packetWithMeta.getPacketLenght(); // lastDatas = new byte[datas.capacity() - len]; // System.arraycopy(datas, len, lastDatas, 0, // lastDatas.length); if (datas.capacity() - len > 0) { lastDatas = datas.copy(len, datas.capacity() - len); if (DebugUtils.isNeedDebug(channelContext)) { log.error("??:{}, {}", datas.capacity() - len, lastDatas); } } else { lastDatas = null; if (DebugUtils.isNeedDebug(channelContext)) { log.error("??:{}", lastDatas); } } processMsgAndStat(packetWithMeta.getPackets(), len, false); } } catch (DecodeException e) { log.error(e.getMessage(), e); channelContext.getErrorPackageHandler().handle(channelContext.getSocketChannel(), channelContext, e.getMessage()); } } }
From source file:com.tacitknowledge.util.migration.jdbc.StandaloneMigrationLauncher.java
void run(String[] arguments) throws Exception { String migrationSystemName = ConfigurationUtil.getRequiredParam("migration.systemname", System.getProperties(), arguments, 0); String migrationSettings = ConfigurationUtil.getOptionalParam("migration.settings", System.getProperties(), arguments, 1);/*from www . jav a2s . com*/ boolean isRollback = false; int[] rollbackLevels = new int[] {}; boolean forceRollback = false; for (int i = 0; i < arguments.length; i++) { String argument1 = arguments[i]; if (ROLLBACK.equals(argument1)) { isRollback = true; if (i + 2 <= arguments.length) { String argument2 = arguments[i + 1]; if (argument2 != null) { try { rollbackLevels = getRollbackLevels(argument2); } catch (NumberFormatException nfe) { throw new MigrationException( "The rollbacklevels should be integers separated by a comma"); } } } if (rollbackLevels.length == 0) { // this indicates that the rollback level has not been set throw new MigrationException( "The rollback flag requires a following integer parameter or a list of integer parameters separated by comma to indicate the rollback level(s)."); } } if (FORCE_ROLLBACK.equals(argument1)) { forceRollback = true; } } // The MigrationLauncher is responsible for handling the interaction // between the PatchTable and the underlying MigrationTasks; as each // task is executed, the patch level is incremented, etc. try { if (isRollback) { String infoMessage = "Found rollback flag. AutoPatch will attempt to rollback the system to patch level(s) " + ArrayUtils.toString(rollbackLevels) + "."; log.info(infoMessage); migrationUtil.doRollbacks(migrationSystemName, migrationSettings, rollbackLevels, forceRollback); } else { migrationUtil.doMigrations(migrationSystemName, migrationSettings); } } catch (Exception e) { log.error(e); throw e; } }
From source file:com.taobao.ad.easyschedule.action.uuser.UUserAction.java
@ActionSecurity(module = 29) public String updateUser() { UUserDO uUserDO = this.userBO.getUUserById(this.user.getId()); if (user != null && roles != null && roles.length > 0) { uUserDO.setId(this.user.getId()); uUserDO.setUsername(this.user.getUsername()); uUserDO.setStatus(this.user.getStatus()); uUserDO.setDescn(this.user.getDescn()); uUserDO.setMobile(this.user.getMobile()); uUserDO.setEmail(this.user.getEmail()); uUserDO.setUpdateTime(null);/* w w w .j a v a 2 s.co m*/ this.userBO.updateUUser(uUserDO, roles, groups); StringBuilder detail = new StringBuilder(); detail.append("roles:").append(ArrayUtils.toString(roles)); detail.append(";groups:").append(ArrayUtils.toString(groups)); logsBO.insertSuccess(LogsDO.SUBTYPE_USER_MOD, user.getUsername() + "|" + (user.getDescn() == null ? "" : user.getDescn()), detail.toString(), getLogname()); } return SUCCESS; }
From source file:com.apress.progwt.server.service.impl.SearchServiceImpl.java
private CompassHitsOperations getHits(final String searchString, final int start, final int max_num_hits, final String[] aliases) { CompassHitsOperations hits = compassTemplate.executeFind(new CompassCallback() { public Object doInCompass(CompassSession session) throws CompassException { CompassHits hits = session.queryBuilder().queryString(searchString).toQuery().setAliases(aliases) .addSort("searchOrder", SortPropertyType.INT, SortDirection.REVERSE).hits(); return hits.detach(start, max_num_hits); }//from ww w . j ava 2 s . co m }); log.debug( "Search " + searchString + " alias " + ArrayUtils.toString(aliases) + " hits " + hits.getLength()); return hits; }
From source file:edu.cornell.med.icb.learning.weka.WekaClassifier.java
public double predict(final ClassificationModel trainingModel, final ClassificationProblem problem, final int instanceIndex, final double[] probabilities) { assert trainingModel instanceof WekaModel : "Model must be a weka model."; final double[] probs; try {//from w w w .j a va2 s. c om probs = getWekaClassifier(this) .distributionForInstance(getWekaProblem(problem).instance(instanceIndex)); } catch (Exception e) { LOG.error("Weka classifier has thrown exception.", e); return Double.NaN; } System.arraycopy(probs, 0, probabilities, 0, probs.length); if (LOG.isDebugEnabled()) { LOG.debug("decision values: " + ArrayUtils.toString(probabilities)); } double maxProb = Double.NEGATIVE_INFINITY; int maxIndex = -1; for (int labelIndex = 0; labelIndex < probabilities.length; labelIndex++) { if (probabilities[labelIndex] > maxProb) { maxProb = probabilities[labelIndex]; maxIndex = labelIndex; } } final double decision; if (maxIndex == -1) { decision = Double.NaN; } else { decision = labelIndex2LabelValue[maxIndex]; } if (LOG.isDebugEnabled()) { LOG.debug("decision: " + decision); } return decision; }
From source file:com.alibaba.otter.manager.biz.remote.impl.ConfigRemoteServiceImpl.java
public boolean notifyChannel(final Channel channel) { Assert.notNull(channel);/*from w ww .j av a2 s .c om*/ // ?Node NotifyChannelEvent event = new NotifyChannelEvent(); event.setChannel(channel); Set<String> addrsSet = new HashSet<String>(); // ?otternode // List<Node> nodes = nodeService.listAll(); // for (Node node : nodes) { // if (node.getStatus().isStart() && // StringUtils.isNotEmpty(node.getIp()) && node.getPort() != 0) { // final String addr = node.getIp() + ":" + node.getPort(); // addrsList.add(addr); // } // } // ?pipelinenode for (Pipeline pipeline : channel.getPipelines()) { List<Node> nodes = new ArrayList<Node>(); nodes.addAll(pipeline.getSelectNodes()); nodes.addAll(pipeline.getExtractNodes()); nodes.addAll(pipeline.getLoadNodes()); for (Node node : nodes) { if (node.getStatus().isStart() && StringUtils.isNotEmpty(node.getIp()) && node.getPort() != 0) { String addr = node.getIp() + ":" + node.getPort(); if (node.getParameters().getUseExternalIp()) { addr = node.getParameters().getExternalIp() + ":" + node.getPort(); } addrsSet.add(addr); } } } List<String> addrsList = new ArrayList<String>(addrsSet); if (CollectionUtils.isEmpty(addrsList) && channel.getStatus().isStart()) { throw new ManagerException("no live node for notifyChannel"); } else if (CollectionUtils.isEmpty(addrsList)) { // ??? return true; } else { Collections.shuffle(addrsList);// ??????? try { String[] addrs = addrsList.toArray(new String[addrsList.size()]); List<Boolean> result = (List<Boolean>) communicationClient.call(addrs, event); // ?? logger.info("## notifyChannel to [{}] channel[{}] result[{}]", new Object[] { ArrayUtils.toString(addrs), channel.toString(), result }); boolean flag = true; for (Boolean f : result) { flag &= f; } return flag; } catch (Exception e) { logger.error("## notifyChannel error!", e); throw new ManagerException(e); } } }
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 a 2 s . com*/ public void testCoefficientsNoTotals2() { String[][] distinctValues = new String[][] { new String[] { "North", "South", "East", "West" }, new String[] { "M", "F" }, new String[] { "20", "50", "80" } }; classUnderTest = new CrossTabCoefficients(distinctValues, false); assertNotNull(classUnderTest); //test colcount and rowcount assertEquals(classUnderTest.getTemplateColumnCount(), 24); 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, 0, 0 })); //test number of totals result = classUnderTest.getTotalsCntInHeaderRow(); assertNotNull(result); System.out.println("Totals Cnt : " + ArrayUtils.toString(result)); assertTrue(ArrayUtils.isEquals(result, new int[] { 0, 0, 0 })); //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[] { 6, 3, 1 })); }
From source file:com.manydesigns.elements.fields.search.SelectSearchField.java
public void configureCriteria(Criteria criteria) { if (!required && notSet) { criteria.isNull(accessor);/*from w ww. j av a 2 s. c o m*/ return; } Object[] values = getValues(); if (values == null) { logger.debug("Null values array. Not adding 'in' criteria."); } else if (values.length == 0) { logger.debug("Enpty values array. Not adding 'in' criteria."); } else { if (logger.isDebugEnabled()) { logger.debug("Adding 'in' criteria for values: {}", ArrayUtils.toString(values)); } criteria.in(accessor, values); } }
From source file:ext.scrollablepopupmenu.TestXCheckedButton.java
/** * Test mouse adapter.//from w w w .jav a 2 s .c o m * */ public void testMouseAdapter() { XCheckedButton button = new XCheckedButton("testtext", new DummyIcon()); // we should have at least one a mouse listener on the button assertTrue(ArrayUtils.toString(button.getMouseListeners()), button.getMouseListeners().length > 0); // none of them looks at the actual event right now... button.getMouseListeners()[1].mousePressed(null); button.getMouseListeners()[1].mouseEntered(null); button.getMouseListeners()[1].mouseExited(null); }