Java Code Examples for org.apache.commons.lang.ArrayUtils#addAll()

The following examples show how to use org.apache.commons.lang.ArrayUtils#addAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpectralMethods.java    From egads with GNU General Public License v3.0 6 votes vote down vote up
public static RealMatrix createHankelMatrix(RealMatrix data, int windowSize) {

        int n = data.getRowDimension();
        int m = data.getColumnDimension();
        int k = n - windowSize + 1;

        RealMatrix res = MatrixUtils.createRealMatrix(k, m * windowSize);
        double[] buffer = {};

        for (int i = 0; i < n; ++i) {
            double[] row = data.getRow(i);
            buffer = ArrayUtils.addAll(buffer, row);

            if (i >= windowSize - 1) {
                RealMatrix mat = MatrixUtils.createRowRealMatrix(buffer);
                res.setRowMatrix(i - windowSize + 1, mat);
                buffer = ArrayUtils.subarray(buffer, m, buffer.length);
            }
        }

        return res;
    }
 
Example 2
Source File: AbstractSimpleFeatureIngestPlugin.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] toBinary() {
  final byte[] filterBinary = filterOptionProvider.toBinary();
  final byte[] typeNameBinary = typeNameProvider.toBinary();
  final byte[] simpBinary = simpOptionProvider.toBinary();
  final byte[] backingBuffer =
      new byte[filterBinary.length
          + typeNameBinary.length
          + simpBinary.length
          + VarintUtils.unsignedIntByteLength(filterBinary.length)
          + VarintUtils.unsignedIntByteLength(typeNameBinary.length)];
  final ByteBuffer buf = ByteBuffer.wrap(backingBuffer);
  VarintUtils.writeUnsignedInt(filterBinary.length, buf);
  buf.put(filterBinary);
  VarintUtils.writeUnsignedInt(typeNameBinary.length, buf);
  buf.put(typeNameBinary);
  buf.put(simpBinary);

  return ArrayUtils.addAll(serializationFormatOptionProvider.toBinary(), backingBuffer);
}
 
Example 3
Source File: Args.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public Args(String[] args) throws IOException {
    OptionSet optionSetTemp = createOptionParser().parse(args);

    List<?> nonOptionArguments = optionSetTemp.nonOptionArguments();
    if (nonOptionArguments.size() < 1) throw new IllegalArgumentException(INVALID_ARGUMENTS);

    String arg = (String) nonOptionArguments.get(0);

    if (Util.isFile(arg)) {
        String[] newArgs = (String[]) ArrayUtils.addAll(parseArgsFile(arg), Arrays.copyOfRange(args, 1, args.length));
        this.optionSet = createOptionParser().parse(newArgs);
        this.zookeeperQuorum = (String) optionSet.nonOptionArguments().get(0);
    } else {
        this.optionSet = optionSetTemp;
        this.zookeeperQuorum = arg;
    }
}
 
Example 4
Source File: S3ProxyImpl.java    From pravega with Apache License 2.0 6 votes vote down vote up
@Synchronized
@Override
public void putObject(String bucketName, String key, Range range, Object content) {
    byte[] existingBytes = new byte[Math.toIntExact(range.getFirst())];
    try {
        if (range.getFirst() != 0) {
            int bytesRead = client.getObject(bucketName, key).getObject().read(existingBytes, 0,
                    Math.toIntExact(range.getFirst()));
            if (bytesRead != range.getFirst()) {
                throw new S3Exception("InvalidRange", HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE, "InvalidRange", key);
            }
        }
        val contentBytes  = IOUtils.toByteArray((InputStream) content);
        if (contentBytes.length != Math.toIntExact(range.getLast()  - range.getFirst() + 1)) {
            throw new S3Exception("InvalidRange", HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE, "InvalidRange", key);
        }

        val objectAfterPut = ArrayUtils.addAll(existingBytes, contentBytes);
        client.putObject(new PutObjectRequest(bucketName, key, (Object) objectAfterPut));
        aclMap.put(key, aclMap.get(key).withSize(range.getLast() - 1));
    } catch (IOException e) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
    }
}
 
Example 5
Source File: AlarmCondition.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Field[] getAllFields(Class<?> conditionClass) {
  Field[] fields = conditionClass.getDeclaredFields();

  Class<?> superClass = conditionClass.getSuperclass();
  while (superClass != null && superClass != AlarmCondition.class && superClass != Object.class) {
    fields = (Field[]) ArrayUtils.addAll(fields, superClass.getDeclaredFields());
    superClass = superClass.getSuperclass();
  }

  return fields;
}
 
