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

The following are Jave code examples for showing how to use addAll() of the org.apache.commons.lang.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: bubichain-sdk-java   File: BlockchainKeyPairFactory.java   View Source Code Vote up 6 votes
/**
 * 根据ED25519算法生成的私钥进行加工,从而得到布比私钥
 * 1.将3字节前缀和1字节版本号0XDA379F01加到P前面,1字节压缩标志添加到P后面即 M=0XDA379F01 + P+0X00
 * 2.将M用SHA256计算两次取前4字节,即Checksum=SHA256(SHA256(M)) 的前4字节
 * 3.将Checksum的前四字节加到M后面,即S=M+Checksum
 * 4.对S进行Base58编码即得到布比私钥。privxxxxxxxxxxxxxxxxxxxxxxxx
 *
 * @param priKey
 * @return
 */
private static String generateBubiPriKey(EdDSAPrivateKey priKey){
    try {
        byte[] priKeyheadArr = Utils.hexToBytes("DA379F01");
        byte[] M = ArrayUtils.addAll(priKeyheadArr, priKey.getSeed());
        byte[] priKeyendArr = Utils.hexToBytes("00");
        M = ArrayUtils.addAll(M, priKeyendArr);
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(M);
        byte[] m_256_1 = md.digest();
        md.update(m_256_1);
        byte[] m_256_2 = md.digest();
        byte[] M_check = new byte[M.length + 4];
        System.arraycopy(M, 0, M_check, 0, M.length);
        System.arraycopy(m_256_2, 0, M_check, M.length, 4);
        return Base58Utils.encode(M_check);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Error occured on generating BubiAddress!--" + e.getMessage(), e);
    }
}
 
Example 2
Project: s3-inventory-usage-examples   File: InventoryManifestRetrieverTest.java   View Source Code Vote up 6 votes
@Test (expected = ChecksumMismatchException.class)
public void getInventoryManifestMD5Mismatch() throws Exception {
    InventoryManifest expectedManifest = manifest();
    byte[] expectedManifestBytes = manifestBytes(expectedManifest);
    byte[] errorBytes = "ERROR".getBytes();
    byte[] wrongManifestBytes = ArrayUtils.addAll(expectedManifestBytes, errorBytes);
    when(mockS3JsonObject.getObjectContent()).thenReturn(new S3ObjectInputStream(
            new ByteArrayInputStream(wrongManifestBytes), null));
    String expectedChecksum = "37289f10a76751046658f6c5e0ab41d9";

    byte[] expectedChecksumBytes = expectedChecksum.getBytes(StandardCharsets.UTF_8);
    when(mockS3ChecksumObject.getObjectContent()).thenReturn(new S3ObjectInputStream(
            new ByteArrayInputStream(expectedChecksumBytes), null));
    when(mockS3Client.getObject(getObjectRequestCaptor.capture())).
            thenReturn(mockS3JsonObject)
            .thenReturn(mockS3ChecksumObject);
    retriever.getInventoryManifest();
}
 
Example 3
Project: ShotgunWSD   File: WordUtils.java   View Source Code Vote up 6 votes
/**
 * Extract from WordNet Database the synsets of a word
 * @param wnDatabase WordNet Database
 * @param word The word that we want to extract its synsets
 * @param synsetType POS Tag of the word
 * @return Array of Synsets
 */
public static Synset[] getSynsetsFromWord(WordNetDatabase wnDatabase, String word, SynsetType synsetType) {
    Synset[] tmpSynsets;

    if(synsetType == null)
        tmpSynsets = wnDatabase.getSynsets(word);
    else {
        tmpSynsets = wnDatabase.getSynsets(word, synsetType);

        // If the synset type is an adjective, check for adjective satellite too
        if (synsetType == SynsetType.ADJECTIVE) {
            tmpSynsets = (Synset[])ArrayUtils.addAll(tmpSynsets, wnDatabase.getSynsets(word, SynsetType.ADJECTIVE_SATELLITE));
        }
    }

    return tmpSynsets;
}
 
Example 4
Project: jpl-framework   File: RankingRegressionTransformerUtils.java   View Source Code Vote up 6 votes
/**
 * It transform one instance of the Object Ranking dataset to {@link BaselearnerDataset} for
 * running regression.
 * 
 * @param objectRankingInstance the object ranking instance to be used for transformation
 * @return the base learner dataset to be used for learning the linear regression function
 */
