diff --git a/src/com/massivecraft/mcore/Couple.java b/src/com/massivecraft/mcore/Couple.java new file mode 100644 index 00000000..99daefbc --- /dev/null +++ b/src/com/massivecraft/mcore/Couple.java @@ -0,0 +1,99 @@ +package com.massivecraft.mcore; + +import java.io.Serializable; +import java.util.Map.Entry; + +import com.massivecraft.mcore.util.MUtil; + +public class Couple implements Entry, Cloneable, Serializable +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + private static final transient long serialVersionUID = 1L; + + // -------------------------------------------- // + // FIELDS: RAW + // -------------------------------------------- // + + private final A first; + public A getFirst() { return this.first; }; + + private final B second; + public B getSecond() { return this.second; }; + + // -------------------------------------------- // + // FIELDS: WITH + // -------------------------------------------- // + + public Couple withFirst(A first) { return valueOf(first, second); } + + public Couple withSecond(B second) { return valueOf(first, second); } + + // -------------------------------------------- // + // PRIVATE CONSTRUCTOR + // -------------------------------------------- // + + private Couple(A first, B second) + { + this.first = first; + this.second = second; + } + + // -------------------------------------------- // + // OVERRIDE: ENTRY + // -------------------------------------------- // + + @Override + public A getKey() + { + return this.first; + } + + @Override + public B getValue() + { + return this.second; + } + + @Override + public B setValue(B arg0) + { + throw new IllegalStateException("This entry is a couple which is immutable."); + } + + // -------------------------------------------- // + // FACTORY: VALUE OF + // -------------------------------------------- // + + public static Couple valueOf(A first, B second) + { + return new Couple(first, second); + } + + // -------------------------------------------- // + // EQUALS + // -------------------------------------------- // + + @Override + public boolean equals(Object derpObject) + { + if (derpObject == null) return false; + if (!(derpObject instanceof Couple)) return false; + Couple derp = (Couple)derpObject; + return MUtil.equals(this.getFirst(), derp.getFirst()) && MUtil.equals(this.getSecond(), derp.getSecond()); + } + + // -------------------------------------------- // + // CLONE + // -------------------------------------------- // + + @Override + public Couple clone() + { + return this; + } + + +}