Example 6
Source File: TrajectoryObservation.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
/**
 * Create geometry for featureOfInterest from
 * {@link TimeLocationValueTriple}s
 *
 * @param values
 *            The {@link TimeLocationValueTriple}s to check for
 *            featureOfInterest
 */
private void checkForFeature(List<TimeLocationValueTriple> values) {
    AbstractFeature featureOfInterest = getObservationConstellation().getFeatureOfInterest();
    if (featureOfInterest instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
        Coordinate[] coords = getCoordinates(values);
        int srid = 0;
        if (sf.isSetGeometry()) {
            srid = sf.getGeometry().getSRID();
            coords = (Coordinate[]) ArrayUtils.addAll(sf.getGeometry().getCoordinates(), coords);
        } else {
            TimeLocationValueTriple next = values.iterator().next();
            if (next.isSetLocation()) {
                srid = next.getLocation().getSRID();
            }
        }
        try {
            if (coords.length == 1) {
                Point point = new GeometryFactory().createPoint(coords[0]);
                point.setSRID(srid);
                sf.setGeometry(point);
            } else if (coords.length > 1) {
                LineString lineString = new GeometryFactory().createLineString(coords);
                lineString.setSRID(srid);
                sf.setGeometry(lineString);
            }
        } catch (InvalidSridException e) {
            // TODO
        }
    }
}
 
Example 7
Source File: CraftItemLine.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int[] getEntitiesIDs() {
	if (isSpawned()) {
		if (touchSlime != null) {
			return ArrayUtils.addAll(new int[] {nmsVehicle.getIdNMS(), nmsItem.getIdNMS()}, touchSlime.getEntitiesIDs());
		} else {
			return new int[] {nmsVehicle.getIdNMS(), nmsItem.getIdNMS()};
		}
	} else {
		return new int[0];
	}
}
 
Example 8
Source File: MassJob.java    From RAMPART with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ConanParameter[] getConanParametersAsArray() {
    return (ConanParameter[])ArrayUtils.addAll(super.getConanParametersAsArray(),
            new ConanParameter[]{
                    this.config,
                    this.jobName,
                    this.outputDir,
                    this.jobPrefix
    });
}
 
Example 9
Source File: EstimatorMatrixHistogram.java    From systemds with Apache License 2.0 5 votes vote down vote up
private static MatrixHistogram deriveRbindHistogram(MatrixHistogram h1, MatrixHistogram h2) {
	int[] rNnz = ArrayUtils.addAll(h1.rNnz, h2.rNnz);
	int rMaxNnz = Math.max(h1.rMaxNnz, h2.rMaxNnz);
	int[] cNnz = new int[h1.getCols()];
	int cMaxNnz = 0;
	for(int i=0; i<h1.getCols(); i++) {
		cNnz[i] = h1.cNnz[i] + h2.cNnz[i];
		cMaxNnz = Math.max(cMaxNnz, cNnz[i]);
	}
	return new MatrixHistogram(rNnz, null, cNnz, null, rMaxNnz, cMaxNnz);
}
 
Example 10
Source File: ONOSLLDP.java    From onos with Apache License 2.0 5 votes vote down vote up
public void setPortName(final String portName) {
    byte[] port = ArrayUtils.addAll(new byte[] {PORT_TLV_INTERFACE_NAME_SUBTYPE},
            portName.getBytes(StandardCharsets.UTF_8));

    LLDPTLV portTLV = new LLDPTLV();
    portTLV.setLength((short) port.length);
    portTLV.setType(PORT_TLV_TYPE);
    portTLV.setValue(port);
    this.setPortId(portTLV);
}
 
