From ecc9e595641370eb813400c1dbedf905b91505bb Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Fri, 18 Mar 2016 17:36:05 -0500 Subject: [PATCH] Fixes (simple) warnings issued by IntelliJ IDEA's 'Analyze > Inspect Code...' feature. --- src/main/java/org/ice4j/StackProperties.java | 2 +- .../ice4j/attribute/IceControlAttribute.java | 16 +++---- .../ice4j/attribute/LifetimeAttribute.java | 2 +- .../attribute/ReservationTokenAttribute.java | 6 +-- .../ice4j/attribute/SoftwareAttribute.java | 2 +- .../attribute/UnknownAttributesAttribute.java | 10 ++-- src/main/java/org/ice4j/ice/Agent.java | 24 ++++------ src/main/java/org/ice4j/ice/CheckList.java | 16 +++---- src/main/java/org/ice4j/ice/Component.java | 46 +++++++++---------- .../ice4j/ice/ConnectivityCheckClient.java | 6 +-- .../java/org/ice4j/ice/DefaultNominator.java | 3 +- .../org/ice4j/ice/FoundationsRegistry.java | 2 +- .../java/org/ice4j/ice/IceMediaStream.java | 19 +++----- src/main/java/org/ice4j/ice/NetworkUtils.java | 7 ++- .../java/org/ice4j/ice/TcpHostCandidate.java | 3 +- .../ice/harvest/CandidateHarvesterSet.java | 13 +++--- .../ice/harvest/HostCandidateHarvester.java | 4 +- .../harvest/MappingCandidateHarvester.java | 2 +- .../ice/harvest/SinglePortUdpHarvester.java | 25 +++++----- .../ice/harvest/StunCandidateHarvest.java | 8 ++-- .../ice/harvest/StunCandidateHarvester.java | 6 +-- .../org/ice4j/ice/harvest/TcpHarvester.java | 38 +++++++-------- .../ice/harvest/TurnCandidateHarvest.java | 4 +- .../org/ice4j/ice/harvest/UPNPHarvester.java | 8 ++-- .../java/org/ice4j/ice/sdp/IceSdpUtils.java | 9 ++-- src/main/java/org/ice4j/message/Message.java | 7 ++- .../java/org/ice4j/pseudotcp/EnShutdown.java | 2 +- src/main/java/org/ice4j/pseudotcp/Option.java | 2 +- .../org/ice4j/pseudotcp/PseudoTCPBase.java | 10 ++-- .../ice4j/pseudotcp/PseudoTcpSocketImpl.java | 4 +- .../org/ice4j/pseudotcp/PseudoTcpState.java | 2 +- .../java/org/ice4j/pseudotcp/SendFlags.java | 2 +- .../java/org/ice4j/pseudotcp/WriteResult.java | 2 +- .../ice4j/security/CredentialsManager.java | 3 +- .../GoogleRelayedCandidateDelegate.java | 10 ++-- .../socket/IceTcpServerSocketWrapper.java | 2 +- .../socket/MultiplexingXXXSocketSupport.java | 2 +- .../RelayedCandidateDatagramSocket.java | 12 ++--- .../ice4j/socket/RtcpDemuxPacketFilter.java | 2 +- .../java/org/ice4j/stack/EventDispatcher.java | 4 +- .../java/org/ice4j/stack/MessageQueue.java | 2 +- .../org/ice4j/stack/NetAccessManager.java | 10 ++-- src/main/java/org/ice4j/stack/StunStack.java | 16 +++---- .../java/org/ice4j/stack/TransactionID.java | 4 +- .../ice4j/MessageEventDispatchingTest.java | 5 +- .../org/ice4j/TransactionSupportTests.java | 6 +-- .../OptionalAttributeAttributeTest.java | 2 +- .../UnknownAttributesAttributeTest.java | 4 +- .../pseudotcp/PseudoTcpTestRecvWindow.java | 4 +- .../stunclient/ResponseSequenceServer.java | 4 +- src/test/java/test/AwsTest.java | 3 +- src/test/java/test/IceDistributed.java | 2 +- src/test/java/test/MappingTest.java | 3 +- src/test/java/test/SdpUtils.java | 2 - src/test/java/test/TrickleIce.java | 4 +- 55 files changed, 183 insertions(+), 235 deletions(-) diff --git a/src/main/java/org/ice4j/StackProperties.java b/src/main/java/org/ice4j/StackProperties.java index d83a788..a3a3486 100644 --- a/src/main/java/org/ice4j/StackProperties.java +++ b/src/main/java/org/ice4j/StackProperties.java @@ -245,7 +245,7 @@ public class StackProperties String[] parts = str.split(regex); // Remove mal-formatted entries. - List res = new ArrayList(); + List res = new ArrayList<>(); for (String s : parts) if (s != null && s.trim().length() != 0) res.add(s); diff --git a/src/main/java/org/ice4j/attribute/IceControlAttribute.java b/src/main/java/org/ice4j/attribute/IceControlAttribute.java index 72c64c3..6a96b79 100644 --- a/src/main/java/org/ice4j/attribute/IceControlAttribute.java +++ b/src/main/java/org/ice4j/attribute/IceControlAttribute.java @@ -74,14 +74,14 @@ public abstract class IceControlAttribute // the attributeValue array // Reading in the network byte order (Big-Endian) - tieBreaker = ((attributeValue[offset++] & 0xffl) << 56) - | ((attributeValue[offset++] & 0xffl) << 48) - | ((attributeValue[offset++] & 0xffl) << 40) - | ((attributeValue[offset++] & 0xffl) << 32) - | ((attributeValue[offset++] & 0xffl) << 24) - | ((attributeValue[offset++] & 0xffl) << 16) - | ((attributeValue[offset++] & 0xffl) << 8) - | (attributeValue[offset++] & 0xffl); + tieBreaker = ((attributeValue[offset++] & 0xffL) << 56) + | ((attributeValue[offset++] & 0xffL) << 48) + | ((attributeValue[offset++] & 0xffL) << 40) + | ((attributeValue[offset++] & 0xffL) << 32) + | ((attributeValue[offset++] & 0xffL) << 24) + | ((attributeValue[offset++] & 0xffL) << 16) + | ((attributeValue[offset++] & 0xffL) << 8) + | (attributeValue[offset] & 0xffL); } /** diff --git a/src/main/java/org/ice4j/attribute/LifetimeAttribute.java b/src/main/java/org/ice4j/attribute/LifetimeAttribute.java index 4018cda..c797abe 100644 --- a/src/main/java/org/ice4j/attribute/LifetimeAttribute.java +++ b/src/main/java/org/ice4j/attribute/LifetimeAttribute.java @@ -144,7 +144,7 @@ public class LifetimeAttribute throw new StunException("length invalid"); } - lifetime = ((attributeValue[offset + 0] << 24) & 0xff000000) + + lifetime = ((attributeValue[offset] << 24) & 0xff000000) + ((attributeValue[offset + 1] << 16) & 0x00ff0000) + ((attributeValue[offset + 2] << 8) & 0x0000ff00) + (attributeValue[offset + 3] & 0x000000ff); diff --git a/src/main/java/org/ice4j/attribute/ReservationTokenAttribute.java b/src/main/java/org/ice4j/attribute/ReservationTokenAttribute.java index a22b251..039da40 100644 --- a/src/main/java/org/ice4j/attribute/ReservationTokenAttribute.java +++ b/src/main/java/org/ice4j/attribute/ReservationTokenAttribute.java @@ -131,7 +131,7 @@ public class ReservationTokenAttribute byte[] copy = new byte[reservationToken.length]; System.arraycopy(reservationToken, 0, copy, 0, reservationToken.length); - return reservationToken; + return copy; } /** @@ -196,8 +196,8 @@ public class ReservationTokenAttribute for(int i = 0; i < b; i++) { - token.reservationToken[i] = (byte)((left >> (i * 8)) & 0xFFl); - token.reservationToken[i + b] = (byte)((right >> (i * 8)) & 0xFFl); + token.reservationToken[i] = (byte)((left >> (i * 8)) & 0xFFL); + token.reservationToken[i + b] = (byte)((right >> (i * 8)) & 0xFFL); } //calculate hashcode for Hashtable storage. diff --git a/src/main/java/org/ice4j/attribute/SoftwareAttribute.java b/src/main/java/org/ice4j/attribute/SoftwareAttribute.java index 2e5b215..1d966bd 100644 --- a/src/main/java/org/ice4j/attribute/SoftwareAttribute.java +++ b/src/main/java/org/ice4j/attribute/SoftwareAttribute.java @@ -121,7 +121,7 @@ public class SoftwareAttribute byte[] copy = new byte[software.length]; System.arraycopy(software, 0, copy, 0, software.length); - return software; + return copy; } /** diff --git a/src/main/java/org/ice4j/attribute/UnknownAttributesAttribute.java b/src/main/java/org/ice4j/attribute/UnknownAttributesAttribute.java index eb578cd..dc2a647 100644 --- a/src/main/java/org/ice4j/attribute/UnknownAttributesAttribute.java +++ b/src/main/java/org/ice4j/attribute/UnknownAttributesAttribute.java @@ -52,7 +52,7 @@ public class UnknownAttributesAttribute extends Attribute /** * A list of attribute types that were not understood by the server. */ - private ArrayList unknownAttributes = new ArrayList(); + private ArrayList unknownAttributes = new ArrayList<>(); /** * Constructor. @@ -100,7 +100,7 @@ public class UnknownAttributesAttribute extends Attribute //some attributes may be repeated for padding //(packet length should be divisable by 4) if(!contains(attributeID)) - unknownAttributes.add(new Character(attributeID)); + unknownAttributes.add(attributeID); } /** @@ -110,7 +110,7 @@ public class UnknownAttributesAttribute extends Attribute */ public boolean contains(char attributeID) { - return unknownAttributes.contains(new Character(attributeID)); + return unknownAttributes.contains(attributeID); } /** @@ -140,7 +140,7 @@ public class UnknownAttributesAttribute extends Attribute */ public char getAttribute(int index ) { - return (unknownAttributes.get(index)).charValue(); + return unknownAttributes.get(index); } /** @@ -164,7 +164,7 @@ public class UnknownAttributesAttribute extends Attribute Iterator attributes = getAttributes(); while (attributes.hasNext()) { - char att = attributes.next().charValue(); + char att = attributes.next(); binValue[offset++] = (byte)(att >> 8); binValue[offset++] = (byte)(att & 0x00FF); } diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java index 18f86a3..1f22240 100644 --- a/src/main/java/org/ice4j/ice/Agent.java +++ b/src/main/java/org/ice4j/ice/Agent.java @@ -27,7 +27,6 @@ import java.util.logging.*; import org.ice4j.*; import org.ice4j.ice.harvest.*; -import org.ice4j.ice.harvest.TrickleCallback; import org.ice4j.stack.*; /** @@ -108,7 +107,7 @@ public class Agent * This map preserves the insertion order of the media streams. */ private final Map mediaStreams - = new LinkedHashMap(); + = new LinkedHashMap<>(); /** * The candidate harvester that we use to gather candidate on the local @@ -122,8 +121,7 @@ public class Agent * harvest candidates synchronously, and previously to harvesting by * {@link #harvesters}. */ - private final List hostHarvesters - = new LinkedList(); + private final List hostHarvesters = new LinkedList<>(); /** * The set of harvesters (i.e. STUN, TURN, and others) that the agent should @@ -166,7 +164,7 @@ public class Agent * the necessary triggered checks. */ private final List preDiscoveredPairsQueue - = new LinkedList(); + = new LinkedList<>(); /** * The lock that we use while starting connectivity establishment. @@ -228,7 +226,7 @@ public class Agent * Agent} and following its changes of state. */ private final List stateListeners - = new LinkedList(); + = new LinkedList<>(); /** * The StunStack used by this Agent. @@ -525,7 +523,7 @@ public class Agent } //create a list of components and start harvesting - List components = new LinkedList(); + List components = new LinkedList<>(); for (IceMediaStream stream : getStreams()) { @@ -571,14 +569,12 @@ public class Agent "Trigger checks for pairs that were received before " + "running state"); - Iterator it = preDiscoveredPairsQueue.iterator(); - - while(it.hasNext()) + for (CandidatePair cp : preDiscoveredPairsQueue) { - triggerCheck(it.next()); + triggerCheck(cp); } - this.preDiscoveredPairsQueue.clear(); + preDiscoveredPairsQueue.clear(); } connCheckClient.startChecks(); @@ -1042,7 +1038,7 @@ public class Agent { synchronized(mediaStreams) { - return new LinkedList(mediaStreams.keySet()); + return new LinkedList<>(mediaStreams.keySet()); } } @@ -1057,7 +1053,7 @@ public class Agent { synchronized(mediaStreams) { - return new LinkedList(mediaStreams.values()); + return new LinkedList<>(mediaStreams.values()); } } diff --git a/src/main/java/org/ice4j/ice/CheckList.java b/src/main/java/org/ice4j/ice/CheckList.java index cf0b39e..e939324 100644 --- a/src/main/java/org/ice4j/ice/CheckList.java +++ b/src/main/java/org/ice4j/ice/CheckList.java @@ -56,8 +56,7 @@ public class CheckList * A pair would get into a triggered check queue as soon as we receive * a check on its local candidate. */ - private final List triggeredCheckQueue - = new LinkedList(); + private final List triggeredCheckQueue = new LinkedList<>(); /** * A reference to the {@link IceMediaStream} that we belong to. @@ -69,14 +68,14 @@ public class CheckList * Agent} and following its changes of state. */ private final List stateListeners - = new LinkedList(); + = new LinkedList<>(); /** * Contains {@link PropertyChangeListener}s registered with this {@link * Agent} and following its changes of state. */ private final List checkListeners - = new LinkedList(); + = new LinkedList<>(); /** * The name of the {@link PropertyChangeEvent} that we use to deliver @@ -297,8 +296,7 @@ public class CheckList */ protected synchronized void computeInitialCheckListPairStates() { - Map pairsToWait - = new Hashtable(); + Map pairsToWait = new Hashtable<>(); //first, determine the pairs that we'd need to put in the waiting state. for(CandidatePair pair : this) @@ -508,8 +506,7 @@ public class CheckList synchronized(stateListeners) { - listenersCopy - = new LinkedList(stateListeners); + listenersCopy = new LinkedList<>(stateListeners); } PropertyChangeEvent evt = new PropertyChangeEvent( @@ -564,8 +561,7 @@ public class CheckList synchronized(checkListeners) { - listenersCopy - = new LinkedList(checkListeners); + listenersCopy = new LinkedList<>(checkListeners); } PropertyChangeEvent evt = new PropertyChangeEvent( diff --git a/src/main/java/org/ice4j/ice/Component.java b/src/main/java/org/ice4j/ice/Component.java index 879c4bf..3b860b2 100644 --- a/src/main/java/org/ice4j/ice/Component.java +++ b/src/main/java/org/ice4j/ice/Component.java @@ -73,21 +73,19 @@ public class Component /** * The list locally gathered candidates for this media stream. */ - private final List localCandidates - = new LinkedList(); + private final List localCandidates = new LinkedList<>(); /** * The list of candidates that the peer agent sent for this stream. */ - private final List remoteCandidates - = new LinkedList(); + private final List remoteCandidates = new LinkedList<>(); /** * The list of candidates that the peer agent sent for this stream after * connectivity establishment. */ - private final List remoteUpdateCandidates = - new LinkedList(); + private final List remoteUpdateCandidates + = new LinkedList<>(); /** * A Comparator that we use for sorting Candidates by @@ -185,7 +183,7 @@ public class Component { synchronized(localCandidates) { - return new ArrayList(localCandidates); + return new ArrayList<>(localCandidates); } } @@ -257,8 +255,7 @@ public class Component logger.info("Update remote candidate for " + toShortString() + ": " + candidate.getTransportAddress()); - List existingCandidates - = new LinkedList(); + List existingCandidates = new LinkedList<>(); synchronized (remoteCandidates) { existingCandidates.addAll(remoteCandidates); @@ -300,8 +297,7 @@ public class Component if(remoteUpdateCandidates.size() == 0) return; - newRemoteCandidates - = new LinkedList(remoteUpdateCandidates); + newRemoteCandidates = new LinkedList<>(remoteUpdateCandidates); List localCnds = getLocalCandidates(); @@ -315,7 +311,7 @@ public class Component } } - checkList = new Vector(); + checkList = new Vector<>(); for(LocalCandidate localCnd : localCnds) { @@ -391,7 +387,7 @@ public class Component { synchronized(remoteCandidates) { - return new ArrayList(remoteCandidates); + return new ArrayList<>(remoteCandidates); } } @@ -459,15 +455,17 @@ public class Component StringBuffer buff = new StringBuffer("Component id=").append(getComponentID()); - buff.append(" parent stream=" + getParentStream().getName()); + buff.append(" parent stream=").append(getParentStream().getName()); //local candidates int localCandidatesCount = getLocalCandidateCount(); if(localCandidatesCount > 0) { - buff.append("\n" + localCandidatesCount + " Local candidates:"); - buff.append("\ndefault candidate: " + getDefaultCandidate()); + buff.append("\n") + .append(localCandidatesCount) + .append(" Local candidates:"); + buff.append("\ndefault candidate: ").append(getDefaultCandidate()); synchronized(localCandidates) { @@ -487,14 +485,16 @@ public class Component if(remoteCandidatesCount > 0) { - buff.append("\n" + remoteCandidatesCount + " Remote candidates:"); - buff.append("\ndefault remote candidate: " - + getDefaultRemoteCandidate()); + buff.append("\n") + .append(remoteCandidatesCount) + .append(" Remote candidates:"); + buff.append("\ndefault remote candidate: ") + .append(getDefaultRemoteCandidate()); synchronized(remoteCandidates) { for (RemoteCandidate cand : remoteCandidates) { - buff.append("\n" + cand.toString()); + buff.append("\n").append(cand); } } } @@ -701,12 +701,8 @@ public class Component { synchronized(localCandidates) { - Iterator localCandsIter = localCandidates.iterator(); - - while (localCandsIter.hasNext()) + for (LocalCandidate cand : localCandidates) { - LocalCandidate cand = localCandsIter.next(); - if ((defaultCandidate == null) || (defaultCandidate.getDefaultPreference() < cand.getDefaultPreference())) diff --git a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java index 8fa8494..7561ac2 100644 --- a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java @@ -57,13 +57,13 @@ class ConnectivityCheckClient /** * The {@link PaceMaker}s that are currently running checks in this client. */ - private final List paceMakers = new LinkedList(); + private final List paceMakers = new LinkedList<>(); /** * Timer that is used to let some seconds before a CheckList is considered * as FAILED. */ - private Map timers = new HashMap(); + private Map timers = new HashMap<>(); /** * A flag that determines whether we have received a STUN response or not. @@ -611,7 +611,7 @@ class ConnectivityCheckClient synchronized(this) { Vector parentCheckList - = new Vector(parentStream.getCheckList()); + = new Vector<>(parentStream.getCheckList()); for(CandidatePair pair : parentCheckList) if ((pair.getState() == CandidatePairState.FROZEN) diff --git a/src/main/java/org/ice4j/ice/DefaultNominator.java b/src/main/java/org/ice4j/ice/DefaultNominator.java index 33d9d8c..c3ee922 100644 --- a/src/main/java/org/ice4j/ice/DefaultNominator.java +++ b/src/main/java/org/ice4j/ice/DefaultNominator.java @@ -50,8 +50,7 @@ public class DefaultNominator * Map that will remember association between validated relayed candidate * and a timer. It is use with the NOMINATE_FIRST_HIGHEST_VALID strategy. */ - private final Map validatedCandidates - = new HashMap(); + private final Map validatedCandidates = new HashMap<>(); /** * Creates a new instance of this nominator using parentAgent as diff --git a/src/main/java/org/ice4j/ice/FoundationsRegistry.java b/src/main/java/org/ice4j/ice/FoundationsRegistry.java index 2c7566f..007b4c7 100644 --- a/src/main/java/org/ice4j/ice/FoundationsRegistry.java +++ b/src/main/java/org/ice4j/ice/FoundationsRegistry.java @@ -44,7 +44,7 @@ public class FoundationsRegistry * Contains mappings between a type+baseIP+server+transport * Strings and the foundation that has been assigned to them. */ - private Map foundations = new Hashtable(); + private Map foundations = new Hashtable<>(); /** * Assigns to candidate the foundation that corresponds to its diff --git a/src/main/java/org/ice4j/ice/IceMediaStream.java b/src/main/java/org/ice4j/ice/IceMediaStream.java index 5be3a18..6768e81 100644 --- a/src/main/java/org/ice4j/ice/IceMediaStream.java +++ b/src/main/java/org/ice4j/ice/IceMediaStream.java @@ -75,8 +75,7 @@ public class IceMediaStream * address; a media stream may require multiple components, each of which * has to work for the media stream as a whole to work. */ - private final Map components - = new LinkedHashMap(); + private final Map components = new LinkedHashMap<>(); /** * An ordered set of candidate pairs for a media stream that have been @@ -84,8 +83,7 @@ public class IceMediaStream * start of ICE processing, and fills as checks are performed, resulting in * valid candidate pairs. */ - private final TreeSet validList - = new TreeSet(); + private final TreeSet validList = new TreeSet<>(); /** * The id that was last assigned to a component. The next id that we give @@ -110,7 +108,7 @@ public class IceMediaStream * Agent} and following the various events it may be generating. */ private final List streamListeners - = new LinkedList(); + = new LinkedList<>(); /** * The maximum number of candidate pairs that we should have in our check @@ -163,9 +161,7 @@ public class IceMediaStream synchronized (components) { component = new Component(++lastComponentID, this); - components.put( - Integer.valueOf(component.getComponentID()), - component); + components.put(component.getComponentID(), component); } return component; @@ -231,7 +227,7 @@ public class IceMediaStream { synchronized(components) { - return new ArrayList(components.values()); + return new ArrayList<>(components.values()); } } @@ -261,7 +257,7 @@ public class IceMediaStream { synchronized(components) { - return new ArrayList(components.keySet()); + return new ArrayList<>(components.keySet()); } } @@ -436,8 +432,7 @@ public class IceMediaStream { //a list that we only use for storing pairs that we've already gone //through. The list is destroyed at the end of this method. - List tmpCheckList - = new ArrayList(checkList.size()); + List tmpCheckList = new ArrayList<>(checkList.size()); Iterator ckListIter = checkList.iterator(); diff --git a/src/main/java/org/ice4j/ice/NetworkUtils.java b/src/main/java/org/ice4j/ice/NetworkUtils.java index f46a8f9..48aa738 100644 --- a/src/main/java/org/ice4j/ice/NetworkUtils.java +++ b/src/main/java/org/ice4j/ice/NetworkUtils.java @@ -707,8 +707,7 @@ public class NetworkUtils { Method method = iface.getClass().getMethod("isLoopback"); - return ((Boolean)method.invoke(iface, new Object[]{})) - .booleanValue(); + return (Boolean) method.invoke(iface); } catch(Throwable t) { @@ -739,7 +738,7 @@ public class NetworkUtils { Method method = iface.getClass().getMethod("isUp"); - return ((Boolean)method.invoke(iface)).booleanValue(); + return (Boolean) method.invoke(iface); } catch(Throwable t) { @@ -769,7 +768,7 @@ public class NetworkUtils { Method method = iface.getClass().getMethod("isVirtual"); - return ((Boolean)method.invoke(iface)).booleanValue(); + return (Boolean) method.invoke(iface); } catch(Throwable t) { diff --git a/src/main/java/org/ice4j/ice/TcpHostCandidate.java b/src/main/java/org/ice4j/ice/TcpHostCandidate.java index caa3831..8cd96d4 100644 --- a/src/main/java/org/ice4j/ice/TcpHostCandidate.java +++ b/src/main/java/org/ice4j/ice/TcpHostCandidate.java @@ -38,8 +38,7 @@ public class TcpHostCandidate /** * List of accepted sockets for this TcpHostCandidate. */ - private final List sockets - = new LinkedList(); + private final List sockets = new LinkedList<>(); /** * Initializes a new TcpHostCandidate. diff --git a/src/main/java/org/ice4j/ice/harvest/CandidateHarvesterSet.java b/src/main/java/org/ice4j/ice/harvest/CandidateHarvesterSet.java index fc41c0a..582f1eb 100644 --- a/src/main/java/org/ice4j/ice/harvest/CandidateHarvesterSet.java +++ b/src/main/java/org/ice4j/ice/harvest/CandidateHarvesterSet.java @@ -44,7 +44,7 @@ public class CandidateHarvesterSet * Set. */ private final Collection elements - = new LinkedList(); + = new LinkedList<>(); /** * A pool of thread used for gathering process. @@ -95,7 +95,7 @@ public class CandidateHarvesterSet */ public void harvest(Component component) { - harvest(Arrays.asList(new Component[]{component}), null); + harvest(Arrays.asList(component), null); } @@ -145,8 +145,7 @@ public class CandidateHarvesterSet * Start asynchronously executing the * CandidateHarvester#harvest(Component) method of the harvesters. */ - Map> tasks - = new HashMap>(); + Map> tasks = new HashMap<>(); while (true) { @@ -171,7 +170,7 @@ public class CandidateHarvesterSet synchronized (components) { - componentsCopy = new ArrayList(components); + componentsCopy = new ArrayList<>(components); } // Asynchronously start gathering candidates using the harvester. @@ -194,7 +193,7 @@ public class CandidateHarvesterSet = taskIter.next(); Future future = task.getValue(); - while (true) + do { try { @@ -232,9 +231,9 @@ public class CandidateHarvesterSet } catch (InterruptedException ie) { - continue; } } + while (true); taskIter.remove(); } } diff --git a/src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java index 0738b24..5920c38 100644 --- a/src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java @@ -194,7 +194,7 @@ public class HostCandidateHarvester } if (allowedAddresses == null) - allowedAddresses = new ArrayList(); + allowedAddresses = new ArrayList<>(); allowedAddresses.add(address); } @@ -220,7 +220,7 @@ public class HostCandidateHarvester } if (blockedAddresses == null) - blockedAddresses = new ArrayList(); + blockedAddresses = new ArrayList<>(); blockedAddresses.add(address); } diff --git a/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvester.java index a68ed25..b2a8877 100644 --- a/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvester.java @@ -84,7 +84,7 @@ public class MappingCandidateHarvester * Report the LocalCandidates gathered by this CandidateHarvester so * that the harvest is sure to be considered successful. */ - Collection candidates = new HashSet(); + Collection candidates = new HashSet<>(); for (Candidate cand : component.getLocalCandidates()) { diff --git a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java index a3dede5..07b58b8 100644 --- a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java @@ -85,10 +85,9 @@ public class SinglePortUdpHarvester public static List createHarvesters(int port) { - List harvesters - = new LinkedList(); + List harvesters = new LinkedList<>(); - List addresses = new LinkedList(); + List addresses = new LinkedList<>(); boolean isIPv6Disabled = StackProperties.getBoolean( StackProperties.DISABLE_IPv6, false); @@ -158,7 +157,7 @@ public class SinglePortUdpHarvester * other threads remove entries when candidates are freed. */ private final Map sockets - = new ConcurrentHashMap(); + = new ConcurrentHashMap<>(); /** * The map which keeps all currently active Candidates created by @@ -166,14 +165,14 @@ public class SinglePortUdpHarvester * the components for which the candidates are harvested. */ private final Map candidates - = new ConcurrentHashMap(); + = new ConcurrentHashMap<>(); /** * A pool of Buffer instances used to avoid creating of new java * objects. */ private final ArrayBlockingQueue pool - = new ArrayBlockingQueue(POOL_SIZE); + = new ArrayBlockingQueue<>(POOL_SIZE); /** * The local address that this harvester is bound to. @@ -235,7 +234,7 @@ public class SinglePortUdpHarvester MySocket destinationSocket; InetSocketAddress remoteAddress; - while (true) + do { // TODO: implement stopping the thread with a switch? @@ -303,21 +302,19 @@ public class SinglePortUdpHarvester catch (SocketException se) { logger.info("Could not create a socket: " + se); - continue; } catch (IOException ioe) { logger.info("Failed to handle new socket: " + ioe); - continue; } } else { // A STUN Binding Request with an unknown USERNAME. Drop it. - continue; } } } + while (true); // TODO we are all done, clean up. } @@ -431,7 +428,7 @@ public class SinglePortUdpHarvester */ logger.info( "More than one Component for an Agent, cannot harvest."); - return new LinkedList(); + return new LinkedList<>(); } MyCandidate candidate = new MyCandidate(component, ufrag); @@ -470,7 +467,7 @@ public class SinglePortUdpHarvester * The FIFO which acts as a buffer for this socket. */ private final ArrayBlockingQueue queue - = new ArrayBlockingQueue(QUEUE_SIZE); + = new ArrayBlockingQueue<>(QUEUE_SIZE); /** * The {@link QueueStatistics} instance optionally used to collect and @@ -721,7 +718,7 @@ public class SinglePortUdpHarvester * a corresponding socket in {@link #sockets}. */ private final Map candidateSockets - = new HashMap(); + = new HashMap<>(); /** * The collection of DatagramSockets added to this candidate. @@ -731,7 +728,7 @@ public class SinglePortUdpHarvester * the STUN stack or the user of ice4j. */ private final Map sockets - = new HashMap(); + = new HashMap<>(); /** * Initializes a new MyCandidate instance with the given diff --git a/src/main/java/org/ice4j/ice/harvest/StunCandidateHarvest.java b/src/main/java/org/ice4j/ice/harvest/StunCandidateHarvest.java index 322619a..edada37 100644 --- a/src/main/java/org/ice4j/ice/harvest/StunCandidateHarvest.java +++ b/src/main/java/org/ice4j/ice/harvest/StunCandidateHarvest.java @@ -68,8 +68,7 @@ public class StunCandidateHarvest * The list of Candidates harvested for {@link #hostCandidate} by * this harvest. */ - private final List candidates - = new LinkedList(); + private final List candidates = new LinkedList<>(); /** * The indicator which determines whether this StunCandidateHarvest @@ -104,8 +103,7 @@ public class StunCandidateHarvest * to which a STUN Response responds available though it is known * in StunClientTransaction. */ - private final Map requests - = new HashMap(); + private final Map requests = new HashMap<>(); /** * The interval in milliseconds at which a new STUN keep-alive message is to @@ -1448,7 +1446,7 @@ public class StunCandidateHarvest */ public SendKeepAliveMessageThread(StunCandidateHarvest harvest) { - this.harvest = new WeakReference(harvest); + this.harvest = new WeakReference<>(harvest); } @Override diff --git a/src/main/java/org/ice4j/ice/harvest/StunCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/StunCandidateHarvester.java index ae109e6..3eaa624 100644 --- a/src/main/java/org/ice4j/ice/harvest/StunCandidateHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/StunCandidateHarvester.java @@ -51,7 +51,7 @@ public class StunCandidateHarvester * completed i.e. have harvested Candidates. */ private final List completedHarvests - = new LinkedList(); + = new LinkedList<>(); /** * The username used by this StunCandidateHarvester for the @@ -65,7 +65,7 @@ public class StunCandidateHarvester * not completed yet so {@link #harvest(Component)} has to wait for them. */ private final List startedHarvests - = new LinkedList(); + = new LinkedList<>(); /** * The address of the STUN server that we will be sending our requests to. @@ -255,7 +255,7 @@ public class StunCandidateHarvester * Report the LocalCandidates gathered by this CandidateHarvester so * that the harvest is sure to be considered successful. */ - Collection candidates = new HashSet(); + Collection candidates = new HashSet<>(); synchronized (completedHarvests) { diff --git a/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java b/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java index bdfb610..3a66010 100644 --- a/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java @@ -83,7 +83,7 @@ public class TcpHarvester List interfaces) throws IOException { - List addresses = new LinkedList(); + List addresses = new LinkedList<>(); for (NetworkInterface iface : interfaces) { @@ -126,34 +126,32 @@ public class TcpHarvester * Components from being freed. */ private final Map> components - = new HashMap>(); + = new HashMap<>(); /** * The list of transport addresses which we have found to be listening on, * and which we will advertise as candidates in * {@link #harvest(org.ice4j.ice.Component)} */ - private final List localAddresses - = new LinkedList(); + private final List localAddresses = new LinkedList<>(); /** * Maps a public address to a local address. */ private final Map mappedAddresses - = new HashMap(); + = new HashMap<>(); /** * Sets of additional ports, for which server reflexive candidates will be * added. */ - private final Set mappedPorts = new HashSet(); + private final Set mappedPorts = new HashSet<>(); /** * Channels pending to be added to the list that {@link #readThread} reads * from. */ - private final List newChannels - = new LinkedList(); + private final List newChannels = new LinkedList<>(); /** * A counter used to decide when to purge {@link #components}. @@ -175,7 +173,7 @@ public class TcpHarvester * on. */ private final List serverSocketChannels - = new LinkedList(); + = new LinkedList<>(); /** * Whether or not to use ssltcp. @@ -421,8 +419,7 @@ public class TcpHarvester */ private List createLocalCandidates(Component component) { - List hostCandidates - = new LinkedList(); + List hostCandidates = new LinkedList<>(); // Add the host candidates for the addresses we really listen on for (TransportAddress transportAddress : localAddresses) @@ -438,8 +435,7 @@ public class TcpHarvester } // Add srflx candidates for any mapped addresses - List mappedCandidates - = new LinkedList(); + List mappedCandidates = new LinkedList<>(); for (Map.Entry mapping : mappedAddresses.entrySet()) @@ -473,8 +469,7 @@ public class TcpHarvester } // Add srflx candidates for mapped ports - List portMappedCandidates - = new LinkedList(); + List portMappedCandidates = new LinkedList<>(); for (TcpHostCandidate base : hostCandidates) { @@ -524,8 +519,7 @@ public class TcpHarvester } } - LinkedList allCandidates - = new LinkedList(); + LinkedList allCandidates = new LinkedList<>(); allCandidates.addAll(hostCandidates); allCandidates.addAll(mappedCandidates); @@ -589,7 +583,7 @@ public class TcpHarvester */ logger.info( "More than one Component for an Agent, cannot harvest."); - return new LinkedList(); + return new LinkedList<>(); } List candidates = createLocalCandidates(component); @@ -599,8 +593,9 @@ public class TcpHarvester synchronized (components) { - components.put(agent.getLocalUfrag(), - new WeakReference(component)); + components.put( + agent.getLocalUfrag(), + new WeakReference<>(component)); purgeComponents(); } @@ -807,8 +802,7 @@ public class TcpHarvester } IOException exception = null; - List channelsToAdd - = new LinkedList(); + List channelsToAdd = new LinkedList<>(); // Allow to go on, so we can quit if closed. long selectTimeout = 3000; diff --git a/src/main/java/org/ice4j/ice/harvest/TurnCandidateHarvest.java b/src/main/java/org/ice4j/ice/harvest/TurnCandidateHarvest.java index 6333b78..926cc45 100644 --- a/src/main/java/org/ice4j/ice/harvest/TurnCandidateHarvest.java +++ b/src/main/java/org/ice4j/ice/harvest/TurnCandidateHarvest.java @@ -323,9 +323,7 @@ public class TurnCandidateHarvest EvenPortAttribute evenPortAttribute = (EvenPortAttribute) request.getAttribute(Attribute.EVEN_PORT); boolean rFlag - = (evenPortAttribute == null) - ? false - : evenPortAttribute.isRFlag(); + = (evenPortAttribute != null) && evenPortAttribute.isRFlag(); return MessageFactory.createAllocateRequest( diff --git a/src/main/java/org/ice4j/ice/harvest/UPNPHarvester.java b/src/main/java/org/ice4j/ice/harvest/UPNPHarvester.java index 16eaa47..6fe0d5a 100644 --- a/src/main/java/org/ice4j/ice/harvest/UPNPHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/UPNPHarvester.java @@ -87,7 +87,7 @@ public class UPNPHarvester */ public synchronized Collection harvest(Component component) { - Collection candidates = new HashSet(); + Collection candidates = new HashSet<>(); int retries = 0; logger.fine("Begin UPnP harvesting"); @@ -213,9 +213,9 @@ public class UPNPHarvester String externalIP, int port, Component cmp, GatewayDevice device) throws Exception { - List ret = new ArrayList(); - TransportAddress addr = new TransportAddress(externalIP, port, - Transport.UDP); + List ret = new ArrayList<>(); + TransportAddress addr + = new TransportAddress(externalIP, port, Transport.UDP); HostCandidate base = new HostCandidate(socket, cmp); diff --git a/src/main/java/org/ice4j/ice/sdp/IceSdpUtils.java b/src/main/java/org/ice4j/ice/sdp/IceSdpUtils.java index cc562d1..c23d613 100644 --- a/src/main/java/org/ice4j/ice/sdp/IceSdpUtils.java +++ b/src/main/java/org/ice4j/ice/sdp/IceSdpUtils.java @@ -273,8 +273,8 @@ public class IceSdpUtils //m lines List streams = agent.getStreams(); - Vector mDescs = new Vector( - agent.getStreamCount()); + Vector mDescs + = new Vector<>(agent.getStreamCount()); for(IceMediaStream stream : streams) { MediaDescription mLine = sdpFactory.createMediaDescription( @@ -320,15 +320,14 @@ public class IceSdpUtils if(localCandidates == null || localCandidates.size() == 0) { - trickleUpdate = new ArrayList(1); + trickleUpdate = new ArrayList<>(1); trickleUpdate.add( sdpFactory.createAttribute(END_OF_CANDIDATES, null)); return trickleUpdate; } - trickleUpdate - = new ArrayList(localCandidates.size() + 1); + trickleUpdate = new ArrayList<>(localCandidates.size() + 1); String streamName = null; diff --git a/src/main/java/org/ice4j/message/Message.java b/src/main/java/org/ice4j/message/Message.java index 03d46ce..bb1fba7 100644 --- a/src/main/java/org/ice4j/message/Message.java +++ b/src/main/java/org/ice4j/message/Message.java @@ -342,7 +342,7 @@ public abstract class Message */ //not sure this is the best solution but I'm trying to keep entry order protected LinkedHashMap attributes - = new LinkedHashMap(); + = new LinkedHashMap<>(); /** * Attribute presentity is a thing of RFC 3489 and no longer exists in @@ -619,7 +619,7 @@ public abstract class Message { synchronized(attributes) { - return new LinkedList(attributes.values()); + return new LinkedList<>(attributes.values()); } } @@ -941,8 +941,7 @@ public abstract class Message offset += RFC3489_TRANSACTION_ID_LENGTH; } - Vector> v = - new Vector>(); + Vector> v = new Vector<>(); Iterator> iter = null; char dataLengthForContentDependentAttribute = 0; diff --git a/src/main/java/org/ice4j/pseudotcp/EnShutdown.java b/src/main/java/org/ice4j/pseudotcp/EnShutdown.java index 82d10aa..068a3de 100644 --- a/src/main/java/org/ice4j/pseudotcp/EnShutdown.java +++ b/src/main/java/org/ice4j/pseudotcp/EnShutdown.java @@ -36,4 +36,4 @@ enum EnShutdown * There was a forceful shutdown */ SD_FORCEFUL -}; +} diff --git a/src/main/java/org/ice4j/pseudotcp/Option.java b/src/main/java/org/ice4j/pseudotcp/Option.java index cac1934..e0c9d88 100644 --- a/src/main/java/org/ice4j/pseudotcp/Option.java +++ b/src/main/java/org/ice4j/pseudotcp/Option.java @@ -48,4 +48,4 @@ public enum Option * Timeout in ms for write operations(0 - no timeout) */ OPT_WRITE_TIMEOUT -}; +} diff --git a/src/main/java/org/ice4j/pseudotcp/PseudoTCPBase.java b/src/main/java/org/ice4j/pseudotcp/PseudoTCPBase.java index 7232c93..1b18764 100755 --- a/src/main/java/org/ice4j/pseudotcp/PseudoTCPBase.java +++ b/src/main/java/org/ice4j/pseudotcp/PseudoTCPBase.java @@ -174,7 +174,7 @@ public class PseudoTCPBase * control flags. If segment contains any data it is stored in the receive * buffer. */ - List m_rlist = new ArrayList(); + List m_rlist = new ArrayList<>(); /** * Last receive timestamp */ @@ -203,7 +203,7 @@ public class PseudoTCPBase /** * Outgoing segments list */ - List m_slist = new ArrayList(); + List m_slist = new ArrayList<>(); /** * Last send timestamp */ @@ -429,7 +429,7 @@ public class PseudoTCPBase // Check if it's time to retransmit a segment if (m_rto_base > 0 && (timeDiff(m_rto_base + m_rx_rto, now) <= 0)) { - assert m_slist.isEmpty() == false; + assert !m_slist.isEmpty(); // retransmit segments if (logger.isLoggable(Level.FINER)) { @@ -1399,7 +1399,7 @@ public class PseudoTCPBase Iterator iter = m_rlist.iterator(); - List toBeRemoved = new ArrayList(); + List toBeRemoved = new ArrayList<>(); while (iter.hasNext()) { RSegment it = iter.next(); @@ -1903,7 +1903,7 @@ public class PseudoTCPBase */ boolean parseOptions(byte[] data, int offset, int len) { - List options_specified = new ArrayList(); + List options_specified = new ArrayList<>(); // See http://www.freesoft.org/CIE/Course/Section4/8.htm for // parsing the options list. diff --git a/src/main/java/org/ice4j/pseudotcp/PseudoTcpSocketImpl.java b/src/main/java/org/ice4j/pseudotcp/PseudoTcpSocketImpl.java index 8bba7fa..a638d81 100755 --- a/src/main/java/org/ice4j/pseudotcp/PseudoTcpSocketImpl.java +++ b/src/main/java/org/ice4j/pseudotcp/PseudoTcpSocketImpl.java @@ -270,7 +270,7 @@ class PseudoTcpSocketImpl throw new UnsupportedOperationException("Not supported yet."); } - private Map options = new HashMap(); + private Map options = new HashMap<>(); public void setOption(int optID, Object value) throws SocketException { @@ -353,7 +353,7 @@ class PseudoTcpSocketImpl synchronized (state_notify) { while (pseudoTcp.getState() != PseudoTcpState.TCP_ESTABLISHED - && (noTimeout ? true : (elapsed < timeout)) ) + && (noTimeout || (elapsed < timeout)) ) { long start = System.currentTimeMillis(); state_notify.wait(timeout); diff --git a/src/main/java/org/ice4j/pseudotcp/PseudoTcpState.java b/src/main/java/org/ice4j/pseudotcp/PseudoTcpState.java index 39f706b..7ff8639 100755 --- a/src/main/java/org/ice4j/pseudotcp/PseudoTcpState.java +++ b/src/main/java/org/ice4j/pseudotcp/PseudoTcpState.java @@ -45,4 +45,4 @@ public enum PseudoTcpState * TODO: closing procedure */ TCP_CLOSED// = 4; -}; +} diff --git a/src/main/java/org/ice4j/pseudotcp/SendFlags.java b/src/main/java/org/ice4j/pseudotcp/SendFlags.java index 03c4aca..1491eba 100644 --- a/src/main/java/org/ice4j/pseudotcp/SendFlags.java +++ b/src/main/java/org/ice4j/pseudotcp/SendFlags.java @@ -24,5 +24,5 @@ package org.ice4j.pseudotcp; */ enum SendFlags { - sfNone, sfImmediateAck, sfDelayedAck; + sfNone, sfImmediateAck, sfDelayedAck } diff --git a/src/main/java/org/ice4j/pseudotcp/WriteResult.java b/src/main/java/org/ice4j/pseudotcp/WriteResult.java index 6a1bfc6..2f0e8ff 100755 --- a/src/main/java/org/ice4j/pseudotcp/WriteResult.java +++ b/src/main/java/org/ice4j/pseudotcp/WriteResult.java @@ -35,4 +35,4 @@ public enum WriteResult * Write failed */ WR_FAIL -}; +} diff --git a/src/main/java/org/ice4j/security/CredentialsManager.java b/src/main/java/org/ice4j/security/CredentialsManager.java index 85b5882..4ea3050 100644 --- a/src/main/java/org/ice4j/security/CredentialsManager.java +++ b/src/main/java/org/ice4j/security/CredentialsManager.java @@ -41,8 +41,7 @@ public class CredentialsManager * The list of CredentialsAuthoritys registered with this manager * as being able to provide credentials. */ - private final List authorities = - new LinkedList(); + private final List authorities = new LinkedList<>(); /** * The list of CredentialsAuthoritys registered with this manager diff --git a/src/main/java/org/ice4j/socket/GoogleRelayedCandidateDelegate.java b/src/main/java/org/ice4j/socket/GoogleRelayedCandidateDelegate.java index 4a1ccd7..bd6564b 100644 --- a/src/main/java/org/ice4j/socket/GoogleRelayedCandidateDelegate.java +++ b/src/main/java/org/ice4j/socket/GoogleRelayedCandidateDelegate.java @@ -58,8 +58,7 @@ public class GoogleRelayedCandidateDelegate * {@link #receive(DatagramPacket)} method. They have been received from the * TURN server in the form of Data indications. */ - private final List packetsToReceive = - new LinkedList(); + private final List packetsToReceive = new LinkedList<>(); /** * The DatagramSockets which have been sent through this @@ -67,8 +66,7 @@ public class GoogleRelayedCandidateDelegate * and which are to be relayed through its associated TURN server in the * form of Send indications. */ - private final List packetsToSend = - new LinkedList(); + private final List packetsToSend = new LinkedList<>(); /** * The Thread which is to send the {@link #packetsToSend} to the @@ -315,7 +313,7 @@ public class GoogleRelayedCandidateDelegate { synchronized (packetsToReceive) { - while (true) + do { /* * According to the javadoc of DatagramSocket#close(), any @@ -337,7 +335,6 @@ public class GoogleRelayedCandidateDelegate catch (InterruptedException iex) { } - continue; } else { @@ -348,6 +345,7 @@ public class GoogleRelayedCandidateDelegate break; } } + while (true); } } diff --git a/src/main/java/org/ice4j/socket/IceTcpServerSocketWrapper.java b/src/main/java/org/ice4j/socket/IceTcpServerSocketWrapper.java index de37490..d6a076b 100644 --- a/src/main/java/org/ice4j/socket/IceTcpServerSocketWrapper.java +++ b/src/main/java/org/ice4j/socket/IceTcpServerSocketWrapper.java @@ -62,7 +62,7 @@ public class IceTcpServerSocketWrapper /** * List of TCP client sockets. */ - private final List sockets = new ArrayList(); + private final List sockets = new ArrayList<>(); /** * Initializes a new IceTcpServerSocketWrapper. diff --git a/src/main/java/org/ice4j/socket/MultiplexingXXXSocketSupport.java b/src/main/java/org/ice4j/socket/MultiplexingXXXSocketSupport.java index 28ee966..643f768 100644 --- a/src/main/java/org/ice4j/socket/MultiplexingXXXSocketSupport.java +++ b/src/main/java/org/ice4j/socket/MultiplexingXXXSocketSupport.java @@ -570,7 +570,7 @@ abstract class MultiplexingXXXSocketSupport if (socketFilter.accept(p)) { if (toMove == null) - toMove = new LinkedList(); + toMove = new LinkedList<>(); toMove.add(p); // XXX In the method receive, we allow multiple filters diff --git a/src/main/java/org/ice4j/socket/RelayedCandidateDatagramSocket.java b/src/main/java/org/ice4j/socket/RelayedCandidateDatagramSocket.java index 77dfb63..1c45e27 100644 --- a/src/main/java/org/ice4j/socket/RelayedCandidateDatagramSocket.java +++ b/src/main/java/org/ice4j/socket/RelayedCandidateDatagramSocket.java @@ -112,7 +112,7 @@ public class RelayedCandidateDatagramSocket * RelayedCandidateDatagramSockets relays data send to it to * peer TransportAddresses. */ - private final List channels = new LinkedList(); + private final List channels = new LinkedList<>(); /** * The indicator which determines whether this instance has started @@ -143,8 +143,7 @@ public class RelayedCandidateDatagramSocket * {@link #receive(DatagramPacket)} method. They have been received from the * TURN server in the form of Data indications. */ - private final List packetsToReceive - = new LinkedList(); + private final List packetsToReceive = new LinkedList<>(); /** * The DatagramSockets which have been sent through this @@ -152,8 +151,7 @@ public class RelayedCandidateDatagramSocket * and which are to be relayed through its associated TURN server in the * form of Send indications. */ - private final List packetsToSend - = new LinkedList(); + private final List packetsToSend = new LinkedList<>(); /** * The Thread which receives DatagramPackets from @@ -704,7 +702,7 @@ public class RelayedCandidateDatagramSocket { synchronized (packetsToReceive) { - while (true) + do { /* * According to the javadoc of DatagramSocket#close(), any @@ -728,7 +726,6 @@ public class RelayedCandidateDatagramSocket catch (InterruptedException iex) { } - continue; } else { @@ -739,6 +736,7 @@ public class RelayedCandidateDatagramSocket break; } } + while (true); } } diff --git a/src/main/java/org/ice4j/socket/RtcpDemuxPacketFilter.java b/src/main/java/org/ice4j/socket/RtcpDemuxPacketFilter.java index 880c2bd..2ddb2a8 100644 --- a/src/main/java/org/ice4j/socket/RtcpDemuxPacketFilter.java +++ b/src/main/java/org/ice4j/socket/RtcpDemuxPacketFilter.java @@ -65,7 +65,7 @@ public class RtcpDemuxPacketFilter byte[] data = p.getData(); int off = p.getOffset(); - if (((data[off + 0] & 0xc0) >> 6) == 2) //RTP/RTCP version field + if (((data[off] & 0xc0) >> 6) == 2) //RTP/RTCP version field { int pt = data[off + 1] & 0xff; diff --git a/src/main/java/org/ice4j/stack/EventDispatcher.java b/src/main/java/org/ice4j/stack/EventDispatcher.java index b2ad34b..7f27c38 100644 --- a/src/main/java/org/ice4j/stack/EventDispatcher.java +++ b/src/main/java/org/ice4j/stack/EventDispatcher.java @@ -39,7 +39,7 @@ public class EventDispatcher * EventDispatcher. */ private final List> messageListeners - = new Vector>(); + = new Vector<>(); /** * The Map of EventDispatchers which keep the @@ -48,7 +48,7 @@ public class EventDispatcher * TransportAddresses. */ private final Map children - = new Hashtable(); + = new Hashtable<>(); /** * Initializes a new EventDispatcher instance. diff --git a/src/main/java/org/ice4j/stack/MessageQueue.java b/src/main/java/org/ice4j/stack/MessageQueue.java index 34f2373..d67e6e7 100644 --- a/src/main/java/org/ice4j/stack/MessageQueue.java +++ b/src/main/java/org/ice4j/stack/MessageQueue.java @@ -38,7 +38,7 @@ class MessageQueue // not sure whether Vector is the best choice here since we explicitly //sync all methods ... review later - private Vector queue = new Vector(); + private final Vector queue = new Vector<>(); //keep a copy of the fifo size and make it accessible for concurrent // queries. diff --git a/src/main/java/org/ice4j/stack/NetAccessManager.java b/src/main/java/org/ice4j/stack/NetAccessManager.java index 2a889f4..70cb56a 100644 --- a/src/main/java/org/ice4j/stack/NetAccessManager.java +++ b/src/main/java/org/ice4j/stack/NetAccessManager.java @@ -59,7 +59,7 @@ class NetAccessManager */ private final Map> udpConnectors - = new HashMap>(); + = new HashMap<>(); /** * All Connectors currently in use with TCP. The table maps a local @@ -74,7 +74,7 @@ class NetAccessManager */ private final Map> tcpConnectors - = new HashMap>(); + = new HashMap<>(); /** * A synchronized FIFO where incoming messages are stocked for processing. @@ -84,8 +84,7 @@ class NetAccessManager /** * A thread pool of message processors. */ - private Vector messageProcessors - = new Vector(); + private final Vector messageProcessors = new Vector<>(); /** * The instance that should be notified when an incoming message has been @@ -332,8 +331,7 @@ class NetAccessManager if (connectorsForLocalAddress == null) { - connectorsForLocalAddress - = new HashMap(); + connectorsForLocalAddress = new HashMap<>(); connectorsMap.put(localAddress, connectorsForLocalAddress); } diff --git a/src/main/java/org/ice4j/stack/StunStack.java b/src/main/java/org/ice4j/stack/StunStack.java index a9e0d6a..b7e558d 100644 --- a/src/main/java/org/ice4j/stack/StunStack.java +++ b/src/main/java/org/ice4j/stack/StunStack.java @@ -81,7 +81,7 @@ public class StunStack */ private final Hashtable clientTransactions - = new Hashtable(); + = new Hashtable<>(); /** * The Thread which expires the StunServerTransactions of @@ -96,7 +96,7 @@ public class StunStack */ private final Hashtable serverTransactions - = new Hashtable(); + = new Hashtable<>(); /** * A dispatcher for incoming requests event; @@ -310,8 +310,7 @@ public class StunStack */ if (clientTransactionsToCancel == null) { - clientTransactionsToCancel - = new LinkedList(); + clientTransactionsToCancel = new LinkedList<>(); } clientTransactionsToCancel.add(tran); } @@ -352,8 +351,7 @@ public class StunStack if (serverTransactionsToExpire == null) { - serverTransactionsToExpire - = new LinkedList(); + serverTransactionsToExpire = new LinkedList<>(); } serverTransactionsToExpire.add(tran); } @@ -1079,8 +1077,7 @@ public class StunStack synchronized (clientTransactions) { clientTransactionsToCancel - = new ArrayList( - clientTransactions.values()); + = new ArrayList<>(clientTransactions.values()); clientTransactions.clear(); } /* @@ -1097,8 +1094,7 @@ public class StunStack synchronized (serverTransactions) { serverTransactionsToExpire - = new ArrayList( - serverTransactions.values()); + = new ArrayList<>(serverTransactions.values()); serverTransactions.clear(); } for (StunServerTransaction tran : serverTransactionsToExpire) diff --git a/src/main/java/org/ice4j/stack/TransactionID.java b/src/main/java/org/ice4j/stack/TransactionID.java index ec1005f..b8a6a5d 100644 --- a/src/main/java/org/ice4j/stack/TransactionID.java +++ b/src/main/java/org/ice4j/stack/TransactionID.java @@ -131,8 +131,8 @@ public class TransactionID for(int i = 0; i < b; i++) { - tid.transactionID[i] = (byte)((left >> (i * 8)) & 0xFFl); - tid.transactionID[i + b] = (byte)((right >> (i * 8)) & 0xFFl); + tid.transactionID[i] = (byte)((left >> (i * 8)) & 0xFFL); + tid.transactionID[i + b] = (byte)((right >> (i * 8)) & 0xFFL); } //calculate hashcode for Hashtable storage. diff --git a/src/test/java/org/ice4j/MessageEventDispatchingTest.java b/src/test/java/org/ice4j/MessageEventDispatchingTest.java index e0f420e..693df1b 100644 --- a/src/test/java/org/ice4j/MessageEventDispatchingTest.java +++ b/src/test/java/org/ice4j/MessageEventDispatchingTest.java @@ -260,8 +260,7 @@ public class MessageEventDispatchingTest extends TestCase private class PlainRequestCollector implements RequestListener { /** all requests we've received so far. */ - public Vector receivedRequests - = new Vector(); + public final Vector receivedRequests = new Vector<>(); /** * Stores incoming requests. @@ -299,7 +298,7 @@ public class MessageEventDispatchingTest extends TestCase private static class PlainResponseCollector extends AbstractResponseCollector { - public final Vector receivedResponses = new Vector(); + public final Vector receivedResponses = new Vector<>(); /** * Notifies this ResponseCollector that a transaction described by diff --git a/src/test/java/org/ice4j/TransactionSupportTests.java b/src/test/java/org/ice4j/TransactionSupportTests.java index deaee03..d47a7af 100644 --- a/src/test/java/org/ice4j/TransactionSupportTests.java +++ b/src/test/java/org/ice4j/TransactionSupportTests.java @@ -515,7 +515,7 @@ public class TransactionSupportTests extends TestCase * */ private Vector receivedRequestsVector - = new Vector(); + = new Vector<>(); /** * Logs the newly received request. @@ -543,7 +543,7 @@ public class TransactionSupportTests extends TestCase */ public Vector getRequestsForTransaction(byte[] tranid) { - Vector newVec = new Vector(); + Vector newVec = new Vector<>(); for (StunMessageEvent evt : receivedRequestsVector) { @@ -581,7 +581,7 @@ public class TransactionSupportTests extends TestCase /** * The responses we've collected so far. */ - public final Vector receivedResponses = new Vector(); + public final Vector receivedResponses = new Vector<>(); /** * Notifies this ResponseCollector that a transaction described by diff --git a/src/test/java/org/ice4j/attribute/OptionalAttributeAttributeTest.java b/src/test/java/org/ice4j/attribute/OptionalAttributeAttributeTest.java index 52bb39e..91ed08c 100644 --- a/src/test/java/org/ice4j/attribute/OptionalAttributeAttributeTest.java +++ b/src/test/java/org/ice4j/attribute/OptionalAttributeAttributeTest.java @@ -109,7 +109,7 @@ public class OptionalAttributeAttributeTest extends TestCase assertEquals("failed null comparison", expectedReturn, actualReturn); //wrong type comparison - obj = new String("hehe :)"); + obj = "hehe :)"; actualReturn = optionalAttribute.equals(obj); assertEquals("failed wrong type comparison", expectedReturn, actualReturn); diff --git a/src/test/java/org/ice4j/attribute/UnknownAttributesAttributeTest.java b/src/test/java/org/ice4j/attribute/UnknownAttributesAttributeTest.java index 156f0a9..7356fd2 100644 --- a/src/test/java/org/ice4j/attribute/UnknownAttributesAttributeTest.java +++ b/src/test/java/org/ice4j/attribute/UnknownAttributesAttributeTest.java @@ -253,8 +253,8 @@ public class UnknownAttributesAttributeTest extends TestCase Iterator iterator = unknownAttributesAttribute.getAttributes(); - actualId1 = iterator.next().charValue(); - actualId2 = iterator.next().charValue();; + actualId1 = iterator.next(); + actualId2 = iterator.next(); assertEquals("getAttributes() return value mismatch", expectedId1, actualId1); assertEquals("getAttributes() return value mismatch", expectedId2, actualId2); diff --git a/src/test/java/org/ice4j/pseudotcp/PseudoTcpTestRecvWindow.java b/src/test/java/org/ice4j/pseudotcp/PseudoTcpTestRecvWindow.java index 1593f18..e1be1ed 100755 --- a/src/test/java/org/ice4j/pseudotcp/PseudoTcpTestRecvWindow.java +++ b/src/test/java/org/ice4j/pseudotcp/PseudoTcpTestRecvWindow.java @@ -67,8 +67,8 @@ public class PseudoTcpTestRecvWindow extends PseudoTcpTestBase Thread.setDefaultUncaughtExceptionHandler(this); testDataSize = size; long start, elapsed; - send_position = new ArrayList(); - recv_position = new ArrayList(); + send_position = new ArrayList<>(); + recv_position = new ArrayList<>(); // Create some dummy data byte[] dummy = createDummyData(size); send_stream = new ByteFifoBuffer(size); diff --git a/src/test/java/org/ice4j/stunclient/ResponseSequenceServer.java b/src/test/java/org/ice4j/stunclient/ResponseSequenceServer.java index 19fa908ac..5a824b7 100644 --- a/src/test/java/org/ice4j/stunclient/ResponseSequenceServer.java +++ b/src/test/java/org/ice4j/stunclient/ResponseSequenceServer.java @@ -46,7 +46,7 @@ public class ResponseSequenceServer /** * The sequence of responses to send. */ - private Vector messageSequence = new Vector(); + private Vector messageSequence = new Vector<>(); /** * The StunStack used by this instance for the purposes of STUN @@ -110,7 +110,7 @@ public class ResponseSequenceServer if (response == null) { //leave a mark to skip a message - messageSequence.add(new Boolean(false)); + messageSequence.add(false); } else messageSequence.add(response); diff --git a/src/test/java/test/AwsTest.java b/src/test/java/test/AwsTest.java index 826cf4b..6539d39 100644 --- a/src/test/java/test/AwsTest.java +++ b/src/test/java/test/AwsTest.java @@ -60,8 +60,7 @@ public class AwsTest } AwsCandidateHarvester mch = new AwsCandidateHarvester(); - List harvesters - = new ArrayList(); + List harvesters = new ArrayList<>(); harvesters.add(mch); Agent localAgent = createAgent(2020, false, harvesters); diff --git a/src/test/java/test/IceDistributed.java b/src/test/java/test/IceDistributed.java index d59cfb7..b46f578 100644 --- a/src/test/java/test/IceDistributed.java +++ b/src/test/java/test/IceDistributed.java @@ -97,7 +97,7 @@ public class IceDistributed = new BufferedReader(new InputStreamReader(System.in)); StringBuffer buff = new StringBuffer(); - String line = new String(); + String line; while ( (line = reader.readLine()) != null) { diff --git a/src/test/java/test/MappingTest.java b/src/test/java/test/MappingTest.java index aa28790..480ba96 100644 --- a/src/test/java/test/MappingTest.java +++ b/src/test/java/test/MappingTest.java @@ -78,8 +78,7 @@ public class MappingTest MappingCandidateHarvester natHarvester = new MappingCandidateHarvester(publicAddress, localAddress); - List harvesters - = new ArrayList(); + List harvesters = new ArrayList<>(); harvesters.add(natHarvester); Agent localAgent = createAgent(2020, false, harvesters); diff --git a/src/test/java/test/SdpUtils.java b/src/test/java/test/SdpUtils.java index d9126d2..efc552c 100644 --- a/src/test/java/test/SdpUtils.java +++ b/src/test/java/test/SdpUtils.java @@ -18,13 +18,11 @@ package test; import java.util.*; -import java.util.StringTokenizer; import javax.sdp.*; import org.ice4j.*; import org.ice4j.ice.*; -import org.ice4j.ice.Agent; import org.ice4j.ice.sdp.*; /** diff --git a/src/test/java/test/TrickleIce.java b/src/test/java/test/TrickleIce.java index b986acd..9f2e238 100644 --- a/src/test/java/test/TrickleIce.java +++ b/src/test/java/test/TrickleIce.java @@ -80,7 +80,7 @@ public class TrickleIce localAgent.startCandidateTrickle(printer); - List allComponents = new LinkedList(); + List allComponents = new LinkedList<>(); int allCandidates = 0; for (IceMediaStream stream : localAgent.getStreams()) { @@ -139,7 +139,7 @@ public class TrickleIce if(iceCandidates == null) { - try{Thread.sleep(1000);}catch(Exception e){}; + try{Thread.sleep(1000);}catch(Exception e){} logger.info("ICE stats: time=" + agent.getTotalHarvestingTime() + "ms");