List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:com.opengamma.analytics.math.surface.NodalSurfaceAdditiveShiftFunction.java
/** * {@inheritDoc}//from w w w . j a v a2 s. com * @throws IllegalArgumentException If the point to shift is not a nodal point of the surface */ @Override public NodalDoublesSurface evaluate(final NodalDoublesSurface surface, final double x, final double y, final double shift, final String newName) { Validate.notNull(surface, "surface"); final double[] xData = surface.getXDataAsPrimitive(); final double[] yData = surface.getYDataAsPrimitive(); final double[] zData = surface.getZDataAsPrimitive(); final int n = zData.length; for (int i = 0; i < n; i++) { if (Double.doubleToLongBits(xData[i]) == Double.doubleToLongBits(x)) { if (Double.doubleToLongBits(yData[i]) == Double.doubleToLongBits(y)) { final double[] shiftedZ = Arrays.copyOf(zData, n); shiftedZ[i] += shift; return NodalDoublesSurface.from(xData, yData, shiftedZ, newName); } } } throw new IllegalArgumentException("No x-y data in surface for (" + x + ", " + y + ")"); }
From source file:com.adobe.acs.commons.exporters.impl.users.Parameters.java
public String[] getCustomProperties() { return Arrays.copyOf(customProperties, customProperties.length); }
From source file:org.apache.solr.common.util.Utils.java
public static byte[] toUTF8(CharArr out) { byte[] arr = new byte[out.size() * 3]; int nBytes = ByteUtils.UTF16toUTF8(out, 0, out.size(), arr, 0); return Arrays.copyOf(arr, nBytes); }
From source file:com.smartsheet.api.internal.http.HttpEntitySnapshot.java
/** * this ctor creates a snapshot of the original entity (which requires its stream either support reset or it must be * entirely consumed and replaced with an exact copy) *//*w w w . j a va 2 s . c om*/ public HttpEntitySnapshot(HttpEntity original) throws IOException { final String contentType = original.getContentType(); final InputStream contentStream = original.getContent(); final long contentLength = original.getContentLength(); super.setContentLength(contentLength); super.setContentType(contentType); if (contentType != null && contentType.startsWith(JSON_MIME_TYPE)) { // we need to read and then reset (if possible) the original entity's content stream (or replace it with an exact copy) // if contentLength > Integer.MAX_VALUE we have MUCH bigger problems than long->int rollover boolean sourceSupportsMark = contentStream.markSupported(); if (sourceSupportsMark) { // here we can read up to a limited contents contentArray = new byte[MAX_SNAPSHOT_SIZE]; contentStream.mark(MAX_SNAPSHOT_SIZE + 1); int bytesRead = contentStream.read(contentArray, 0, MAX_SNAPSHOT_SIZE); contentStream.reset(); // trim content array to actual size if (bytesRead < MAX_SNAPSHOT_SIZE) { contentArray = Arrays.copyOf(contentArray, bytesRead); } } else { // here we must read everything and then repackage the byte[] into an input stream to replace the original byte[] fullContentArray; try { fullContentArray = StreamUtil.readBytesFromStream(contentStream, StreamUtil.ONE_MB); } finally { contentStream.close(); } // having consumed the content into memory we must now replace the original stream (so it can be read by subsequent code) original.setContent(new ByteArrayInputStream(fullContentArray)); // and we need a copy for potential logging purposes contentArray = Arrays.copyOf(fullContentArray, Math.min(MAX_SNAPSHOT_SIZE, fullContentArray.length)); // we see a lot of Content-Length:-1 from certain responses - no point in logging those if (contentLength != -1 && fullContentArray.length != contentLength) { LoggerFactory.getLogger(HttpEntitySnapshot.class).info( "actual content-length {} doesn't match" + " declared content-length {}", fullContentArray.length, contentLength); } } } else { contentArray = String.format("**contentType '%s' not logged**", contentType).getBytes(); } }
From source file:graph.inference.module.TransitiveWorker.java
/** * Runs the transitive interval module to efficiently compute the solution * to a query./*from w ww . j av a2 s .c o m*/ * * @param queryObj * The query to run and store results in. */ private void runIntervalModule(QueryObject queryObj) { // TODO Ensure node is a collection. if (queryObj.isProof()) { // Find the proof and justify it. Collection<DAGNode> result = transIntModule_.execute(true, queryObj.getNode(1), queryObj.getNode(2)); if (result != null) { queryObj.addResult(new Substitution(), queryObj.getNodes()); List<Node[]> justification = queryObj.getJustification(); justification.clear(); justification.addAll(transIntModule_.justifyTransitive((DAGNode) queryObj.getNode(1), (DAGNode) queryObj.getNode(2))); } } else { // Find the results and add them to the query object. boolean upwards = queryObj.getAtomicIndex() == 1; DAGNode baseNode = queryObj.getAtomic(); Collection<DAGNode> transitiveNodes = transIntModule_.execute(upwards, baseNode); if (transitiveNodes == null) return; for (DAGNode n : transitiveNodes) { queryObj.addCompleted(n); Node[] nodes = Arrays.copyOf(queryObj.getNodes(), 3); nodes[queryObj.getVariableIndex()] = n; queryObj.addResult(nodes); } } }
From source file:com.adobe.acs.commons.quickly.Command.java
public String[] getPunctuation() { return Arrays.copyOf(this.punctuation, this.punctuation.length); }
From source file:azkaban.flow.GroupedExecutableFlow.java
public GroupedExecutableFlow(String id, ExecutableFlow... flows) { this.id = id; this.flows = flows; this.sortedFlows = Arrays.copyOf(this.flows, this.flows.length); Arrays.sort(this.sortedFlows, new Comparator<ExecutableFlow>() { @Override/*from w ww . j ava 2 s.c o m*/ public int compare(ExecutableFlow o1, ExecutableFlow o2) { return o1.getName().compareTo(o2.getName()); } }); String[] names = new String[flows.length]; for (int i = 0; i < flows.length; i++) { names[i] = flows[i].getName(); } name = StringUtils.join(names, " + "); jobState = Status.READY; updateState(); callbacksToCall = new ArrayList<FlowCallback>(); theGroupCallback = new GroupedFlowCallback(); switch (jobState) { case SUCCEEDED: case COMPLETED: case FAILED: DateTime theStartTime = new DateTime(); DateTime theEndTime = new DateTime(0); for (ExecutableFlow flow : flows) { final DateTime subFlowStartTime = flow.getStartTime(); if (theStartTime.isAfter(subFlowStartTime)) { theStartTime = subFlowStartTime; } final DateTime subFlowEndTime = flow.getEndTime(); if (subFlowEndTime != null && subFlowEndTime.isAfter(theEndTime)) { theEndTime = subFlowEndTime; } } setAndVerifyParentProps(); startTime = theStartTime; endTime = theEndTime; break; default: // Check for Flows that are "RUNNING" boolean allRunning = true; List<ExecutableFlow> runningFlows = new ArrayList<ExecutableFlow>(); DateTime thisStartTime = null; for (ExecutableFlow flow : flows) { if (flow.getStatus() != Status.RUNNING) { allRunning = false; final DateTime subFlowStartTime = flow.getStartTime(); if (subFlowStartTime != null && subFlowStartTime.isBefore(thisStartTime)) { thisStartTime = subFlowStartTime; } } else { runningFlows.add(flow); } } if (allRunning) { jobState = Status.RUNNING; } for (ExecutableFlow runningFlow : runningFlows) { final DateTime subFlowStartTime = runningFlow.getStartTime(); if (subFlowStartTime != null && subFlowStartTime.isBefore(thisStartTime)) { thisStartTime = subFlowStartTime; } } setAndVerifyParentProps(); startTime = thisStartTime; endTime = null; // Make sure everything is initialized before leaking the pointer to "this". // This is just installing the callback in an already running flow. for (ExecutableFlow runningFlow : runningFlows) { runningFlow.execute(parentProps, theGroupCallback); } } }
From source file:com.opengamma.analytics.math.surface.NodalSurfaceMultiplicativeShiftFunction.java
/** * {@inheritDoc}// w w w .java 2 s . c o m * @throws IllegalArgumentException If the point to shift is not a nodal point of the surface */ @Override public NodalDoublesSurface evaluate(final NodalDoublesSurface surface, final double x, final double y, final double percentage, final String newName) { Validate.notNull(surface, "surface"); final double[] xData = surface.getXDataAsPrimitive(); final double[] yData = surface.getYDataAsPrimitive(); final double[] zData = surface.getZDataAsPrimitive(); final int n = zData.length; for (int i = 0; i < n; i++) { if (Double.doubleToLongBits(xData[i]) == Double.doubleToLongBits(x)) { if (Double.doubleToLongBits(yData[i]) == Double.doubleToLongBits(y)) { final double[] shiftedZ = Arrays.copyOf(zData, n); shiftedZ[i] *= 1 + percentage; return NodalDoublesSurface.from(xData, yData, shiftedZ, newName); } } } throw new IllegalArgumentException("No x-y data in surface for (" + x + ", " + y + ")"); }
From source file:de.codecentric.boot.admin.notify.MailNotifier.java
public void setTo(String[] to) { this.to = Arrays.copyOf(to, to.length); }
From source file:com.rapidminer.operator.learner.tree.SelectionCreator.java
/** * Creates an example index start selection for each numerical attribute, or if there is none, * only one.//from ww w . ja va2 s . com * * @return a map containing for each numerical attribute an example index array such that the * associated attribute values are in ascending order. */ public Map<Integer, int[]> getStartSelection() { Map<Integer, int[]> selection = new HashMap<>(); if (columnTable.getNumberOfRegularNumericalAttributes() == 0) { selection.put(0, createFullArray(columnTable.getNumberOfExamples())); } else { Integer[] bigSelectionArray = createFullBigArray(columnTable.getNumberOfExamples()); for (int j = columnTable.getNumberOfRegularNominalAttributes(); j < columnTable .getTotalNumberOfRegularAttributes(); j++) { final double[] attributeColumn = columnTable.getNumericalAttributeColumn(j); Integer[] startSelection = Arrays.copyOf(bigSelectionArray, bigSelectionArray.length); Arrays.sort(startSelection, new Comparator<Integer>() { @Override public int compare(Integer a, Integer b) { return Double.compare(attributeColumn[a], attributeColumn[b]); } }); selection.put(j, ArrayUtils.toPrimitive(startSelection)); } } return selection; }