Example 11
Source File: KeyDerivationFunction.java    From oxAuth with MIT License 5 votes vote down vote up
public static byte[] generateCik(byte[] cmk, BlockEncryptionAlgorithm blockEncryptionAlgorithm)
        throws UnsupportedEncodingException, NoSuchProviderException, NoSuchAlgorithmException, InvalidParameterException {
    if (cmk == null) {
        throw new InvalidParameterException("The content master key (CMK) is null");
    }
    if (blockEncryptionAlgorithm == null) {
        throw new InvalidParameterException("The block encryption algorithm is null");
    }
    if (blockEncryptionAlgorithm != BlockEncryptionAlgorithm.A128CBC_PLUS_HS256
            && blockEncryptionAlgorithm != BlockEncryptionAlgorithm.A256CBC_PLUS_HS512) {
        throw new InvalidParameterException("The block encryption algorithm is not supported");
    }

    byte[] round1 = Base64Util.unsignedToBytes(new int[]{0, 0, 0, 1});
    byte[] outputBitSize = null;
    if (blockEncryptionAlgorithm != BlockEncryptionAlgorithm.A128CBC_PLUS_HS256) {
        outputBitSize = Base64Util.unsignedToBytes(new int[]{0, 0, 1, 0});
    } else { //A256CBC_PLUS_HS512
        outputBitSize = Base64Util.unsignedToBytes(new int[]{0, 0, 2, 0});
    }
    byte[] encValue = blockEncryptionAlgorithm.getName().getBytes(Util.UTF8_STRING_ENCODING);
    byte[] epu = Base64Util.unsignedToBytes(new int[]{0, 0, 0, 0});
    byte[] epv = Base64Util.unsignedToBytes(new int[]{0, 0, 0, 0});
    byte[] label = "Integrity".getBytes(Util.UTF8_STRING_ENCODING);
    byte[] round1Input = ArrayUtils.addAll(round1, cmk);
    round1Input = ArrayUtils.addAll(round1Input, outputBitSize);
    round1Input = ArrayUtils.addAll(round1Input, encValue);
    round1Input = ArrayUtils.addAll(round1Input, epu);
    round1Input = ArrayUtils.addAll(round1Input, epv);
    round1Input = ArrayUtils.addAll(round1Input, label);

    MessageDigest mda = MessageDigest.getInstance(blockEncryptionAlgorithm.getMessageDiggestAlgorithm(), "BC");
    byte[] cik = mda.digest(round1Input);

    return cik;
}
 
Example 12
Source File: EstimatorMatrixHistogram.java    From systemds with Apache License 2.0 5 votes vote down vote up
private static MatrixHistogram deriveCbindHistogram(MatrixHistogram h1, MatrixHistogram h2) {
	int[] rNnz = new int[h1.getRows()];
	int rMaxNnz = 0;
	for(int i=0; i<h1.getRows(); i++) {
		rNnz[i] = h1.rNnz[i] + h2.rNnz[i];
		rMaxNnz = Math.max(rMaxNnz, rNnz[i]);
	}
	int[] cNnz = ArrayUtils.addAll(h1.cNnz, h2.cNnz);
	int cMaxNnz = Math.max(h1.cMaxNnz, h2.cMaxNnz);
	return new MatrixHistogram(rNnz, null, cNnz, null, rMaxNnz, cMaxNnz);
}
 
Example 13
Source File: TestConfiguration.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized void initAsTestConfiguration(final String... additionalContextFiles)
{
  System.setProperty("base.dir", new File("./tmp").getAbsoluteFile().toString());
  ConfigXmlTest.createTestConfiguration();
  final String[] contextFiles;
  if (additionalContextFiles != null && additionalContextFiles.length > 0) {
    contextFiles = (String[]) ArrayUtils.addAll(TEST_CONTEXT_FILES, additionalContextFiles);
  } else {
    contextFiles = TEST_CONTEXT_FILES;
  }
  init(contextFiles);
}
 
Example 14
Source File: BootstrappingOperator.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public OperatorVersion[] getIncompatibleVersionChanges() {
	return (OperatorVersion[]) ArrayUtils.addAll(super.getIncompatibleVersionChanges(),
			new OperatorVersion[] { VERSION_6_4_0 });
}
 
Example 15
Source File: HashBasedUuidGenStrategy.java    From ambari-metrics with Apache License 2.0 4 votes vote down vote up
/**
 * Computes the UUID for a timelineClusterMetric.
 * @param timelineClusterMetric
 * @param maxLength
 * @return byte array of length 'maxlength'
 */