public static BaselearnerDataset tranformOneInstanceToBaseLearnerRegressionDataset(ObjectRankingInstance objectRankingInstance) {
   Ranking ranking = objectRankingInstance.getRating();
   int numOfObjectsInPartialOrder = ranking.getObjectList().length;
   int numberOfFeatures = objectRankingInstance.getNumofItemFeatures();
   int numberOfContextFeatures = objectRankingInstance.getNumberOfContextsFeatures();
   BaselearnerDataset transformedDataset = new BaselearnerDataset(numOfObjectsInPartialOrder,
         numberOfFeatures + numberOfContextFeatures);
   double rank = 1;
   for (int obj : ranking.getObjectList()) {
      double expectedRank = rank / (numOfObjectsInPartialOrder + 1);
      double[] features = ArrayUtils.addAll(objectRankingInstance.getContextFeatureVector(),
            objectRankingInstance.getFeaturesForItem(obj));

      BaselearnerInstance instance = new BaselearnerInstance(features, expectedRank);
      transformedDataset.addInstance(instance);
      rank++;
   }
   return transformedDataset;
}
 
Example 5
Project: monarch   File: AmpoolMetadata.java   View Source Code Vote up 6 votes
@Override
public List<SchemaTableName> listTables(ConnectorSession connectorSession, String s)
{
    log.info("INFORMATION: AmpoolMetadata listTables() called.");

    if (s == null) {
        return listTables(connectorSession, "ampool");
    }

    String[] fTableNames = ampoolClient.getAdmin().listFTableNames();
    String[] mTableNames = ampoolClient.getAdmin().listMTableNames();
    String[] tableNames = (String[]) ArrayUtils.addAll(fTableNames, mTableNames);
    ImmutableList.Builder<SchemaTableName> tables = ImmutableList.builder();
    for (String n : tableNames)
    {
        tables.add(new SchemaTableName("ampool", n));
    }

    return tables.build();
}
 
Example 6
Project: ditb   File: RWQueueRpcExecutor.java   View Source Code Vote up 5 votes
public RWQueueRpcExecutor(final String name, final int handlerCount, final int numQueues,
    final float readShare, final float scanShare, final int maxQueueLength,
    final Configuration conf, final Abortable abortable,
    final Class<? extends BlockingQueue> readQueueClass, Object... readQueueInitArgs) {
  this(name, calcNumWriters(handlerCount, readShare), calcNumReaders(handlerCount, readShare),
    calcNumWriters(numQueues, readShare), calcNumReaders(numQueues, readShare), scanShare,
    LinkedBlockingQueue.class, new Object[] {maxQueueLength},
    readQueueClass, ArrayUtils.addAll(new Object[] {maxQueueLength}, readQueueInitArgs));
}
 
Example 7
Project: Hydrograph   File: Utils.java   View Source Code Vote up 5 votes
/**
 * 
 * loading the properties files without open jon file
 * @param jobFile job file path
 */
public void loadProperties(IFile jobFile) {
	List<File> paramNameList = null;
	IProject activeProject = jobFile.getProject();
	final File globalparamFilesPath = new File(activeProject.getLocation().toString() + "/" + "globalparam");
	final File localParamFilePath = new File(activeProject.getLocation().toString() + "/" + Constants.PARAM_FOLDER);
	File[] files = (File[]) ArrayUtils.addAll(listFilesForFolder(globalparamFilesPath),
			getJobsPropertyFile(localParamFilePath, jobFile));
	if (files != null) {
		paramNameList = Arrays.asList(files);
		getParamMap(paramNameList, jobFile);
	}
}
 
Example 8
Project: buenojo   File: ResourceHelper.java   View Source Code Vote up 5 votes
public static final String getResourceAddress(boolean isFromGameResourceInput, String... fileResourcePathComponents)
{
	if (isFromGameResourceInput)
	{
		final String[] inputGameResourceArray = {BuenOjoFileUtils.GAME_RESOURCES_INPUT_DIR};
		fileResourcePathComponents = (String[]) ArrayUtils.addAll(inputGameResourceArray, fileResourcePathComponents);
	}	
	return getResourceAddress(fileResourcePathComponents);
}
 
