@NotNull private static String toString(@NotNull OtpErlangTuple quoted) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("{"); for (int i = 0; i < quoted.arity(); i++) { if (i > 0) { stringBuilder.append(","); } stringBuilder.append(toString(quoted.elementAt(i))); } stringBuilder.append("}"); return stringBuilder.toString(); } }
private static void renderTuple(OtpErlangTuple tuple, XValueTextRenderer renderer) { int i; renderer.renderSpecialSymbol("{"); for (i = 0; i < tuple.arity(); i++) { if (i > 0) { renderer.renderSpecialSymbol(", "); } renderObject(tuple.elementAt(i), renderer); } renderer.renderSpecialSymbol("}"); }
/** * Get the specified element from the tuple. * * @param i * the index of the requested element. Tuple elements are * numbered as array elements, starting at 0. * * @return the requested element, of null if i is not a valid element index. */ public OtpErlangObject elementAt(final int i) { if (i >= arity() || i < 0) { return null; } return elems[i]; }
/** * Get all the elements from the tuple as an array. * * @return an array containing all of the tuple's elements. */ public OtpErlangObject[] elements() { final OtpErlangObject[] res = new OtpErlangObject[arity()]; System.arraycopy(elems, 0, res, 0, res.length); return res; }
/** * Determine if two tuples are equal. Tuples are equal if they have the same * arity and all of the elements are equal. * * @param o * the tuple to compare to. * * @return true if the tuples have the same arity and all the elements are * equal. */ @Override public boolean equals(final Object o) { if (!(o instanceof OtpErlangTuple)) { return false; } final OtpErlangTuple t = (OtpErlangTuple) o; final int a = arity(); if (a != t.arity()) { return false; } for (int i = 0; i < a; i++) { if (!elems[i].equals(t.elems[i])) { return false; // early exit } } return true; }
if (t.arity() == 2) { return t.elementAt(1); // obs: second element
@Override protected int doHashCode() { final OtpErlangObject.Hash hash = new OtpErlangObject.Hash(9); final int a = arity(); hash.combine(a); for (int i = 0; i < a; i++) { hash.combine(elems[i].hashCode()); } return hash.valueOf(); }