@Override
public byte[] computeUuid(TimelineClusterMetric timelineClusterMetric, int maxLength) {

  int metricNameUuidLength = 12;
  String instanceId = timelineClusterMetric.getInstanceId();

  if ((StringUtils.isEmpty(instanceId))) {
    metricNameUuidLength = 14;
  }

  String metricName = timelineClusterMetric.getMetricName();

  //Compute the individual splits.
  String[] splits = getIndidivualSplits(metricName);

  /*
  Compute the weighted ascii sum of every split in the metric name. (asciiSum += (int) splits[s].charAt(i))
  These weighted sums are 'appended' to get the unique ID for metric name.
   */
  StringBuilder splitSums = new StringBuilder();
  long totalAsciiSum = 0l;
  if (splits.length > 0) {
    for (String split : splits) {
      int asciiSum = 0;
      for (int i = 0; i < split.length(); i++) {
        asciiSum += ((i + 1) * (int) split.charAt(i)); //weighted sum for split.
      }
      splitSums.append(asciiSum); //Append the sum to the array of sums.
      totalAsciiSum += asciiSum; //Parity Sum
    }
  }

  String splitSumString = totalAsciiSum + splitSums.reverse().toString(); //Reverse and attach parity sum.
  int splitLength = splitSumString.length();

  //Compute a unique metric seed for the stemmed metric name
  String stemmedMetric = stem(metricName);
  long metricSeed = 100123456789L;
  metricSeed += computeWeightedNumericalAsciiSum(stemmedMetric);
  //Reverse the computed seed to get a metric UUID portion which is used optionally.
  byte[] metricSeedBytes = StringUtils.reverse(String.valueOf(metricSeed)).getBytes();

  int seedLength = (int)(0.25 * metricNameUuidLength);
  int sumLength = metricNameUuidLength - seedLength;
  if (splitLength < sumLength) {
    sumLength = splitLength;
    seedLength = metricNameUuidLength - sumLength;
  }

  byte[] metricUuidPortion = ArrayUtils.addAll(
    ArrayUtils.subarray(splitSumString.getBytes(), 0, sumLength)
    , ArrayUtils.subarray(metricSeedBytes, 0, seedLength));

  /*
    For appId and instanceId the logic is similar. Use a seed integer to start with and compute ascii sum.
    Based on required length, use a suffix of the computed uuid.
   */
  String appId = timelineClusterMetric.getAppId();
  int appidSeed = 11;
  for (int i = 0; i < appId.length(); i++) {
    appidSeed += appId.charAt(i);
  }
  String appIdSeedStr = String.valueOf(appidSeed);
  byte[] appUuidPortion = ArrayUtils.subarray(appIdSeedStr.getBytes(), appIdSeedStr.length() - 2, appIdSeedStr.length());

  if (StringUtils.isNotEmpty(instanceId)) {
    byte[] instanceUuidPortion = new byte[2];
    ByteBuffer buffer = ByteBuffer.allocate(4);
    int instanceIdSeed = 1489;
    for (int i = 0; i < appId.length(); i++) {
      instanceIdSeed += ((i+1) * appId.charAt(i));
    }
    buffer.putInt(instanceIdSeed);
    ArrayUtils.subarray(buffer.array(), 2, 4);
    // Concatenate all UUIDs together (metric uuid + appId uuid + instanceId uuid)
    return ArrayUtils.addAll(ArrayUtils.addAll(metricUuidPortion, appUuidPortion), instanceUuidPortion);
  }

  return ArrayUtils.addAll(metricUuidPortion, appUuidPortion);
}
 
Example 16
Source File: AlgorithmMSVM.java    From systemds with Apache License 2.0 4 votes vote down vote up
private void runMSVMTest( String testname, boolean rewrites, boolean sparse, boolean lineage, int numClasses, ExecType instType, CodegenTestType CodegenTestType)
{
	boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
	ExecMode platformOld = rtplatform;
	switch( instType ){
		case SPARK: rtplatform = ExecMode.SPARK; break;
		default: rtplatform = ExecMode.HYBRID; break;
	}
	currentTestType = CodegenTestType;
	boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
	if( rtplatform == ExecMode.SPARK || rtplatform == ExecMode.HYBRID )
		DMLScript.USE_LOCAL_SPARK_CONFIG = true;

	try
	{
		String TEST_NAME = testname;
		TestConfiguration config = getTestConfiguration(TEST_NAME);
		loadTestConfiguration(config);
		
		fullDMLScriptName = "scripts/algorithms/m-svm.dml";
		programArgs = new String[]{ "-stats", "-nvargs", "X="+input("X"), "Y="+input("Y"),
				"icpt="+String.valueOf(intercept), "tol="+String.valueOf(epsilon), "reg=0.001",
				"maxiter="+String.valueOf(maxiter), "model="+output("w"), "Log= "};
		if( lineage )
			programArgs = (String[])ArrayUtils.addAll(new String[]{"-lineage"}, programArgs);
		
		rCmd = getRCmd(inputDir(), String.valueOf(intercept),String.valueOf(epsilon),
			String.valueOf(maxiter), expectedDir());

		OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrites;
		
		//generate actual datasets
		double[][] X = getRandomMatrix(rows, cols, 0, 1, sparse?sparsity2:sparsity1, 714);
		writeInputMatrixWithMTD("X", X, true);
		double[][] y = TestUtils.round(getRandomMatrix(rows, 1, 1, numClasses, 1.0, 136));
		writeInputMatrixWithMTD("Y", y, true);
		
		runTest(true, false, null, -1); 
		runRScript(true); 
		
		//compare matrices 
		HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("w");
		HashMap<CellIndex, Double> rfile  = readRMatrixFromFS("w");
		TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
		Assert.assertTrue(heavyHittersContainsSubString("spoof") || heavyHittersContainsSubString("sp_spoof"));
	}
	finally {
		rtplatform = platformOld;
		DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
		OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
		OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
		OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
	}
}
 
