| 11 | package clojure.lang; |
| 12 | |
| 13 | public class TaggedLiteral implements ILookup { |
| 14 | |
| 15 | public static final Keyword TAG_KW = Keyword.intern("tag"); |
| 16 | public static final Keyword FORM_KW = Keyword.intern("form"); |
| 17 | |
| 18 | public final Symbol tag; |
| 19 | public final Object form; |
| 20 | |
| 21 | public static TaggedLiteral create(Symbol tag, Object form) { |
| 22 | return new TaggedLiteral(tag, form); |
| 23 | } |
| 24 | |
| 25 | private TaggedLiteral(Symbol tag, Object form){ |
| 26 | this.tag = tag; |
| 27 | this.form = form; |
| 28 | } |
| 29 | |
| 30 | public Object valAt(Object key) { |
| 31 | return valAt(key, null); |
| 32 | } |
| 33 | |
| 34 | public Object valAt(Object key, Object notFound) { |
| 35 | if (FORM_KW.equals(key)) { |
| 36 | return this.form; |
| 37 | } else if (TAG_KW.equals(key)) { |
| 38 | return this.tag; |
| 39 | } else { |
| 40 | return notFound; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public boolean equals(Object o) { |
| 46 | if (this == o) return true; |
| 47 | if (o == null || getClass() != o.getClass()) return false; |
| 48 | |
| 49 | TaggedLiteral that = (TaggedLiteral) o; |
| 50 | |
| 51 | if (form != null ? !form.equals(that.form) : that.form != null) return false; |
| 52 | if (tag != null ? !tag.equals(that.tag) : that.tag != null) return false; |
| 53 | |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | int result = Util.hash(tag); |
| 60 | result = 31 * result + Util.hash(form); |
| 61 | return result; |
| 62 | } |
| 63 | |
| 64 | } |