HBASE-12062 Fix usage of Collections.toArray

This commit is contained in:
Elliott Clark 2014-09-22 21:44:01 -07:00
parent 791a03b40f
commit 2635791027
30 changed files with 57 additions and 91 deletions

View File

@ -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()]);
}
/**

View File

@ -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) {

View File

@ -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());

View File

@ -119,7 +119,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) {

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}
/**

View File

@ -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()];

View File

@ -898,9 +898,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
String[] tables = conf.getStrings(
"hbase.balancer.tablesOnMaster", DEFAULT_TABLES_ON_MASTER);
if (tables != null) {
for (String table: tables) {
tablesOnMaster.add(table);
}
Collections.addAll(tablesOnMaster, tables);
}
this.rackManager = new RackManager(getConf());
regionFinder.setConf(conf);

View File

@ -1174,11 +1174,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);

View File

@ -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() );
}

View File

@ -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;
}

View File

@ -1221,7 +1221,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));
}
/**

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

View File

@ -1298,7 +1298,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);

View File

@ -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);
}
}

View File

@ -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();

View File

@ -2074,9 +2074,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);
}
@ -3085,9 +3083,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;
}
@ -3599,6 +3595,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()]);
}
}

View File

@ -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;
@ -4073,9 +4074,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++) {

View File

@ -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;
@ -193,9 +194,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,
@ -277,9 +276,7 @@ public class TestSnapshotMetadata {
}
familiesWithDataList.add(familyForUpdate);
} else {
for (byte[] family : families) {
emptyFamiliesList.add(family);
}
Collections.addAll(emptyFamiliesList, families);
}
// take a "disabled" snapshot

View File

@ -87,33 +87,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,

View File

@ -655,9 +655,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;
}

View File

@ -134,11 +134,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);
}

View File

@ -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;
}

View File

@ -693,8 +693,8 @@ public class TestHBaseFsck {
}
}
Put put = new Put(metaKey);
ServerName sn = TEST_UTIL.getHBaseAdmin().getClusterStatus().getServers()
.toArray(new ServerName[0])[0];
Collection<ServerName> var = TEST_UTIL.getHBaseAdmin().getClusterStatus().getServers();
ServerName sn = var.toArray(new ServerName[var.size()])[0];
//add a location with replicaId as 2 (since we already have replicas with replicaid 0 and 1)
MetaTableAccessor.addLocation(put, sn, sn.getStartcode(), 2);
meta.put(put);

View File

@ -173,7 +173,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