Example 17
Source File: AlgorithmMSVM.java    From systemds with Apache License 2.0 4 votes vote down vote up
private void runMSVMTest( String testname, boolean rewrites, boolean sparse, boolean lineage, int numClasses, ExecType instType, TestType testType)
{
	boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
	ExecMode platformOld = rtplatform;
	switch( instType ){
		case SPARK: rtplatform = ExecMode.SPARK; break;
		default: rtplatform = ExecMode.HYBRID; break;
	}
	currentTestType = testType;
	boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
	if( rtplatform == ExecMode.SPARK || rtplatform == ExecMode.HYBRID )
		DMLScript.USE_LOCAL_SPARK_CONFIG = true;

	try
	{
		String TEST_NAME = testname;
		TestConfiguration config = getTestConfiguration(TEST_NAME);
		loadTestConfiguration(config);
		
		fullDMLScriptName = "scripts/algorithms/m-svm.dml";
		programArgs = new String[]{ "-stats", "-nvargs", "X="+input("X"), "Y="+input("Y"),
				"icpt="+String.valueOf(intercept), "tol="+String.valueOf(epsilon), "reg=0.001",
				"maxiter="+String.valueOf(maxiter), "model="+output("w"), "Log= "};
		if( lineage )
			programArgs = (String[])ArrayUtils.addAll(new String[]{"-lineage"}, programArgs);
		
		rCmd = getRCmd(inputDir(), String.valueOf(intercept),String.valueOf(epsilon),
			String.valueOf(maxiter), expectedDir());

		OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrites;
		
		//generate actual datasets
		double[][] X = getRandomMatrix(rows, cols, 0, 1, sparse?sparsity2:sparsity1, 714);
		writeInputMatrixWithMTD("X", X, true);
		double[][] y = TestUtils.round(getRandomMatrix(rows, 1, 1, numClasses, 1.0, 136));
		writeInputMatrixWithMTD("Y", y, true);
		
		runTest(true, false, null, -1); 
		runRScript(true); 
		
		//compare matrices 
		HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("w");
		HashMap<CellIndex, Double> rfile  = readRMatrixFromFS("w");
		TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
		Assert.assertTrue(heavyHittersContainsSubString("spoof") || heavyHittersContainsSubString("sp_spoof"));
	}
	finally {
		rtplatform = platformOld;
		DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
		OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
		OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
		OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
	}
}
 
Example 18
Source File: PercentileFilter.java    From usergrid with Apache License 2.0 3 votes vote down vote up
private static double[] toArray(Map<String, Collection<Value>> map) {

        double arr[] = {};

        for (Collection<Value> valueList : map.values()) {
            arr = ArrayUtils.addAll(arr, toArray(valueList));
        }

        return arr;
    }
 
Example 19
Source File: FrameObject.java    From systemds with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new collection which contains the schema of the current
 * frame object concatenated with the schema of the passed frame object.
 * 
 * @param fo frame object
 * @return schema of value types
 */
public ValueType[] mergeSchemas(FrameObject fo) {
	return (ValueType[]) ArrayUtils.addAll(
		(_schema!=null) ? _schema : UtilFunctions.nCopies((int)getNumColumns(), ValueType.STRING), 
		(fo._schema!=null) ? fo._schema : UtilFunctions.nCopies((int)fo.getNumColumns(), ValueType.STRING));
}
 
Example 20
Source File: ControlObjectCommand.java    From openhab1-addons with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Creates new command class instance for specified type of control.
 *
 * @param controlType
 *            type of controlled objects
 * @param objects
 *            bits that represents objects to control
 * @param userCode
 *            code of the user on behalf the control is made
 */
public ControlObjectCommand(ControlType controlType, byte[] objects, String userCode) {
    super(controlType.getControlCommand(), ArrayUtils.addAll(userCodeToBytes(userCode), objects));
    this.controlType = controlType;
}