Example 9
Project: athena   File: ONOSLLDP.java   View Source Code Vote up 5 votes
public void setPortId(final int portNumber) {
    byte[] port = ArrayUtils.addAll(new byte[] {PORT_TLV_SUBTYPE},
                                    ByteBuffer.allocate(4).putInt(portNumber).array());

    LLDPTLV portTLV = new LLDPTLV();
    portTLV.setLength(PORT_TLV_SIZE);
    portTLV.setType(PORT_TLV_TYPE);
    portTLV.setValue(port);
    this.setPortId(portTLV);
}
 
Example 10
Project: jpl-framework   File: PairwiseRankingTransformerUtils.java   View Source Code Vote up 5 votes
/**
 * The method to transform the provided {@link ObjectRankingInstance} to classifier
 * {@link BaselearnerDataset}. This function takes one ranking and generate all possible
 * combinations of pair wise preferences. Suppose if x1 is ranked before x2 then it creates an
 * instance with weights (features(x1-x2)) and class as 1. or an instance with weights
 * (features(x2-x1)) and class -1. The output dataset contains balanced classes, i.e. there are
 * the same number of -1 as +1
 * 
 * @param objectRankingInstance the dataset to be transformed
 * @return the transformed base learner dataset
 */
public static BaselearnerDataset transformInstanceToPairswisePreferencesClassifcationDataset(
      ObjectRankingInstance objectRankingInstance) {
   int[] objects = objectRankingInstance.getRating().getObjectList();
   List<Integer> listOfIndexes = CollectionsUtils.createListOfIndexesForProvidedNumber(objects.length);
   List<Integer[]> combination = PermuatorCombinator.getCombinationsnCr(listOfIndexes, 2);
   int numberOfItemFeatures = objectRankingInstance.getNumofItemFeatures();
   int numberOfContextFeatures = objectRankingInstance.getNumberOfContextsFeatures();
   BaselearnerDataset transformedDataset = new BaselearnerDataset(combination.size(), numberOfItemFeatures + numberOfContextFeatures);
   int k = 1;
   double[] contextFeatures = objectRankingInstance.getContextFeatureVector();
   for (Integer[] obj : combination) {

      double[] itemFeaturesForObjectOne = objectRankingInstance.getFeaturesForItem(objects[obj[0]]);
      double[] itemFeaturesForObjectTwo = objectRankingInstance.getFeaturesForItem(objects[obj[1]]);
      DenseDoubleVector featureVector = new DenseDoubleVector(itemFeaturesForObjectOne);
      featureVector.subtractVector(itemFeaturesForObjectTwo);
      double classValue = Math.signum(obj[1] - (double) obj[0]);
      if (Double.compare(classValue, Math.pow(-1, k)) != 0) {
         featureVector.multiplyByConstant(-1);
         classValue = classValue * -1;
      }
      BaselearnerInstance instance = new BaselearnerInstance(ArrayUtils.addAll(contextFeatures, featureVector.asArray()), classValue);
      transformedDataset.addInstance(instance);
      k++;
   }
   return transformedDataset;
}
 
Example 11
Project: jpl-framework   File: PairwiseRankingTransformerUtils.java   View Source Code Vote up 5 votes
/**
 * The method to transform the provided {@link ObjectRankingInstance} to classifier
 * {@link BaselearnerDataset}.A threshold point say t. which is determined by this value t =
 * thresholdPercentage*numberofrankedobjects in an ranking. Then all objects ranked before t are
 * classified as +1 while others as -1.
 * 
 * @param objectRankingInstance the dataset to be transformed
 * @param minimumThresholdRank the minimum threshold rank for which the dataset has to be created
 * @param lambda the lamda value for order-svm for regularizers
 * @return the transformed base learner dataset
 */
