List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:com.fns.grivet.repo.JdbcEntityRepository.java
@Override public void save(Long eid, Attribute attribute, AttributeType attributeType, Object rawValue, LocalDateTime createdTime) { Assert.isTrue(rawValue != null, String .format("Attempt to persist value failed! %s's value must not be null!", attribute.getName())); Object value = ValueHelper.toValue(attributeType, rawValue); String createdBy = getCurrentUsername(); String[] columns = { "eid", "aid", "val", "created_time" }; Map<String, Object> keyValuePairs = ImmutableMap.of("eid", eid, "aid", attribute.getId(), "val", value, "created_time", Timestamp.valueOf(createdTime)); if (createdBy != null) { columns = Arrays.copyOf(columns, columns.length + 1); columns[columns.length - 1] = "created_by"; Map<String, Object> keyValuePairsWithCreatedBy = new HashMap<>(keyValuePairs); keyValuePairsWithCreatedBy.put("created_by", createdBy); keyValuePairs = keyValuePairsWithCreatedBy; }/*from w w w. java 2 s .c o m*/ new SimpleJdbcInsert(jdbcTemplate).withTableName(String.join("_", "entityav", attributeType.getType())) .usingColumns(columns).execute(keyValuePairs); }
From source file:com.intuit.tank.harness.functions.CSVReader.java
public synchronized String[] getNextLine(boolean loop) { String[] ret = null;//from w w w .ja v a 2s.c om if (pointer >= lines.size()) { if (loop) { pointer = 0; } else { return null; } } ret = lines.get(pointer); pointer++; return Arrays.copyOf(ret, ret.length); }
From source file:com.sonicle.webtop.core.util.IdentifierUtils.java
/** * @deprecated use com.sonicle.commons.IdentifierUtils.getCRSFToken instead * @return//w w w. j a va 2 s . c o m */ @Deprecated public static synchronized String getCRSFToken() { try { byte[] buffer = new byte[80 / 8]; SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); sr.nextBytes(buffer); byte[] secretKey = Arrays.copyOf(buffer, 80 / 8); byte[] encodedKey = new Base32().encode(secretKey); return new String(encodedKey).toLowerCase(); } catch (NoSuchAlgorithmException ex) { return null; } }
From source file:com.opengamma.analytics.math.surface.InterpolatedFromCurvesSurfaceAdditiveShiftFunction.java
/** * {@inheritDoc}/*from www.j av a 2s . c o m*/ * @throws UnsupportedOperationException If the <i>x</i> (<i>y</i>) position of the shift does not coincide with one of the <i>x</i> (<i>y</i>) intersections * of the curves with the axis */ @Override public InterpolatedFromCurvesDoublesSurface evaluate(final InterpolatedFromCurvesDoublesSurface surface, final double x, final double y, final double shift, final String newName) { Validate.notNull(surface, "surface"); final boolean xzCurves = surface.isXZCurves(); final double[] points = surface.getPoints(); if (xzCurves) { final int index = Arrays.binarySearch(points, y); final Curve<Double, Double>[] curves = surface.getCurves(); if (index >= 0) { final Curve<Double, Double>[] newCurves = Arrays.copyOf(surface.getCurves(), points.length); newCurves[index] = CurveShiftFunctionFactory.getShiftedCurve(curves[index], x, shift); return InterpolatedFromCurvesDoublesSurface.fromSorted(xzCurves, points, newCurves, surface.getInterpolator(), newName); } throw new UnsupportedOperationException( "Cannot get shift for y-value not in original list of curves: asked for " + y); } final int index = Arrays.binarySearch(points, x); final Curve<Double, Double>[] curves = surface.getCurves(); if (index >= 0) { final Curve<Double, Double>[] newCurves = Arrays.copyOf(surface.getCurves(), points.length); newCurves[index] = CurveShiftFunctionFactory.getShiftedCurve(curves[index], y, shift); return InterpolatedFromCurvesDoublesSurface.fromSorted(xzCurves, points, newCurves, surface.getInterpolator(), newName); } throw new UnsupportedOperationException( "Cannot get shift for x-value not in original list of curves: asked for " + x); }
From source file:com.almende.eve.algorithms.Graph.java
/** * Adds a new edge./*from ww w. j a v a 2 s . c o m*/ * * @param edge * the edge */ @Access(AccessType.PUBLIC) public void addEdge(final @Name("edge") Edge edge) { edges = Arrays.copyOf(edges, edges.length + 1); edges[edges.length - 1] = edge; if (set != null) { set.add(edge); } }
From source file:com.opengamma.analytics.math.interpolation.MonotonicityPreservingQuinticSplineInterpolator.java
@Override public PiecewisePolynomialResult interpolate(final double[] xValues, final double[] yValues) { ArgumentChecker.notNull(xValues, "xValues"); ArgumentChecker.notNull(yValues, "yValues"); ArgumentChecker.isTrue(xValues.length == yValues.length | xValues.length + 2 == yValues.length, "(xValues length = yValues length) or (xValues length + 2 = yValues length)"); ArgumentChecker.isTrue(xValues.length > 2, "Data points should be more than 2"); final int nDataPts = xValues.length; final int yValuesLen = yValues.length; for (int i = 0; i < nDataPts; ++i) { ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xValues containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xValues containing Infinity"); }/* ww w .j a v a 2 s .co m*/ for (int i = 0; i < yValuesLen; ++i) { ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yValues containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yValues containing Infinity"); } for (int i = 0; i < nDataPts - 1; ++i) { for (int j = i + 1; j < nDataPts; ++j) { ArgumentChecker.isFalse(xValues[i] == xValues[j], "xValues should be distinct"); } } double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts); double[] yValuesSrt = new double[nDataPts]; if (nDataPts == yValuesLen) { yValuesSrt = Arrays.copyOf(yValues, nDataPts); } else { yValuesSrt = Arrays.copyOfRange(yValues, 1, nDataPts + 1); } ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt); final double[] intervals = _solver.intervalsCalculator(xValuesSrt); final double[] slopes = _solver.slopesCalculator(yValuesSrt, intervals); final PiecewisePolynomialResult result = _method.interpolate(xValues, yValues); ArgumentChecker.isTrue(result.getOrder() >= 3, "Primary interpolant should be degree >= 2"); final double[] initialFirst = _function.differentiate(result, xValuesSrt).getData()[0]; final double[] initialSecond = _function.differentiateTwice(result, xValuesSrt).getData()[0]; double[] first = firstDerivativeCalculator(yValuesSrt, intervals, slopes, initialFirst); boolean modFirst = false; int k; double[] aValues = aValuesCalculator(slopes, first); double[] bValues = bValuesCalculator(slopes, first); double[][] intervalsA = getIntervalsA(intervals, slopes, first, bValues); double[][] intervalsB = getIntervalsB(intervals, slopes, first, aValues); while (modFirst == false) { k = 0; for (int i = 0; i < nDataPts - 2; ++i) { if (first[i + 1] > 0.) { if (intervalsA[i + 1][1] + Math.abs(intervalsA[i + 1][1]) * ERROR < intervalsB[i][0] - Math.abs(intervalsB[i][0]) * ERROR | intervalsA[i + 1][0] - Math.abs(intervalsA[i + 1][0]) * ERROR > intervalsB[i][1] + Math.abs(intervalsB[i][1]) * ERROR) { ++k; first[i + 1] = firstDerivativesRecalculator(intervals, slopes, aValues, bValues, i + 1); } } } if (k == 0) { modFirst = true; } aValues = aValuesCalculator(slopes, first); bValues = bValuesCalculator(slopes, first); intervalsA = getIntervalsA(intervals, slopes, first, bValues); intervalsB = getIntervalsB(intervals, slopes, first, aValues); } final double[] second = secondDerivativeCalculator(initialSecond, intervalsA, intervalsB); final double[][] coefs = _solver.solve(yValuesSrt, intervals, slopes, first, second); for (int i = 0; i < nDataPts - 1; ++i) { for (int j = 0; j < 6; ++j) { ArgumentChecker.isFalse(Double.isNaN(coefs[i][j]), "Too large input"); ArgumentChecker.isFalse(Double.isInfinite(coefs[i][j]), "Too large input"); } } return new PiecewisePolynomialResult(new DoubleMatrix1D(xValuesSrt), new DoubleMatrix2D(coefs), 6, 1); }
From source file:com.reactive.hzdfs.utils.Digestor.java
private void updateBytes(ByteBuffer buff) { int i = buff.position(); buff.flip();/*from ww w . j ava 2s . com*/ byte[] b = new byte[i]; buff.get(b); if (byteArray == null) byteArray = b; else { i = byteArray.length; byteArray = Arrays.copyOf(byteArray, i + b.length); System.arraycopy(b, 0, byteArray, i, b.length); } }
From source file:com.qmetry.qaf.automation.step.BaseTestStep.java
@Override public void setActualArgs(Object... args) { if (null != args) { actualArgs = Arrays.copyOf(args, args.length); } }
From source file:gobblin.writer.SimpleDataWriter.java
/** * Write a source record to the staging file * * @param record data record to write/*from ww w. j av a 2 s. c o m*/ * @throws java.io.IOException if there is anything wrong writing the record */ @Override public void write(byte[] record) throws IOException { Preconditions.checkNotNull(record); byte[] toWrite = record; if (this.recordDelimiter.isPresent()) { toWrite = Arrays.copyOf(record, record.length + 1); toWrite[toWrite.length - 1] = this.recordDelimiter.get(); } if (this.prependSize) { long recordSize = toWrite.length; ByteBuffer buf = ByteBuffer.allocate(Longs.BYTES); buf.putLong(recordSize); toWrite = ArrayUtils.addAll(buf.array(), toWrite); } this.stagingFileOutputStream.write(toWrite); this.bytesWritten += toWrite.length; this.recordsWritten++; }
From source file:com.yimidida.shards.utils.ParameterUtil.java
public static Serializable extractPrimaryKey(Object object) { if (object != null) { Class<?> clazz = object.getClass(); Field[] first = clazz.getDeclaredFields(); Field[] second = clazz.getSuperclass().getDeclaredFields(); Field[] fields = Arrays.copyOf(first, first.length + second.length); System.arraycopy(second, 0, fields, first.length, second.length); for (Field field : fields) { field.setAccessible(true);/*from w w w .ja v a 2 s . c o m*/ PrimaryKey primaryKey = field.getAnnotation(PrimaryKey.class); if (primaryKey != null) { try { //0 Object result = field.get(object); if (result != null && "0".equals(result.toString())) { return null; } return (Serializable) result; } catch (Exception e) { e.printStackTrace(); } } } } return null; }