[utilities COMMIT] /java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java
noreply at shibboleth.net
noreply at shibboleth.net
Mon Mar 19 11:25:49 GMT 2012
Author: lajoie
Date: Mon Mar 19 11:25:49 2012
New Revision: 248
URL: http://svn.shibboleth.net/view/utilities?rev=248&view=rev
Log:
Annotate constraints
Add default and copy constructor
Modified:
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java
Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java?rev=248&r1=247&r2=248&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java Mon Mar 19 11:25:49 2012
@@ -17,6 +17,9 @@
package net.shibboleth.utilities.java.support.collection;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import com.google.common.base.Objects;
/**
@@ -33,15 +36,31 @@
/** Second object in pair. */
private T2 second;
+ /** Constructor. */
+ public Pair() {
+
+ }
+
/**
* Constructor.
*
* @param newFirst first object in the pair
* @param newSecond second object in the pair
*/
- public Pair(final T1 newFirst, final T2 newSecond) {
+ public Pair(@Nullable final T1 newFirst, @Nullable final T2 newSecond) {
first = newFirst;
second = newSecond;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param pair pair to be copied
+ */
+ public Pair(@Nonnull Pair<? extends T1, ? extends T2> pair) {
+ assert pair != null : "Pair to be copied can not be null";
+ first = pair.getFirst();
+ second = pair.getSecond();
}
/**
@@ -49,7 +68,7 @@
*
* @return first object in the pair
*/
- public T1 getFirst() {
+ @Nullable public T1 getFirst() {
return first;
}
@@ -58,7 +77,7 @@
*
* @param newFirst first object in the pair
*/
- public void setFirst(final T1 newFirst) {
+ public void setFirst(@Nullable final T1 newFirst) {
first = newFirst;
}
@@ -67,7 +86,7 @@
*
* @return second object in the pair
*/
- public T2 getSecond() {
+ @Nullable public T2 getSecond() {
return second;
}
@@ -76,12 +95,12 @@
*
* @param newSecond second object in the pair
*/
- public void setSecond(final T2 newSecond) {
+ public void setSecond(@Nullable final T2 newSecond) {
second = newSecond;
}
/** {@inheritDoc} */
- @SuppressWarnings("unchecked") public boolean equals(Object o) {
+ public boolean equals(@Nullable final Object o) {
if (o == this) {
return true;
}
@@ -100,7 +119,7 @@
}
/** {@inheritDoc} */
- public String toString() {
- return "(" + getFirst() + "," + getSecond() + ")";
+ @Nonnull public String toString() {
+ return Objects.toStringHelper(this).add("first", first).add("second", second).toString();
}
}
More information about the commits
mailing list