What follows is the highlighted source code with comments. You can also download this file directly: FiniteCyclicGroup.java.
/* * This work by W. Patrick Hooper is free of known copyright restrictions. * The work is in the public domain. * * Author's website: <a href="http://wphooper.com">http://wphooper.com</a>. */ package finitecyclicgroup; /** * * @author pat */ public class FiniteCyclicGroup { private final int n; /** * Construct the finite cyclic group of size n. * * @param n The number of elements in the cyclic group. */ public FiniteCyclicGroup(int n){ this.n=n; } public int getSize() { return n; } public FiniteCyclicGroupElement convert(int value) { return new FiniteCyclicGroupElement(this, value); } public FiniteCyclicGroupElement add(Number t1, Number t2) { return new FiniteCyclicGroupElement(this, t1.intValue()+t2.intValue()); } public FiniteCyclicGroupElement subtract(Number t1, Number t2) { return new FiniteCyclicGroupElement(this, t1.intValue()-t2.intValue()); } public FiniteCyclicGroupElement negate(Number t) { return new FiniteCyclicGroupElement(this, -t.intValue()); } public FiniteCyclicGroupElement zero() { return new FiniteCyclicGroupElement(this, 0); } public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final FiniteCyclicGroup other = (FiniteCyclicGroup) obj; if (this.n != other.n) { return false; } return true; } public int hashCode() { int hash = 7; hash = 11 * hash + this.n; return hash; } }