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