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.core.meka.SOMController.java
private String ejecutarTest(double[][] patrones) { String result = ""; if (patrones != null) { result = "Resultado del test\n"; for (double[] patron : patrones) { int neurona = som.test(patron); result += "\ntest(" + ArrayUtils.toString(patron).replaceAll("\\{", "").replaceAll("\\}", "") + ") activa la neurona " + neurona + " " + "[" + ArrayUtils.toString(som.getW()[neurona]).replaceAll("\\{", "").replaceAll("\\}", "") + "]"; }//from w w w . j av a 2s . com } return result; }
From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractMessageWrappingController.java
/** * Parameter value to string./*from w w w.j av a 2 s.c o m*/ * * @param param * the param * @return the string */ private String parameterValueToString(Object param) { String paramString; if (param.getClass().isArray()) { paramString = ArrayUtils.toString(param); } else { paramString = param.toString().trim(); } if (paramString.startsWith("{")) { paramString = paramString.substring(1); } if (paramString.endsWith("}")) { paramString = paramString.substring(0, paramString.length() - 1); } return paramString; }
From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java
@Test public void testQueryIte_reverse() { String query = "VPool[exists @environment]{*}.parentCluster!Compute[@fqdns=~\".*.com\"]"; QueryContext qc = newQueryContext(STRATUS_REPO, IBranch.DEFAULT_BRANCH); qc.setPaginationMode(PaginationMode.ID_BASED); qc.setAllowFullTableScan(true);// w w w . j a va 2 s. co m qc.getCursor().setLimits(new int[] { 1, 2 }); qc.setSourceIP("127.0.0.1"); IQueryResult result = queryService.query(query, qc); Assert.assertTrue(result.hasMoreResults()); Assert.assertNotNull(result.getNextCursor().getJoinCursorValues()); Assert.assertNull(result.getNextCursor().getSkips()); int[] nLimit = result.getNextCursor().getLimits(); int hint = result.getNextCursor().getHint(); Assert.assertEquals(0, hint); Assert.assertEquals(2, nLimit.length); Assert.assertEquals(1, nLimit[0]); Assert.assertEquals(2, nLimit[1]); int count = result.getEntities().size(); System.out.println("fetch size: " + count); int iterateCount = 1; while (result.hasMoreResults()) { iterateCount++; System.out.println("iterate round: " + iterateCount + ", next skip _oids: " + ArrayUtils.toString(result.getNextCursor().getJoinCursorValues()) + ",next limits: " + ArrayUtils.toString(result.getNextCursor().getLimits())); qc.setCursor(result.getNextCursor()); result = queryService.query(query, qc); System.out.println("fetch size: " + result.getEntities().size()); count += result.getEntities().size(); } Assert.assertEquals(11, iterateCount); QueryContext qc1 = newQueryContext(STRATUS_REPO, IBranch.DEFAULT_BRANCH); qc1.setAllowFullTableScan(true); qc.setPaginationMode(PaginationMode.ID_BASED); qc1.setSourceIP("127.0.0.1"); IQueryResult result1 = queryService.query(query, qc1); Assert.assertFalse(result1.hasMoreResults()); Assert.assertNull(result.getNextCursor()); Assert.assertTrue(count >= result1.getEntities().size()); }
From source file:edu.cornell.med.icb.learning.CrossValidation.java
/** * Evaluate a variety of performance measures with <a href="http://rocr.bioinf.mpi-sb.mpg.de/ROCR.pdf">ROCR</a>. * * @param decisionValues Larger values indicate better confidence that the instance belongs to class 1. * @param labels Values of -1 or 0 indicate that the instance belongs to class 0, values of 1 indicate that the * instance belongs to class 1. * @param measureNames Name of performance measures to evaluate. * @param measure Where performance values will be stored. * @see #evaluateMeasure/*from w ww . j av a 2 s . c o m*/ */ public static void evaluateWithROCR(final double[] decisionValues, final double[] labels, final ObjectSet<CharSequence> measureNames, final EvaluationMeasure measure, final CharSequence measureNamePrefix) { assert decisionValues.length == labels.length : "number of predictions must match number of labels."; for (int i = 0; i < labels.length; i++) { // for each training example, leave it out: if (labels[i] < 0) { labels[i] = 0; } } if (LOG.isDebugEnabled()) { LOG.debug("decisions: " + ArrayUtils.toString(decisionValues)); } if (LOG.isDebugEnabled()) { LOG.debug("labels: " + ArrayUtils.toString(labels)); } final RConnectionPool connectionPool = RConnectionPool.getInstance(); RConnection connection = null; CharSequence performanceValueName = null; try { // CALL R ROC connection = connectionPool.borrowConnection(); connection.assign("predictions", decisionValues); connection.assign("labels", labels); // library(ROCR) // predictions <- c(1,1,0,1,1,1,1) // labels <- c(1,1,1,1,1,0,1) // flabels <- factor(labels,c(0,1)) // pred.svm <- prediction(predictions, flabels) // perf.svm <- performance(pred.svm, 'auc') // attr(perf.svm,"y.values")[[1]] final StringBuilder rCommand = new StringBuilder(); rCommand.append("library(ROCR)\n"); rCommand.append("flabels <- labels\n"); rCommand.append("pred.svm <- prediction(predictions, labels)\n"); connection.eval(rCommand.toString()); for (ObjectIterator<CharSequence> charSequenceObjectIterator = measureNames .iterator(); charSequenceObjectIterator.hasNext();) { final StringBuilder rCommandMeasure = new StringBuilder(); performanceValueName = charSequenceObjectIterator.next(); if (performanceValueName == null) { continue; } final CharSequence storedPerformanceMeasureName = measureNamePrefix.toString() + performanceValueName.toString(); rCommandMeasure.append("perf.svm <- performance(pred.svm, '"); rCommandMeasure.append(performanceValueName); rCommandMeasure.append("')\n"); rCommandMeasure.append("attr(perf.svm,\"y.values\")[[1]]"); final REXP expressionValue = connection.eval(rCommandMeasure.toString()); final double[] values = expressionValue.asDoubles(); if (values.length == 1) { // this performance measure is threshold independent.. LOG.debug("result from R (" + performanceValueName + ") : " + values[0]); measure.addValue(storedPerformanceMeasureName, values[0]); } else { // we have one performance measure value per decision threshold. final StringBuilder rCommandThresholds = new StringBuilder(); rCommandThresholds.append("attr(perf.svm,\"x.values\")[[1]]"); final REXP expressionThresholds = connection.eval(rCommandThresholds.toString()); final double[] thresholds = expressionThresholds.asDoubles(); // find the index of x.value which indicates a threshold more or equal to zero (for the decision value) int thresholdGEZero = -1; for (int index = thresholds.length - 1; index >= 0; index--) { if (thresholds[index] >= 0) { thresholdGEZero = index; break; } } if (LOG.isDebugEnabled()) { LOG.debug("result from R (" + performanceValueName + ") : " + values[thresholdGEZero]); } if (thresholdGEZero != -1) { measure.addValue(storedPerformanceMeasureName, values[thresholdGEZero]); } } } } catch (Exception e) { // connection error or otherwise LOG.warn("Cannot evaluate performance measure " + performanceValueName + ". Make sure Rserve (R server) is configured and running.", e); } finally { if (connection != null) { connectionPool.returnConnection(connection); } } }
From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java
@Test public void testQueryIte_join() { String query = "VPool[exists @environment]{*}.computes[@fqdns=~\".*.com\"]"; QueryContext qc = newQueryContext(STRATUS_REPO, IBranch.DEFAULT_BRANCH); qc.setPaginationMode(PaginationMode.ID_BASED); qc.setAllowFullTableScan(true);//from www . jav a 2s . c o m qc.setLimits(new int[] { 1, 6 }); qc.setSourceIP("127.0.0.1"); IQueryResult result = queryService.query(query, qc); Assert.assertTrue(result.hasMoreResults()); int[] nLimit = result.getNextCursor().getLimits(); int hint = result.getNextCursor().getHint(); Assert.assertEquals(0, hint); List<String> nextCursorValues = result.getNextCursor().getJoinCursorValues(); Assert.assertNotNull(nextCursorValues); Assert.assertEquals(2, nextCursorValues.size()); Assert.assertEquals(2, nLimit.length); Assert.assertEquals(1, nLimit[0]); Assert.assertEquals(6, nLimit[1]); // continuing query using the next cursor List<String> fetchVPoolIds = new ArrayList<String>(); int count = result.getEntities().size(); System.out.println("fetch size: " + count); // add to fetched ids for (IEntity entity : result.getEntities()) { fetchVPoolIds.add(entity.getId()); } int iterateCount = 1; while (result.hasMoreResults()) { iterateCount++; System.out.println("iterate round: " + iterateCount + ", next skip _oid s: " + ArrayUtils.toString(result.getNextCursor().getJoinCursorValues()) + ",next limits: " + ArrayUtils.toString(result.getNextCursor().getLimits())); qc.setCursor(result.getNextCursor()); result = queryService.query(query, qc); System.out.println("fetch size: " + result.getEntities().size()); count += result.getEntities().size(); for (IEntity entity : result.getEntities()) { Assert.assertFalse(fetchVPoolIds.contains(entity.getId())); fetchVPoolIds.add(entity.getId()); } } Assert.assertEquals(10, iterateCount); // assert the iterated query results with the no-limit results. List<String> fetchVPoolIds2 = new ArrayList<String>(); QueryContext qc1 = newQueryContext(STRATUS_REPO, IBranch.DEFAULT_BRANCH); qc1.setPaginationMode(PaginationMode.ID_BASED); qc1.setAllowFullTableScan(true); qc1.setSourceIP("127.0.0.1"); IQueryResult result1 = queryService.query(query, qc1); Assert.assertFalse(result1.hasMoreResults()); Assert.assertTrue(2 >= result1.getEntities().size()); for (IEntity entity : result1.getEntities()) { fetchVPoolIds2.add(entity.getId()); } Assert.assertEquals(fetchVPoolIds, fetchVPoolIds2); }
From source file:edu.cornell.med.icb.goby.modes.SortMode.java
/** * Subsequent merge of multiple splits/*from w ww . java 2 s . co m*/ * * @param toMerge the splits to sort * @param lastMerge if this is the very last merge */ private void mergeSplits(final List<SortMergeSplit> toMerge, final boolean lastMerge) { numSortMergesRunning.incrementAndGet(); final Runnable toRun = new Runnable() { @Override public void run() { final String threadId = String.format("%02d", Thread.currentThread().getId()); final List<String> mergeFromBasenames = new LinkedList<String>(); ConcatSortedAlignmentReader concatReader = null; AlignmentWriter writer = null; try { System.gc(); // Prepare to merge final SortMergeSplit merged = new SortMergeSplit(toMerge.get(0)); final int numSplits = toMerge.size(); for (int i = 1; i < numSplits; i++) { merged.mergeWith(toMerge.get(i)); } merged.ranges = mergeRangeList(merged.ranges); LOG.debug(String.format("[%s] Merging %d items %s to %s", threadId, numSplits, ArrayUtils.toString(toMerge), ArrayUtils.toString(merged))); for (final SortMergeSplit mergeFrom : toMerge) { final String inputBasename = tempDir + "/sorted-" + mergeFrom.tag; mergeFromBasenames.add(inputBasename); } // note that we don't adjust query indices because they are already not overlapping (all come from the // same input file) final String[] mergeFromBasenamesArray = mergeFromBasenames .toArray(new String[mergeFromBasenames.size()]); for (final String mergeBasename : mergeFromBasenamesArray) { checkBasename(threadId, mergeBasename); } if (!dryRun) { concatReader = new ConcatSortedAlignmentReader(false, mergeFromBasenamesArray); concatReader.readHeader(); } // We've used merged's tag as input. Let's get a new tag for it's output merged.makeNewTag(); final String subOutputFilename; if (lastMerge) { subOutputFilename = outputFilename; } else { final String subBasename = "sorted-" + merged.tag; subOutputFilename = tempDir + "/" + subBasename; } if (!dryRun) { writer = new AlignmentWriterImpl(subOutputFilename); HeaderUtil.copyHeader(concatReader, writer); writer.setSorted(true); for (final Alignments.AlignmentEntry entry : concatReader) { writer.appendEntry(entry); } } if (dryRun) { System.out.printf("dry-run: will sort-merge %d splits into %s %n", toMerge.size(), merged.toString()); } // Sort/merge finished numMergesExecuted.incrementAndGet(); sortedSplits.add(merged); } catch (Throwable e) { LOG.error(String.format("[%s] Exception sorting!! class=%s message=%s", threadId, e.getClass().getName(), e.getMessage())); e.printStackTrace(); exceptions.add(e); } finally { try { if (concatReader != null) { concatReader.close(); } } catch (IOException e) { // Close quietly. LOG.info("Exception closing concatReader", e); } try { if (writer != null) { writer.close(); } } catch (IOException e) { // Close quietly. LOG.info("Exception closing writer", e); } // Delete the merged FROM files for (final String mergeFromBasename : mergeFromBasenames) { deleteFile(new File(mergeFromBasename + ".entries"), true); deleteFile(new File(mergeFromBasename + ".header"), true); deleteFile(new File(mergeFromBasename + ".index"), true); deleteFile(new File(mergeFromBasename + ".stats"), true); } progressMergeSort.update(toMerge.size() - 1); } } }; if (executorService != null) { executorService.submit(toRun); } else { toRun.run(); } }
From source file:edu.cornell.med.icb.io.TestConditionsParser.java
private void checkIntArray(final int[] expected, final int[] found) { if (expected == null && found == null) { return;//from w w w. j ava 2 s. c o 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("Expected to find " + ArrayUtils.toString(expected) + " but found null"); return; } if (expected.length != found.length) { fail("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] != found[i]) { fail("Arrays differ. Expected was " + ArrayUtils.toString(expected) + " and found was " + ArrayUtils.toString(found)); return; } } }
From source file:edu.cornell.med.icb.io.TestConditionsParser.java
private void checkBooleanArray(final boolean[] expected, final boolean[] found) { if (expected == null && found == null) { return;//from w w w . j a v a2s.c o 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("Expected to find " + ArrayUtils.toString(expected) + " but found null"); return; } if (expected.length != found.length) { fail("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] != found[i]) { fail("Arrays differ. Expected was " + ArrayUtils.toString(expected) + " and found was " + ArrayUtils.toString(found)); return; } } }
From source file:edu.cornell.med.icb.io.TestConditionsParser.java
private void checkDoubleArray(final double[] expected, final double[] found) { if (expected == null && found == null) { return;//from ww w . j a va 2 s . com } 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("Expected to find " + ArrayUtils.toString(expected) + " but found null"); return; } if (expected.length != found.length) { fail("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] != found[i]) { fail("Arrays differ. Expected was " + ArrayUtils.toString(expected) + " and found was " + ArrayUtils.toString(found)); return; } } }
From source file:edu.cornell.med.icb.io.TestConditionsParser.java
private void checkStringArray(final String[] expected, final String[] found) { if (expected == null && found == null) { return;/*from w w w.j av a2s.c om*/ } 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("Expected to find " + ArrayUtils.toString(expected) + " but found null"); return; } if (expected.length != found.length) { fail("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("Arrays differ. Expected was " + ArrayUtils.toString(expected) + " and found was " + ArrayUtils.toString(found)); return; } } }