HBASE-12062 Fix usage of Collections.toArray
This commit is contained in:
parent
11e612c28c
commit
7e6cb56e4c
@ -235,7 +235,7 @@ public class ServerLoad {
|
||||
for (Coprocessor coprocessor : obtainServerLoadPB().getCoprocessorsList()) {
|
||||
coprocessSet.add(coprocessor.getName());
|
||||
}
|
||||
return coprocessSet.toArray(new String[0]);
|
||||
return coprocessSet.toArray(new String[coprocessSet.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,9 +35,7 @@ public class Authorizations {
|
||||
private List<String> labels;
|
||||
public Authorizations(String... labels) {
|
||||
this.labels = new ArrayList<String>(labels.length);
|
||||
for (String label : labels) {
|
||||
this.labels.add(label);
|
||||
}
|
||||
Collections.addAll(this.labels, labels);
|
||||
}
|
||||
|
||||
public Authorizations(List<String> labels) {
|
||||
|
@ -20,6 +20,7 @@ package org.apache.hadoop.hbase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -228,9 +229,7 @@ public class TestKeyValue extends TestCase {
|
||||
new KeyValue(Bytes.toBytes("a,a,0"), fam, qf, 0, nb),
|
||||
};
|
||||
// Add to set with bad comparator
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
set.add(keys[i]);
|
||||
}
|
||||
Collections.addAll(set, keys);
|
||||
// This will output the keys incorrectly.
|
||||
boolean assertion = false;
|
||||
int count = 0;
|
||||
@ -245,9 +244,7 @@ public class TestKeyValue extends TestCase {
|
||||
assertTrue(assertion);
|
||||
// Make set with good comparator
|
||||
set = new TreeSet<KeyValue>(new KeyValue.MetaComparator());
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
set.add(keys[i]);
|
||||
}
|
||||
Collections.addAll(set, keys);
|
||||
count = 0;
|
||||
for (KeyValue k: set) {
|
||||
assertTrue(count++ == k.getTimestamp());
|
||||
|
@ -118,7 +118,7 @@ public class TestConcatenatedLists {
|
||||
assertEquals((last == -1), c.isEmpty());
|
||||
assertEquals(last + 1, c.size());
|
||||
assertTrue(c.containsAll(c));
|
||||
Long[] array = c.toArray(new Long[0]);
|
||||
Long[] array = c.toArray(new Long[c.size()]);
|
||||
List<Long> all = new ArrayList<Long>();
|
||||
Iterator<Long> iter = c.iterator();
|
||||
for (Long i = 0L; i <= last; ++i) {
|
||||
|
@ -124,9 +124,7 @@ public class IndexBuilder {
|
||||
conf.set("index.tablename", tableName);
|
||||
conf.set("index.familyname", columnFamily);
|
||||
String[] fields = new String[args.length - 2];
|
||||
for(int i = 0; i < fields.length; i++) {
|
||||
fields[i] = args[i + 2];
|
||||
}
|
||||
System.arraycopy(args, 2, fields, 0, fields.length);
|
||||
conf.setStrings("index.fields", fields);
|
||||
Job job = new Job(conf, tableName);
|
||||
job.setJarByClass(IndexBuilder.class);
|
||||
|
@ -127,7 +127,7 @@ public class RollingBatchRestartRsAction extends BatchRestartRsAction {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
serverNames.add(ServerName.valueOf(i + ".example.org", i, i));
|
||||
}
|
||||
return serverNames.toArray(new ServerName [] {});
|
||||
return serverNames.toArray(new ServerName[serverNames.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -401,8 +401,7 @@ public class IntegrationTestBigLinkedList extends IntegrationTestBase {
|
||||
|
||||
private static <T> void circularLeftShift(T[] first) {
|
||||
T ez = first[0];
|
||||
for (int i = 0; i < first.length - 1; i++)
|
||||
first[i] = first[i + 1];
|
||||
System.arraycopy(first, 1, first, 0, first.length - 1);
|
||||
first[first.length - 1] = ez;
|
||||
}
|
||||
|
||||
|
@ -413,9 +413,7 @@ public class FileLink {
|
||||
assert this.locations == null : "Link locations already set";
|
||||
this.locations = new Path[1 + alternativePaths.length];
|
||||
this.locations[0] = originPath;
|
||||
for (int i = 0; i < alternativePaths.length; i++) {
|
||||
this.locations[i + 1] = alternativePaths[i];
|
||||
}
|
||||
System.arraycopy(alternativePaths, 0, this.locations, 1, alternativePaths.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,8 +171,7 @@ public class SplitLogManager {
|
||||
if (logfiles == null || logfiles.length == 0) {
|
||||
LOG.info(hLogDir + " is empty dir, no logs to split");
|
||||
} else {
|
||||
for (FileStatus status : logfiles)
|
||||
fileStatus.add(status);
|
||||
Collections.addAll(fileStatus, logfiles);
|
||||
}
|
||||
}
|
||||
FileStatus[] a = new FileStatus[fileStatus.size()];
|
||||
|
@ -889,9 +889,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
||||
}
|
||||
String[] tables = conf.getStrings("hbase.balancer.tablesOnMaster");
|
||||
if (tables != null) {
|
||||
for (String table: tables) {
|
||||
tablesOnMaster.add(table);
|
||||
}
|
||||
Collections.addAll(tablesOnMaster, tables);
|
||||
}
|
||||
this.rackManager = new RackManager(getConf());
|
||||
regionFinder.setConf(conf);
|
||||
|
@ -1175,11 +1175,8 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||
}
|
||||
// max cost is the case where every region replica is hosted together regardless of host
|
||||
int[] primariesOfRegions = new int[cluster.numRegions];
|
||||
for (int i = 0; i < cluster.regions.length; i++) {
|
||||
// assume all regions are hosted by only one server
|
||||
int primaryIndex = cluster.regionIndexToPrimaryIndex[i];
|
||||
primariesOfRegions[i] = primaryIndex;
|
||||
}
|
||||
System.arraycopy(cluster.regionIndexToPrimaryIndex, 0, primariesOfRegions, 0,
|
||||
cluster.regions.length);
|
||||
|
||||
Arrays.sort(primariesOfRegions);
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class MetricsMBeanBase extends MetricsDynamicMBeanBase {
|
||||
|
||||
LOG.info("new MBeanInfo");
|
||||
this.extendedInfo = new MBeanInfo( this.getClass().getName(),
|
||||
this.description, attributes.toArray( new MBeanAttributeInfo[0] ),
|
||||
this.description, attributes.toArray(new MBeanAttributeInfo[attributes.size()]),
|
||||
parentInfo.getConstructors(), parentInfo.getOperations(),
|
||||
parentInfo.getNotifications() );
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
@ -913,9 +914,7 @@ public class StripeStoreFileManager
|
||||
if (this.state.stripeFiles.isEmpty()) return new ArrayList<byte[]>();
|
||||
ArrayList<byte[]> result = new ArrayList<byte[]>(this.state.stripeEndRows.length + 2);
|
||||
result.add(OPEN_KEY);
|
||||
for (int i = 0; i < this.state.stripeEndRows.length; ++i) {
|
||||
result.add(this.state.stripeEndRows[i]);
|
||||
}
|
||||
Collections.addAll(result, this.state.stripeEndRows);
|
||||
result.add(OPEN_KEY);
|
||||
return result;
|
||||
}
|
||||
|
@ -1213,7 +1213,7 @@ class FSHLog implements HLog, Syncable {
|
||||
void offer(final long sequence, final SyncFuture [] syncFutures, final int syncFutureCount) {
|
||||
// Set sequence first because the add to the queue will wake the thread if sleeping.
|
||||
this.sequence = sequence;
|
||||
for (int i = 0; i < syncFutureCount; i++) this.syncFutures.add(syncFutures[i]);
|
||||
this.syncFutures.addAll(Arrays.asList(syncFutures).subList(0, syncFutureCount));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@
|
||||
package org.apache.hadoop.hbase.replication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
@ -43,9 +44,7 @@ public class ChainWALEntryFilter implements WALEntryFilter {
|
||||
// flatten the chains
|
||||
for (WALEntryFilter filter : filters) {
|
||||
if (filter instanceof ChainWALEntryFilter) {
|
||||
for (WALEntryFilter f : ((ChainWALEntryFilter) filter).filters) {
|
||||
rawFilters.add(f);
|
||||
}
|
||||
Collections.addAll(rawFilters, ((ChainWALEntryFilter) filter).filters);
|
||||
} else {
|
||||
rawFilters.add(filter);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@ -270,9 +271,7 @@ public class RowSpec {
|
||||
this.row = startRow;
|
||||
this.endRow = endRow;
|
||||
if (columns != null) {
|
||||
for (byte[] col: columns) {
|
||||
this.columns.add(col);
|
||||
}
|
||||
Collections.addAll(this.columns, columns);
|
||||
}
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.apache.hadoop.hbase.security.visibility.expression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
@ -46,9 +47,7 @@ public class NonLeafExpressionNode implements ExpressionNode {
|
||||
public NonLeafExpressionNode(Operator op, ExpressionNode... exps) {
|
||||
this.op = op;
|
||||
List<ExpressionNode> expLst = new ArrayList<ExpressionNode>();
|
||||
for (ExpressionNode exp : exps) {
|
||||
expLst.add(exp);
|
||||
}
|
||||
Collections.addAll(expLst, exps);
|
||||
this.childExps = expLst;
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,7 @@ public class CollectionBackedScanner extends NonReversedNonLazyKeyValueScanner {
|
||||
this.comparator = comparator;
|
||||
|
||||
List<KeyValue> tmp = new ArrayList<KeyValue>(array.length);
|
||||
for( int i = 0; i < array.length ; ++i) {
|
||||
tmp.add(array[i]);
|
||||
}
|
||||
Collections.addAll(tmp, array);
|
||||
Collections.sort(tmp, comparator);
|
||||
data = tmp;
|
||||
init();
|
||||
|
@ -1296,7 +1296,7 @@ public class HBaseFsck extends Configured {
|
||||
"You may need to restore the previously sidelined hbase:meta");
|
||||
return false;
|
||||
}
|
||||
meta.batchMutate(puts.toArray(new Put[0]));
|
||||
meta.batchMutate(puts.toArray(new Put[puts.size()]));
|
||||
HRegion.closeHRegion(meta);
|
||||
LOG.info("Success! hbase:meta table rebuilt.");
|
||||
LOG.info("Old hbase:meta is moved into " + backupDir);
|
||||
|
@ -129,9 +129,7 @@ public class MunkresAssignment {
|
||||
}
|
||||
} else {
|
||||
for (int r = 0; r < rows; r++) {
|
||||
for (int c = 0; c < cols; c++) {
|
||||
cost[r][c] = costMatrix[r][c];
|
||||
}
|
||||
System.arraycopy(costMatrix[r], 0, cost[r], 0, cols);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -681,7 +681,7 @@ public class RegionSplitter {
|
||||
LinkedList<HRegionInfo> check = Lists.newLinkedList();
|
||||
check.add(table.getRegionLocation(start).getRegionInfo());
|
||||
check.add(table.getRegionLocation(split).getRegionInfo());
|
||||
for (HRegionInfo hri : check.toArray(new HRegionInfo[] {})) {
|
||||
for (HRegionInfo hri : check.toArray(new HRegionInfo[check.size()])) {
|
||||
byte[] sk = hri.getStartKey();
|
||||
if (sk.length == 0)
|
||||
sk = splitAlgo.firstRow();
|
||||
|
@ -1994,9 +1994,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
|
||||
byte [] endKey = Bytes.toBytes("zzzzz");
|
||||
byte [][] splitKeys = Bytes.split(startKey, endKey, numRegions - 3);
|
||||
byte [][] regionStartKeys = new byte[splitKeys.length+1][];
|
||||
for (int i=0;i<splitKeys.length;i++) {
|
||||
regionStartKeys[i+1] = splitKeys[i];
|
||||
}
|
||||
System.arraycopy(splitKeys, 0, regionStartKeys, 1, splitKeys.length);
|
||||
regionStartKeys[0] = HConstants.EMPTY_BYTE_ARRAY;
|
||||
return createMultiRegions(c, table, family, regionStartKeys);
|
||||
}
|
||||
@ -2963,9 +2961,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
|
||||
assertTrue(numRegions>3);
|
||||
byte [][] tmpSplitKeys = Bytes.split(startKey, endKey, numRegions - 3);
|
||||
byte [][] result = new byte[tmpSplitKeys.length+1][];
|
||||
for (int i=0;i<tmpSplitKeys.length;i++) {
|
||||
result[i+1] = tmpSplitKeys[i];
|
||||
}
|
||||
System.arraycopy(tmpSplitKeys, 0, result, 1, tmpSplitKeys.length);
|
||||
result[0] = HConstants.EMPTY_BYTE_ARRAY;
|
||||
return result;
|
||||
}
|
||||
@ -3491,6 +3487,6 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
|
||||
// this algo is not available
|
||||
}
|
||||
}
|
||||
return supportedAlgos.toArray(new Compression.Algorithm[0]);
|
||||
return supportedAlgos.toArray(new Algorithm[supportedAlgos.size()]);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -4072,9 +4073,7 @@ public class TestFromClientSide {
|
||||
Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
|
||||
HTableDescriptor[] ts = admin.listTables();
|
||||
HashSet<HTableDescriptor> result = new HashSet<HTableDescriptor>(ts.length);
|
||||
for (int i = 0; i < ts.length; i++) {
|
||||
result.add(ts[i]);
|
||||
}
|
||||
Collections.addAll(result, ts);
|
||||
int size = result.size();
|
||||
assertTrue(size >= tables.length);
|
||||
for (int i = 0; i < tables.length && i < size; i++) {
|
||||
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@ -192,9 +193,7 @@ public class TestSnapshotMetadata {
|
||||
|
||||
// restore the snapshot into a cloned table and examine the output
|
||||
List<byte[]> familiesList = new ArrayList<byte[]>();
|
||||
for (byte[] family : families) {
|
||||
familiesList.add(family);
|
||||
}
|
||||
Collections.addAll(familiesList, families);
|
||||
|
||||
// Create a snapshot in which all families are empty
|
||||
SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, null,
|
||||
@ -276,9 +275,7 @@ public class TestSnapshotMetadata {
|
||||
}
|
||||
familiesWithDataList.add(familyForUpdate);
|
||||
} else {
|
||||
for (byte[] family : families) {
|
||||
emptyFamiliesList.add(family);
|
||||
}
|
||||
Collections.addAll(emptyFamiliesList, families);
|
||||
}
|
||||
|
||||
// take a "disabled" snapshot
|
||||
|
@ -86,33 +86,33 @@ public class TestInvocationRecordFilter {
|
||||
List<Integer> expectedQualifiers = new ArrayList<Integer>();
|
||||
|
||||
selectQualifiers.add(-1);
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[0]),
|
||||
expectedQualifiers.toArray(new Integer[0]));
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[selectQualifiers.size()]),
|
||||
expectedQualifiers.toArray(new Integer[expectedQualifiers.size()]));
|
||||
|
||||
selectQualifiers.clear();
|
||||
|
||||
selectQualifiers.add(0);
|
||||
expectedQualifiers.add(0);
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[0]),
|
||||
expectedQualifiers.toArray(new Integer[0]));
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[selectQualifiers.size()]),
|
||||
expectedQualifiers.toArray(new Integer[expectedQualifiers.size()]));
|
||||
|
||||
selectQualifiers.add(3);
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[0]),
|
||||
expectedQualifiers.toArray(new Integer[0]));
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[selectQualifiers.size()]),
|
||||
expectedQualifiers.toArray(new Integer[expectedQualifiers.size()]));
|
||||
|
||||
selectQualifiers.add(4);
|
||||
expectedQualifiers.add(4);
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[0]),
|
||||
expectedQualifiers.toArray(new Integer[0]));
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[selectQualifiers.size()]),
|
||||
expectedQualifiers.toArray(new Integer[expectedQualifiers.size()]));
|
||||
|
||||
selectQualifiers.add(5);
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[0]),
|
||||
expectedQualifiers.toArray(new Integer[0]));
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[selectQualifiers.size()]),
|
||||
expectedQualifiers.toArray(new Integer[expectedQualifiers.size()]));
|
||||
|
||||
selectQualifiers.add(8);
|
||||
expectedQualifiers.add(8);
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[0]),
|
||||
expectedQualifiers.toArray(new Integer[0]));
|
||||
verifyInvocationResults(selectQualifiers.toArray(new Integer[selectQualifiers.size()]),
|
||||
expectedQualifiers.toArray(new Integer[expectedQualifiers.size()]));
|
||||
}
|
||||
|
||||
public void verifyInvocationResults(Integer[] selectQualifiers,
|
||||
|
@ -644,9 +644,7 @@ public class TestStripeCompactionPolicy {
|
||||
byte[][] keys = new byte[][] { KEY_A, KEY_B, KEY_C, KEY_D, KEY_E };
|
||||
assert stripeCount <= keys.length + 1;
|
||||
List<byte[]> boundaries = new ArrayList<byte[]>();
|
||||
for (int i = 0; i < stripeCount - 1; ++i) {
|
||||
boundaries.add(keys[i]);
|
||||
}
|
||||
boundaries.addAll(Arrays.asList(keys).subList(0, stripeCount - 1));
|
||||
return boundaries;
|
||||
}
|
||||
|
||||
|
@ -133,11 +133,13 @@ public class TestUser {
|
||||
final String username = "testuser";
|
||||
final ImmutableSet<String> singleGroups = ImmutableSet.of("group");
|
||||
final Configuration conf = HBaseConfiguration.create();
|
||||
User user = User.createUserForTesting(conf, username, singleGroups.toArray(new String[]{}));
|
||||
User user = User.createUserForTesting(conf, username,
|
||||
singleGroups.toArray(new String[singleGroups.size()]));
|
||||
assertUserGroup(user, singleGroups);
|
||||
|
||||
final ImmutableSet<String> multiGroups = ImmutableSet.of("group", "group1", "group2");
|
||||
user = User.createUserForTesting(conf, username, multiGroups.toArray(new String[]{}));
|
||||
user = User.createUserForTesting(conf, username,
|
||||
multiGroups.toArray(new String[multiGroups.size()]));
|
||||
assertUserGroup(user, multiGroups);
|
||||
}
|
||||
|
||||
|
@ -757,9 +757,7 @@ public class LoadTestTool extends AbstractHBaseTool {
|
||||
newArgs = new String[cmdLineArgs.length + 2];
|
||||
newArgs[0] = "-" + LoadTestTool.OPT_TABLE_NAME;
|
||||
newArgs[1] = LoadTestTool.DEFAULT_TABLE_NAME;
|
||||
for (int i = 0; i < cmdLineArgs.length; i++) {
|
||||
newArgs[i + 2] = cmdLineArgs[i];
|
||||
}
|
||||
System.arraycopy(cmdLineArgs, 0, newArgs, 2, cmdLineArgs.length);
|
||||
} else {
|
||||
newArgs = cmdLineArgs;
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ public class TestThriftServerCmdLine {
|
||||
args.add("start");
|
||||
|
||||
thriftServer = new ThriftServer(TEST_UTIL.getConfiguration());
|
||||
startCmdLineThread(args.toArray(new String[0]));
|
||||
startCmdLineThread(args.toArray(new String[args.size()]));
|
||||
|
||||
// wait up to 10s for the server to start
|
||||
for (int i = 0; i < 100
|
||||
|
Loading…
x
Reference in New Issue
Block a user