Cleanups: Collections.singleton(), COWAS - includes ticket #388

This commit is contained in:
zzz
2011-01-13 14:21:48 +00:00
parent 4c1050b93a
commit 65c6186479
15 changed files with 38 additions and 59 deletions

View File

@@ -225,7 +225,7 @@ public class OutNetMessage {
public void transportFailed(String transportStyle) {
if (_failedTransports == null)
_failedTransports = new HashSet(1);
_failedTransports = new HashSet(2);
_failedTransports.add(transportStyle);
}
/** not thread safe - dont fail transports and iterate over this at the same time */

View File

@@ -34,7 +34,7 @@ public class RouterClock extends Clock {
private long _lastChanged;
private int _lastStratum;
RouterContext _contextRC; // LINT field hides another field
private final RouterContext _contextRC;
public RouterClock(RouterContext context) {
super(context);

View File

@@ -156,7 +156,7 @@ public class Shitlist {
e.causeCode = reasonCode;
e.transports = null;
if (transport != null) {
e.transports = new ConcurrentHashSet(1);
e.transports = new ConcurrentHashSet(2);
e.transports.add(transport);
}

View File

@@ -74,8 +74,9 @@ class FloodfillPeerSelector extends PeerSelector {
*/
List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets, boolean preferConnected) {
if (peersToIgnore == null)
peersToIgnore = new HashSet(1);
peersToIgnore.add(_context.routerHash());
peersToIgnore = Collections.singleton(_context.routerHash());
else
peersToIgnore.add(_context.routerHash());
// TODO this is very slow
FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters);
if (kbuckets == null) return new ArrayList();
@@ -94,8 +95,7 @@ class FloodfillPeerSelector extends PeerSelector {
* List is not sorted and not shuffled.
*/
List<Hash> selectFloodfillParticipants(KBucketSet kbuckets) {
Set<Hash> ignore = new HashSet(1);
ignore.add(_context.routerHash());
Set<Hash> ignore = Collections.singleton(_context.routerHash());
return selectFloodfillParticipants(ignore, kbuckets);
}
@@ -132,8 +132,7 @@ class FloodfillPeerSelector extends PeerSelector {
* Group 3: All others
*/
List<Hash> selectFloodfillParticipants(Hash key, int maxNumRouters, KBucketSet kbuckets) {
Set<Hash> ignore = new HashSet(1);
ignore.add(_context.routerHash());
Set<Hash> ignore = Collections.singleton(_context.routerHash());
return selectFloodfillParticipants(key, maxNumRouters, ignore, kbuckets);
}
@@ -152,8 +151,7 @@ class FloodfillPeerSelector extends PeerSelector {
*/
List<Hash> selectFloodfillParticipants(Hash key, int howMany, Set<Hash> toIgnore, KBucketSet kbuckets) {
if (toIgnore == null) {
toIgnore = new HashSet(1);
toIgnore.add(_context.routerHash());
toIgnore = Collections.singleton(_context.routerHash());
} else if (!toIgnore.contains(_context.routerHash())) {
// copy the Set so we don't confuse StoreJob
toIgnore = new HashSet(toIgnore);

View File

@@ -31,8 +31,8 @@ import net.i2p.util.Log;
* Mostly unused, see overrides in FloodfillPeerSelector
*/
class PeerSelector {
protected Log _log;
protected RouterContext _context;
protected final Log _log;
protected final RouterContext _context;
public PeerSelector(RouterContext ctx) {
_context = ctx;

View File

@@ -9,7 +9,7 @@ package net.i2p.router.networkdb.kademlia;
*/
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -800,8 +800,7 @@ class SearchJob extends JobImpl {
if (rv) {
if (_log.shouldLog(Log.DEBUG))
_log.debug(getJobId() + ": Queueing up for next time: " + peer);
Set s = new HashSet(1);
s.add(peer);
Set<Hash> s = Collections.singleton(peer);
_facade.queueForExploration(s);
}
return rv;

View File

@@ -11,6 +11,7 @@ package net.i2p.router.peermanager;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -115,8 +116,7 @@ class PeerManager {
*/
List<Hash> selectPeers(PeerSelectionCriteria criteria) {
Set<Hash> peers = new HashSet(criteria.getMinimumRequired());
Set<Hash> exclude = new HashSet(1);
exclude.add(_context.routerHash());
Set<Hash> exclude = Collections.singleton(_context.routerHash());
switch (criteria.getPurpose()) {
case PeerSelectionCriteria.PURPOSE_TEST:
// for now, the peers we test will be the reliable ones

View File

@@ -1,6 +1,6 @@
package net.i2p.router.tunnel.pool;
import java.util.HashSet;
import java.util.Collections;
import java.util.Set;
import net.i2p.crypto.SessionKeyManager;
@@ -144,8 +144,7 @@ class TestJob extends JobImpl {
scheduleRetest();
return;
}
Set encryptTags = new HashSet(1);
encryptTags.add(encryptTag);
Set<SessionTag> encryptTags = Collections.singleton(encryptTag);
// Register the single tag with the appropriate SKM
if (_cfg.isInbound() && !_pool.getSettings().isExploratory()) {
SessionKeyManager skm = getContext().clientManager().getClientSessionKeyManager(_pool.getSettings().getDestination());