List of usage examples for java.util Arrays fill
public static void fill(Object[] a, Object val)
From source file:com.antsdb.saltedfish.sql.vdm.KeyUtil.java
public static void add(byte[] bytes, byte n) { int overflow = 0; for (int i = bytes.length - 1; i >= 0; i--) { int v = (bytes[i] & 0xff) + n + overflow; bytes[i] = (byte) v; overflow = v >>> 8;/*from w ww . j a v a 2 s . c o m*/ if (overflow == 0) { break; } n = 0; } if (overflow > 0) { Arrays.fill(bytes, (byte) 0xff); } else if (overflow < 0) { Arrays.fill(bytes, (byte) 0); } }
From source file:es.udc.gii.common.eaf.benchmark.real_param.ShekelFamilyObjectiveFunction.java
@Override public double[][] getOptimum(int dim) { double[][] optimums = new double[1][]; double[] optimum = new double[4]; Arrays.fill(optimum, 4.0 / 5.0 - 1.0); optimums[0] = optimum;//from ww w . j a va 2s . c o m return optimums; }
From source file:gda.analysis.numerical.straightline.StraightLineFit.java
public static Results fitInt(List<Object> data, long[] dims, double[] x) { Object object = data.get(0);/*from w w w . j a v a2s.c om*/ if (!object.getClass().isArray()) { throw new IllegalArgumentException("fitInt can only accept arrays"); } int numLines = ArrayUtils.getLength(object); int pointsPerLine = x.length; if (data.size() != pointsPerLine) throw new IllegalArgumentException("data.size() != pointsPerLine"); for (int i = 0; i < pointsPerLine; i++) { if (ArrayUtils.getLength(data.get(i)) != numLines) throw new IllegalArgumentException("data.get(i).length != numLines"); } double[] slopes = new double[numLines]; double[] offsets = new double[numLines]; short[] fitoks = new short[numLines]; Arrays.fill(fitoks, (short) 0); if (pointsPerLine > 2) { double xAverage = getXAverage(x); double x1 = getX(x, xAverage); double[] y = new double[pointsPerLine]; Arrays.fill(fitoks, (short) 1); for (int line = 0; line < numLines; line++) { for (int point = 0; point < pointsPerLine; point++) { y[point] = Array.getDouble(data.get(point), line); } Result fit2 = fit2(y, x, xAverage, x1); slopes[line] = fit2.getSlope(); offsets[line] = fit2.getOffset(); } } else if (pointsPerLine == 2) { double[] y = new double[pointsPerLine]; Arrays.fill(fitoks, (short) 1); for (int line = 0; line < numLines; line++) { for (int point = 0; point < pointsPerLine; point++) { y[point] = Array.getDouble(data.get(point), line); } slopes[line] = (y[1] - y[0]) / (x[1] - x[0]); offsets[line] = y[1] - slopes[line] * x[1]; } } return new Results(offsets, slopes, dims, fitoks); }
From source file:com.bconomy.autobit.Encryption.java
private static byte[] charsToBytes(char[] chars) { CharBuffer charBuffer = CharBuffer.wrap(chars); ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer); byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data Arrays.fill(chars, '\u0000'); // clear sensitive data return bytes; }
From source file:net.myrrix.common.collection.FastByIDMap.java
/** * Creates a new whose capacity can accommodate the given number of entries without * rehash.//from w w w .j a v a 2s . c o m * * @param size desired capacity * @throws IllegalArgumentException if size is less than 0, maxSize is less than 1 * or at least half of {@link RandomUtils#MAX_INT_SMALLER_TWIN_PRIME}, or * loadFactor is less than 1 */ public FastByIDMap(int size) { Preconditions.checkArgument(size >= 0, "size must be at least 0"); Preconditions.checkArgument(size < MAX_SIZE, "size must be less than " + MAX_SIZE); int hashSize = RandomUtils.nextTwinPrime((int) (DEFAULT_LOAD_FACTOR * size) + 1); keys = new long[hashSize]; Arrays.fill(keys, NULL); @SuppressWarnings("unchecked") V[] theValues = (V[]) new Object[hashSize]; values = theValues; }
From source file:com.cloudera.oryx.common.collection.LongSet.java
/** * Creates a new {@code LongSet} with the given initial capacity. * * @param initialCapacity initial capacity of set *//*from w w w . j a v a 2 s . com*/ public LongSet(int initialCapacity) { Preconditions.checkArgument(initialCapacity >= 0, "initialCapacity must be at least 0"); Preconditions.checkArgument(initialCapacity < MAX_SIZE, "initialCapacity must be less than %d", MAX_SIZE); int hashSize = RandomUtils.nextTwinPrime((int) (LOAD_FACTOR * initialCapacity) + 1); keys = new long[hashSize]; Arrays.fill(keys, NULL); }
From source file:net.femtoparsec.jnlmin.GradientEvaluator.java
/** * Evaluate the model and compute its gradient. If the model cannot compute its gradient, an approximation is obtained with forward differences. * If the model can compute its gradient, this call is equivalent to : * * <pre>/*w w w. j a va 2s. c o m*/ * model.evaluate(parameter, true, resultBuffer) * return 1 * </pre> * @param parameters the parameters at which the model must be evaluated. * @param resultBuffer the result buffer that will contain the value and the gradient of the model at the given parameters. * @param computationBuffer a buffer used for computation. * @return the number of times the model has been evaluated */ public int evaluateWithGradient(double[] parameters, ModelResult resultBuffer, ModelResult computationBuffer) { int nbEvaluations; if (model.hasDerivative()) { model.evaluate(parameters, true, resultBuffer); nbEvaluations = 1; } else { model.evaluate(parameters, false, resultBuffer); final double[] gradient = resultBuffer.getGradient(); Arrays.fill(gradient, 0); double increment, backup; double invIncrement; int subIndex; for (int i = 0; i < nbFitted; i++) { subIndex = indexes[i]; backup = parameters[subIndex]; increment = this.epsilon * Math.abs(backup); if (increment <= 0) { increment = this.epsilon; } invIncrement = 1. / increment; parameters[subIndex] += increment; model.evaluate(parameters, false, computationBuffer); parameters[subIndex] = backup; gradient[subIndex] = (computationBuffer.getValue() - resultBuffer.getValue()) * invIncrement; } nbEvaluations = 1 + nbFitted; } return nbEvaluations; }
From source file:bookkeepr.xmlable.DatabaseManager.java
public DatabaseManager() { Arrays.fill(nextId, 0x1L); for (int i = 0; i < latestIds.length; i++) { Arrays.fill(latestIds[i], 0x0L); }/* www.j av a 2 s. co m*/ for (int i = 0; i < listeners.length; i++) { listeners[i] = new ArrayList(); } }
From source file:com.qtplaf.library.trading.data.indicators.GaussianSmoother.java
/** * Calculates the indicator data at the given index, for the list of indicator sources. * <p>//from w w w. ja v a 2 s. c o m * This indicator already calculated data is passed as a parameter because some indicators may need previous * calculated values or use them to improve calculation performance. * * @param index The data index. * @param indicatorSources The list of indicator sources. * @param indicatorData This indicator already calculated data. * @return The result data. */ @Override public Data calculate(int index, List<IndicatorSource> indicatorSources, DataList indicatorData) { // If index < 0 do nothing. if (index < 0) { return null; } // The unique data list and the index of the data. int period = getIndicatorInfo().getParameter("PERIOD").getValue().getInteger(); // If index < period, calculate the mean from scratch. if (index < period) { return getSource(index, indicatorSources); } // The Gaussian curve fitter and the Gaussian function. GaussianCurveFitter fitter = GaussianCurveFitter.create(); Gaussian.Parametric function = new Gaussian.Parametric(); // For every indicator source, build the list of observation points. int numIndexes = getNumIndexes(); double[] values = new double[numIndexes]; Arrays.fill(values, 0); int valueIndex = 0; for (IndicatorSource source : indicatorSources) { DataList dataList = source.getDataList(); List<Integer> indexes = source.getIndexes(); for (Integer dataIndex : indexes) { // The list of observations. WeightedObservedPoints obs = new WeightedObservedPoints(); int startIndex = index - period + 1; int endIndex = index; int x = 0; for (int i = startIndex; i <= endIndex; i++) { double y = dataList.get(i).getValue(dataIndex); obs.add(x, y); x++; } // Reduce last x to get the last coordinate applied. x--; // The parameters to apply to the function. double[] params = fitter.fit(obs.toList()); // The value. values[valueIndex] = function.value(x, params); valueIndex++; } } Data data = new Data(); data.setData(values); data.setTime(indicatorSources.get(0).getDataList().get(index).getTime()); return data; }
From source file:bide.core.par.TunePar.java
private void setType(String type) { int typeIndex = -1; if (type.equalsIgnoreCase("normal")) { typeIndex = 0;//ww w.j av a 2s. c o m } else if (type.equalsIgnoreCase("normalbig")) { typeIndex = 1; } else if (type.equalsIgnoreCase("scale")) { typeIndex = 2; } tuneType = new int[noTunePar]; Arrays.fill(tuneType, typeIndex); }