當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayUtils.add方法代碼示例

本文整理匯總了Java中org.apache.commons.lang.ArrayUtils.add方法的典型用法代碼示例。如果您正苦於以下問題:Java ArrayUtils.add方法的具體用法?Java ArrayUtils.add怎麽用?Java ArrayUtils.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang.ArrayUtils的用法示例。


在下文中一共展示了ArrayUtils.add方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pickRandomFromArray

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * picks randomly non-repeating some elements from a source array and not in
 * another array. For example, pickRandomFromArray(new int[] {1,2,3,4,5,6},
 * new int[] {2,6}, 2) returns {1,5}.
 * 
 * @param srcArray
 *            the source array where elements will be picked from.
 * @param excludedArray
 *            the array containing elements that must not be picked.
 * @param nPick
 *            number of array to be picked.
 * @sRandom a random object generating controlled random numbers.
 * @return a subset of the source array that have no elements as specified
 *         in the excludedArray.
 */
public static int[] pickRandomFromArray(int[] srcArray, int[] excludedArray,
		int nPick, Random sRandom) {
	if (nPick <= 0 || srcArray == null || srcArray.length == 0) {
		return null;
       }
	int[] excluded = excludedArray;
	int[] finArr = new int[nPick];
	int[] remained = getNonCommonInArrays(srcArray,excluded);
	if (remained.length < nPick) {
		finArr = null;
       } else {
		for (int i = 0; i <= nPick - 1; i++) {
			if (remained.length == 1) {
				finArr[i] = remained[0];
               } else {
				//finArr[i] = remained[sRandom.nextInt(remained.length - 1)];
               	finArr[i] = remained[sRandom.nextInt(remained.length)];
               }
			excluded = ArrayUtils.add(excluded, finArr[i]);
			remained = getNonCommonInArrays(srcArray, excluded);
		}
	}
	return finArr;
}
 
開發者ID:smart-facility,項目名稱:calendar-based-microsim,代碼行數:40,代碼來源:ArrayHandler.java

示例2: getNonCommonInArrays

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * returns values in an array (source array) that are not in another array
 * (comparing array). For example getNonCommonInArrays(new int[]
 * {1,2,3,6,8}, new String[] {3,7,2}) returns {1,6,8}.
 * 
 * @param array1
 *            source array.
 * @param array2
 *            comparing array.
 * @return values in source array that are not in comparing array.
 */
public static int[] getNonCommonInArrays(int[] array1, int[] array2) {
	int[] nonCommon = null;

	if (array2 == null) {
		return array1;
       }
	if (array1 == null) {
		return null;
       }

	for (int i1 = 0; i1 <= array1.length - 1; i1++) {
		boolean common = false;
		for (int i2 = 0; i2 <= array2.length - 1; i2++) {
			if (array1[i1] == array2[i2]) {
				common = true;
				break;
			}
           }
		if (!common) {
			nonCommon = ArrayUtils.add(nonCommon, array1[i1]);
           }
	}

	return nonCommon;
}
 
開發者ID:smart-facility,項目名稱:calendar-based-microsim,代碼行數:37,代碼來源:ArrayHandler.java

示例3: removeValueInArray

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * removes elements equal to a specified value from an original array.
 * 
 * @param tmparray
 *            the original integer array.
 * @param remVal
 *            the value to be removed.
 * @return subset of the original array (with out elements equal to the
 *         specified value)
 */
public static int[] removeValueInArray(int[] tmparray, int remVal) {
	int[] finarray = null;
	if (tmparray == null) {
		return finarray;
       }
	int[] idxVal = null;
	for (int i = 0; i < tmparray.length; i++) {
		if (tmparray[i] == remVal) {
			idxVal = ArrayUtils.add(idxVal, i);
           }
       }
	if (idxVal == null) {
		return tmparray;
       }
	int[] idxRemain = null;
	for (int i = 0; i < tmparray.length; i++) {
		if (ArrayUtils.indexOf(idxVal, i) == -1) {
			idxRemain = ArrayUtils.add(idxRemain, i);
           }
       }

	if (idxRemain == null) {
		return finarray;
       }

	finarray = extractArray(tmparray, idxRemain);

	return finarray;
}
 
開發者ID:smart-facility,項目名稱:calendar-based-microsim,代碼行數:40,代碼來源:ArrayHandler.java

示例4: addCcy_

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * Adds the cached currency to the array
 */
private void addCcy_() {
    CcyPair pair = configToAdd.pair;
    for (CcyConfig ccyConfig : configArray) {
        if (pair == ccyConfig.pair) {
            ccyConfig.bias = configToAdd.bias;
            ccyConfig.delayMircos = configToAdd.delayMircos;
            ccyConfig.orderRate = configToAdd.orderRate;
            ccyConfig.rejectRate = configToAdd.rejectRate;
            return;
        }
    }
    configArray = (CcyConfig[]) ArrayUtils.add(configArray, configToAdd);
}
 
開發者ID:v12technology,項目名稱:fluxtion-examples,代碼行數:17,代碼來源:PriceOrderGenerator.java

