diff --git a/src/org/ice4j/ice/Candidate.java b/src/org/ice4j/ice/Candidate.java index 55594a2..098bc25 100644 --- a/src/org/ice4j/ice/Candidate.java +++ b/src/org/ice4j/ice/Candidate.java @@ -57,7 +57,7 @@ public abstract class Candidate * a base, equal to that candidate itself. Similarly, the base of a * relayed candidate is that candidate itself. */ - private Candidate base = null; + private LocalCandidate base = null; /** * A unique priority number that MUST be a positive integer between 1 and @@ -206,7 +206,7 @@ public abstract class Candidate * * @return the base Candidate for this Candidate. */ - public Candidate getBase() + public LocalCandidate getBase() { return base; } @@ -220,7 +220,7 @@ public abstract class Candidate * * @param base the base Candidate of this Candidate. */ - public void setBase(Candidate base) + public void setBase(LocalCandidate base) { this.base = base; } diff --git a/src/org/ice4j/ice/CandidatePair.java b/src/org/ice4j/ice/CandidatePair.java index 5a2773b..8b4d8b5 100644 --- a/src/org/ice4j/ice/CandidatePair.java +++ b/src/org/ice4j/ice/CandidatePair.java @@ -6,6 +6,7 @@ */ package org.ice4j.ice; +import java.util.*; import java.util.logging.*; /** @@ -32,18 +33,24 @@ public class CandidatePair /** * The local candidate of this pair. */ - private final LocalCandidate localCandidate; + private LocalCandidate localCandidate; /** * The remote candidate of this pair. */ - private final Candidate remoteCandidate; + private Candidate remoteCandidate; /** * Priority of the candidate-pair */ private final long priority; + /** + * A Comparator using the compareTo method of the + * CandidatePair. + */ + public static final PairComparator comparator = new PairComparator(); + /** * Each candidate pair has a a state that is assigned once the check list * for each media stream has been computed. The ICE RFC defines five @@ -98,6 +105,17 @@ public class CandidatePair return localCandidate; } + /** + * Sets the LocalCandidate of this CandidatePair. + * + * @param localCnd the local Candidate of this + * CandidatePair. + */ + protected void setLocalCandidate( LocalCandidate localCnd) + { + this.localCandidate = localCnd;; + } + /** * Returns the remote candidate of this CandidatePair. * @@ -108,6 +126,17 @@ public class CandidatePair return remoteCandidate; } + /** + * Sets the RemoteCandidate of this CandidatePair. + * + * @param remoteCnd the local Candidate of this + * CandidatePair. + */ + protected void setRemoteCandidate( Candidate remoteCnd) + { + this.remoteCandidate = remoteCnd;; + } + /** * Returns the state of this CandidatePair. Each candidate pair has * a state that is assigned once the check list for each media stream has @@ -218,20 +247,52 @@ public class CandidatePair /** * Compares this CandidatePair with the specified object for order. * Returns a negative integer, zero, or a positive integer as this - * CandidatePair is less than, equal to, or greater than the - * specified object.
+ * CandidatePair's priority is greater than, equal to, or less than + * the one of the specified object thus insuring that higher priority pairs + * will come first.
*
* @param candidatePair the Object to be compared.
* @return a negative integer, zero, or a positive integer as this
- * CandidatePair is less than, equal to, or greater than the
- * specified object.
+ * CandidatePair's priority is greater than, equal to, or less than
+ * the one of the specified object.
*
* @throws ClassCastException if the specified object's type prevents it
* from being compared to this Object.
*/
public int compareTo(CandidatePair candidatePair)
{
- return (int)(getPriority() - candidatePair.getPriority());
+ long thisPri = getPriority();
+ long otherPri = candidatePair.getPriority();
+
+ return (thisPri < otherPri
+ ? 1
+ : (thisPri==otherPri
+ ? 0
+ : -1));
+ }
+
+ /**
+ * Compares this CandidatePair to targetPair and returns
+ * true if pairs have equal local and equal remote candidates and
+ * false otherwise.
+ *
+ * @param targetPair the Object that we'd like to compare this
+ * target pair to.
+ *
+ * @return true if pairs have equal local and equal remote
+ * candidates and false otherwise.
+ */
+ public boolean equals(Object targetPair)
+ {
+ if (! (targetPair instanceof CandidatePair)
+ || targetPair == null
+ || !localCandidate.equals(((CandidatePair)targetPair)
+ .localCandidate)
+ || !remoteCandidate.equals(((CandidatePair)targetPair)
+ .remoteCandidate))
+ return false;
+
+ return true;
}
/**
@@ -246,4 +307,59 @@ public class CandidatePair
+ "):\n\tLocalCandidate=" + getLocalCandidate()
+ "\n\tRemoteCandidate=" + getRemoteCandidate();
}
+
+ /**
+ * A Comparator using the compareTo method of the
+ * CandidatePair
+ */
+ public static class PairComparator implements Comparator
+ *
+ * Note that it is always safe not to override
+ * Object.equals(Object). However, overriding this method may,
+ * in some cases, improve performance by allowing programs to determine
+ * that two distinct Comparators impose the same order.
+ *
+ * @param obj the reference object with which to compare.
+ * @return comp1.equals(comp2) implies that sgn(comp1.compare(o1,
+ * o2))==sgn(comp2.compare(o1, o2)) for every object reference
+ * o1 and o2.true only if the specified object is also
+ * a comparator and it imposes the same ordering as this
+ * comparator.
+ * @see java.lang.Object#equals(java.lang.Object)
+ * @see java.lang.Object#hashCode()
+ */
+ public boolean equals(Object obj)
+ {
+ return obj instanceof PairComparator;
+ }
+ }
}
diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java
index 7463fe1..8b05fcd 100644
--- a/src/org/ice4j/ice/IceMediaStream.java
+++ b/src/org/ice4j/ice/IceMediaStream.java
@@ -54,6 +54,18 @@ public class IceMediaStream
private final List