public static BaselearnerDataset transformInstanceToOrderedPairwiseClassificationDataset(ObjectRankingInstance objectRankingInstance,
      int minimumThresholdRank, double lambda) {
   int[] objects = objectRankingInstance.getRating().getObjectList();
   int numberOfItemFeatures = objectRankingInstance.getNumofItemFeatures();
   int numberOfContextFeatures = objectRankingInstance.getNumberOfContextsFeatures();
   int totalNumOfObjectFeatures = numberOfItemFeatures + numberOfContextFeatures;
   int numbderOfFeaturesForBaseLearnerDataset = minimumThresholdRank * (totalNumOfObjectFeatures + 1) - 1;
   BaselearnerDataset transformedDataset = new BaselearnerDataset(objects.length * (minimumThresholdRank - 1),
         numbderOfFeaturesForBaseLearnerDataset);
   double[] contextFeatures = objectRankingInstance.getContextFeatureVector();
   double constant = Math.sqrt((lambda * totalNumOfObjectFeatures) / 2);
   for (int thresholdRank = 1; thresholdRank < minimumThresholdRank; thresholdRank++) {
      int rank = 1;
      for (int obj : objects) {
         double classValue = Math.signum((float) thresholdRank - (float) rank);
         if (thresholdRank == rank)
            classValue = 1.0;
         double[] itemFeaturesForObjectOne = objectRankingInstance.getFeaturesForItem(obj);
         double[] feature = ArrayUtils.addAll(contextFeatures, itemFeaturesForObjectOne);
         double[] bias = new double[minimumThresholdRank - 1];
         Arrays.fill(bias, 0.0);
         bias[thresholdRank - 1] = 1;
         double[] vtFeatures = new double[totalNumOfObjectFeatures * (minimumThresholdRank - 1)];
         for (int i = totalNumOfObjectFeatures * (thresholdRank - 1); i < totalNumOfObjectFeatures * thresholdRank; i++) {
            vtFeatures[i] = constant * feature[i - totalNumOfObjectFeatures * (thresholdRank - 1)];
         }
         BaselearnerInstance instance = new BaselearnerInstance(ArrayUtils.addAll(ArrayUtils.addAll(feature, bias), vtFeatures),
               classValue);
         transformedDataset.addInstance(instance);
         rank++;
      }
   }
   return transformedDataset;
}
 
Example 12
Project: SparkSeq   File: Path.java   View Source Code Vote up 5 votes
/**
 * The base sequence for this path. Pull the full sequence for source nodes and then the suffix for all subsequent nodes
 * @return  non-null sequence of bases corresponding to this path
 */
public byte[] getBases() {
    if( getEdges().isEmpty() ) { return graph.getAdditionalSequence(lastVertex); }

    byte[] bases = graph.getAdditionalSequence(graph.getEdgeSource(edgesInOrder.get(0)));
    for( final E e : edgesInOrder ) {
        bases = ArrayUtils.addAll(bases, graph.getAdditionalSequence(graph.getEdgeTarget(e)));
    }
    return bases;
}
 
Example 13
Project: convertigo-engine   File: MySimpleBeanInfo.java   View Source Code Vote up 5 votes
private void checkAdditionalProperties() {
	if (!additionalPropertiesLoaded) {
		checkLocalProperties();
		if (additionalBeanClass != null) {
try {
	properties = (PropertyDescriptor[]) ArrayUtils.addAll(properties, CachedIntrospector
			.getBeanInfo(additionalBeanClass).getPropertyDescriptors());
} catch (IntrospectionException e) {
}
		}
		additionalPropertiesLoaded = true;
	}
}
 
Example 14
Project: rapidminer   File: AggregationOperator.java   View Source Code Vote up 4 votes
@Override
public OperatorVersion[] getIncompatibleVersionChanges() {
	return (OperatorVersion[]) ArrayUtils.addAll(super.getIncompatibleVersionChanges(), new OperatorVersion[] {
			VERSION_5_1_6, VERSION_5_2_8, VERSION_6_0_6 });
}
 
Example 15
Project: MCLibrary   File: Reflections.java   View Source Code Vote up 4 votes
public static Method[] getAllMethods(Class<?> aClass) {
    return (Method[]) ArrayUtils.addAll(aClass.getMethods(), aClass.getDeclaredMethods());
}
 
Example 16
Project: flume-release-1.7.0   File: SourceCounter.java   View Source Code Vote up 4 votes
public SourceCounter(String name, String[] attributes) {
  super(Type.SOURCE, name,
      (String[]) ArrayUtils.addAll(attributes,ATTRIBUTES));
}
 
