Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.skipifzero.superiority.utils;
- import com.google.common.base.Objects;
- /**
- * <p>Oh Oracle, why do thy smite me with lack of pass-by-reference?<br/>
- * I shallt redeem this injustice with providing me with C++ goodies.</p>
- *
- * @author Centril<twingoow@gmail.com> / Mazdak Farrokhzad.
- * @since 28 apr 2013
- * @version 1.0
- * @see http://stackoverflow.com/questions/430479/how-do-i-use-an-equivalent-to-c-reference-parameters-in-java
- */
- public final class _<E> {
- private E ref;
- /**
- * Constructs the reference with null as value.
- */
- public _() {
- }
- /**
- * Constructs the reference with initial value.<br/>
- * Null is allowed.
- *
- * @param value the value to set.
- */
- public _( E value ) {
- this.ref = value;
- }
- /**
- * Returns the value of the reference.
- *
- * @return the value of the reference.
- */
- public E r() {
- return this.ref;
- }
- /**
- * Sets the value of the reference.
- *
- * @param value the value to set.
- */
- public void r( E value ) {
- this.ref = value;
- }
- /**
- * The given obj is equal to this iff one of the following:<br/>
- * this == obj, the {@link #r()} equals obj.r() if obj instanceof {@link _},<br/>
- * or if {@link #r()} equals obj.
- */
- public boolean equals( Object obj ) {
- return this == obj || (obj != null && obj instanceof _
- ? Objects.equal( this.r(), ((_<?>) obj).r() )
- : Objects.equal( this.r(), obj ));
- }
- /**
- * If {@link #r()} == null => 0,<br/>
- * otherwise the hashcode of {@link #r()}.
- */
- @Override
- public int hashCode() {
- return this.r() == null ? 0 : this.r().hashCode();
- }
- /**
- * Relays to the values toString method.
- *
- * @return the value as string.
- */
- public String toString() {
- return ref.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement