当前位置: 首页>>代码示例>>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;未经允许,请勿转载。