Example 17
Project: wrdocletbase   File: AbstractDocBuilder.java   View Source Code Vote up 4 votes
protected Tag[] getTagTaglets(MethodDoc methodDoc) {
	return (Tag[]) ArrayUtils.addAll(methodDoc.tags(WRTagTaglet.NAME),
			methodDoc.containingClass().tags(WRTagTaglet.NAME));
}
 
Example 18
Project: convertigo-engine   File: MySimpleBeanInfo.java   View Source Code Vote up 4 votes
private void checkLocalProperties() {
   	if (localProperties == null) {
   		localProperties = new PropertyDescriptor[0];
   		ArrayUtils.addAll(localProperties, properties);
   	}
}
 
Example 19
Project: oneops   File: WorkOrderExecutor.java   View Source Code Vote up 4 votes
private Set<String> syncServiceCookbooks(CmsWorkOrderSimple wo, String woBomCircuit, String user,
    String[] rsyncCmdLineWithKey, String host, String port, String logKey, String keyFile) {
  logger.info("checking for any service cookbook to be rsynched ..");
  //rsync cloud services cookbooks
  String cloudName = wo.getCloud().getCiName();
  Set<String> serviceCookbookPaths = new HashSet<>();
  Map<String, Map<String, CmsCISimple>> services = wo.getServices();
  if (services != null) {
    for (String serviceName : services.keySet()) { // for each service
      CmsCISimple serviceCi = services.get(serviceName).get(cloudName);
      if (serviceCi != null) {
        String serviceClassName = serviceCi.getCiClassName();
        String serviceCookbookCircuit = getCookbookPath(serviceClassName);
        if (!serviceCookbookCircuit.equals(woBomCircuit)) {
          //this service class is not in the same circuit as that of the bom ci getting deployed.
          //Go ahead and include the cookbook of this service to rsync to remote
          String serviceCookbookBaseDir = config.getCircuitDir()
              .replace("packer", serviceCookbookCircuit);
          String serviceClassNameShort = serviceClassName
              .substring(serviceClassName.lastIndexOf(".") + 1);
          String serviceCookbookPath = serviceCookbookBaseDir
              + "/components/cookbooks/" + serviceClassNameShort.toLowerCase() + "/";
          logger.info("service-serviceCookbookPath: " + serviceCookbookPath);
          if (new File(serviceCookbookPath).exists()) {
            String serviceCookbookCircuitPath =
                "/home/" + user + "/" + serviceCookbookCircuit + "/components/cookbooks";
            serviceCookbookPaths.add(serviceCookbookCircuitPath);
            String destination =
                serviceCookbookCircuitPath + "/" + serviceClassNameShort.toLowerCase() + "/";

            String remoteCmd = "mkdir -p " + destination;
            String[] cmd = (String[]) ArrayUtils.addAll(sshCmdLine,
                new String[]{keyFile, "-p " + port, user + "@" + host,
                    remoteCmd});
            logger.info(logKey + " ### EXEC: " + user + "@" + host + " "
                + remoteCmd);
            ProcessResult result = processRunner.executeProcessRetry(
                new ExecutionContext(wo, cmd, getLogKey(wo), getRetryCountForWorkOrder(wo)));
            if (result.getResultCode() != 0) {
              logger.error(logKey + " Error while creating service cookbook directory on remote");
            }

            String[] cmdLine = (String[]) ArrayUtils.addAll(rsyncCmdLineWithKey,
                new String[]{serviceCookbookPath,
                    user + "@" + host + ":" + destination});

            logger.info(logKey + " ### SYNC Service cookbook: " + serviceCookbookPath);

            result = processRunner
                .executeProcessRetry(new ExecutionContext(wo, cmdLine, logKey, retryCount));
            if (result.getResultCode() > 0) {
              wo.setComments("FATAL: " + generateRsyncErrorMessage(result.getResultCode(),
                  host + ":" + port));
              return null;
            }

          } else {
            logger.warn("Cookbook " + serviceCookbookPath + " does not exist on this inductor");
          }
        }
      }
    }
  }
  return serviceCookbookPaths;
}
 
Example 20
Project: flume-release-1.7.0   File: SinkCounter.java   View Source Code Vote up 4 votes
public SinkCounter(String name, String[] attributes) {
  super(MonitoredCounterGroup.Type.SINK, name,
      (String[]) ArrayUtils.addAll(attributes,ATTRIBUTES));
}