本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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"));
}