示例5: createMergedVariantContext

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
protected VariantContext createMergedVariantContext( final VariantContext thisVC, final VariantContext nextVC, final byte[] ref, final GenomeLoc refLoc ) {
    final int thisStart = thisVC.getStart();
    final int nextStart = nextVC.getStart();
    byte[] refBases = new byte[]{};
    byte[] altBases = new byte[]{};
    refBases = ArrayUtils.addAll(refBases, thisVC.getReference().getBases());
    altBases = ArrayUtils.addAll(altBases, thisVC.getAlternateAllele(0).getBases());
    int locus;
    for( locus = thisStart + refBases.length; locus < nextStart; locus++ ) {
        final byte refByte = ref[locus - refLoc.getStart()];
        refBases = ArrayUtils.add(refBases, refByte);
        altBases = ArrayUtils.add(altBases, refByte);
    }
    refBases = ArrayUtils.addAll(refBases, ArrayUtils.subarray(nextVC.getReference().getBases(), locus > nextStart ? 1 : 0, nextVC.getReference().getBases().length)); // special case of deletion including the padding base of consecutive indel
    altBases = ArrayUtils.addAll(altBases, nextVC.getAlternateAllele(0).getBases());

    int iii = 0;
    if( refBases.length == altBases.length ) { // insertion + deletion of same length creates an MNP --> trim common prefix bases off the beginning of the allele
        while( iii < refBases.length && refBases[iii] == altBases[iii] ) { iii++; }
        if ( iii == refBases.length ) {
            // we've become a null allele, such as with CA/C + A/AA -> CA/CA => after trimming there's nothing left
            // so return a null variant context so we can eliminate the variants from consideration
            return null;
        }
    }


    final Allele refAllele = Allele.create( ArrayUtils.subarray(refBases, iii, refBases.length), true );
    final Allele altAllele =  Allele.create( ArrayUtils.subarray(altBases, iii, altBases.length), false );
    return new VariantContextBuilder("merged", thisVC.getChr(), thisVC.getStart() + iii, nextVC.getEnd(), Arrays.asList(refAllele, altAllele)).make();
}
 
開發者ID:PAA-NCIC,項目名稱:SparkSeq,代碼行數:32,代碼來源:LDMerger.java

示例6: prepareArguments

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
private String[] prepareArguments(Path harPath, Path[] fileList, String replication) {
    Object[] args = new String[]{"-archiveName", harPath.getName(), "-p", "/", "-r", replication};
    for (Path path : fileList) {
        args = ArrayUtils.add(args, makeRelativeToRoot(path.toString()));
    }
    args = ArrayUtils.add(args, new String(harPath.getParent().toString() + "/"));
    return (String[]) args;
}
 
開發者ID:trenner,項目名稱:ahar,代碼行數:9,代碼來源:ArchiveManager.java

示例7: getConfigLocations

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
private String[] getConfigLocations()
{
    String[] defaultLocations = ApplicationContextHelper.CONFIG_LOCATIONS;
    Object[] locations = ArrayUtils.add(defaultLocations, ACTIVITI_CONTEXT);
    return (String[]) locations;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:7,代碼來源:ActivitiSpringTest.java

示例8: testUpdateCollectionMediaItems

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
public void testUpdateCollectionMediaItems() {
    MediaCollection coll;
    List<MediaItem> items;
    String[] kalturaIds;

    // SUPER ADMIN
    external.currentUserId = KalturaAPIServiceStub.ADMIN_USER_ID;

    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertNotNull(coll);
    assertTrue(coll.isAddItems());
    items = coll.getItems();
    assertEquals(5, items.size());
    kalturaIds = coll.getKalturaIds().toArray(new String[items.size()]);
    service.updateCollectionMediaItems(coll.getId(), kalturaIds);
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertEquals(5, coll.getItems().size()); // no change in size

    // test adding one
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertNotNull(coll);
    assertTrue(coll.isAddItems());
    items = coll.getItems();
    assertEquals(5, items.size());
    kalturaIds = coll.getKalturaIds().toArray(new String[items.size()]);
    kalturaIds = (String[]) ArrayUtils.add(kalturaIds, "kid7");
    service.updateCollectionMediaItems(coll.getId(), kalturaIds);
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertEquals(6, coll.getItems().size()); // +1 size
    assertTrue(coll.getKalturaIds().contains("kid7"));

    // test removing one
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertNotNull(coll);
    assertTrue(coll.isAddItems());
    items = coll.getItems();
    assertEquals(6, items.size());
    kalturaIds = coll.getKalturaIds().toArray(new String[items.size()]);
    kalturaIds = (String[]) ArrayUtils.removeElement(kalturaIds, "kid7");
    service.updateCollectionMediaItems(coll.getId(), kalturaIds);
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertEquals(5, coll.getItems().size()); // -1 size
    assertFalse(coll.getKalturaIds().contains("kid7"));

    // testing adding and removing
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertNotNull(coll);
    assertTrue(coll.isAddItems());
    items = coll.getItems();
    assertEquals(5, items.size());
    kalturaIds = coll.getKalturaIds().toArray(new String[items.size()]);
    kalturaIds = (String[]) ArrayUtils.removeElement(kalturaIds, "kid5");
    kalturaIds = (String[]) ArrayUtils.add(kalturaIds, "kidA");
    kalturaIds = (String[]) ArrayUtils.add(kalturaIds, "kidB");
    service.updateCollectionMediaItems(coll.getId(), kalturaIds);
    coll = service.getCollection(kalturaAPIService.mcAd.getIdStr(), 0, -1);
    assertEquals(6, coll.getItems().size()); // -1 +2 size
    assertFalse(coll.getKalturaIds().contains("kid5"));
    assertTrue(coll.getKalturaIds().contains("kidA"));
    assertTrue(coll.getKalturaIds().contains("kidB"));
}
 
開發者ID:ITYug,項目名稱:kaltura-ce-sakai-extension,代碼行數:62,代碼來源:MediaServiceTest.java


注:本文中的org.apache.commons.lang.ArrayUtils.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。