/** * Receives a list of tuples and returns the first tuple where the item at {@code position} in the tuple matches the * given {@code item}. * * @param tupleList List of tuples. Tuples don't all have to be the same size or have position as a valid offset. * @param key key to search for at * @param position position of the * @param defaultValue * @return tuple with equal {@code key} or {@code defaultValue} if {@code key} is not found. */ public static OtpErlangObject keyfind(OtpErlangList tupleList, OtpErlangObject key, int position, OtpErlangObject defaultValue) { OtpErlangObject matchTuple = defaultValue; for (OtpErlangObject element : tupleList) { OtpErlangTuple tuple = (OtpErlangTuple) element; if (tuple.elementAt(position).equals(key)) { matchTuple = tuple; break; } } return matchTuple; } }
@Nullable public static OtpErlangPid whereis(OtpMbox localMbox, OtpNode localNode, String remoteName, String remoteNode, int timeout) throws OtpErlangExit, OtpErlangDecodeException { OtpErlangObject response = RPC.INSTANCE.unmonitoredCall( remoteNode, localMbox, localNode, timeout, new OtpErlangAtom("Elixir.Process"), new OtpErlangAtom("whereis"), new OtpErlangAtom(remoteName) ); OtpErlangPid pid; if (response instanceof OtpErlangAtom) { if (response.equals(NIL)) { pid = null; } else { throw new NotImplementedException("Expected atoms to be nil, but got" + response); } } else { pid = (OtpErlangPid) response; } return pid; } }
private static void assertQuotedCorrectly(@NotNull OtpErlangObject expectedQuoted, @NotNull OtpErlangObject actualQuoted) { if (!expectedQuoted.equals(actualQuoted)) { throw new ComparisonFailure(null, toString(expectedQuoted), toString(actualQuoted)); } }
/** * Perform match operation against given term. * * @param term * the object to match * @param binds * variable bindings * @return true if match succeeded */ public <T> boolean match(final OtpErlangObject term, final T binds) { return equals(term); }
/** * 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; }
val = e.getValue(); final OtpErlangObject v = t.get(key); if (v == null || !val.equals(v)) { return false;