1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org |
2 | * |
3 | * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. |
4 | * |
5 | * "Hilbert II" is free software; you can redistribute |
6 | * it and/or modify it under the terms of the GNU General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | */ |
15 | |
16 | package org.qedeq.kernel.se.dto.module; |
17 | |
18 | import org.apache.commons.lang.ArrayUtils; |
19 | import org.qedeq.base.utility.EqualsUtility; |
20 | import org.qedeq.kernel.se.base.module.ModusPonens; |
21 | |
22 | |
23 | /** |
24 | * Modes Ponens usage. |
25 | * |
26 | * @author Michael Meyling |
27 | */ |
28 | public class ModusPonensVo implements ModusPonens { |
29 | |
30 | /** Usually reference to a formula like A -> B. */ |
31 | private String reference1; |
32 | |
33 | /** Usually reference to a formula like A. */ |
34 | private String reference2; |
35 | |
36 | /** |
37 | * Constructs a Modus Ponens argument. |
38 | * |
39 | * @param reference1 Usually reference to a formula like A -> B. Might be <code>null</code>. |
40 | * @param reference2 Usually reference to a formula like A. Might be <code>null</code>. |
41 | */ |
42 | public ModusPonensVo(final String reference1, final String reference2) { |
43 | this.reference1 = reference1; |
44 | this.reference2 = reference2; |
45 | } |
46 | |
47 | /** |
48 | * Default constructor. |
49 | */ |
50 | public ModusPonensVo() { |
51 | // nothing to do |
52 | } |
53 | |
54 | public ModusPonens getModusPonens() { |
55 | return this; |
56 | } |
57 | |
58 | public String getReference1() { |
59 | return reference1; |
60 | } |
61 | |
62 | /** |
63 | * Set first formula reference. |
64 | * |
65 | * @param reference1 Reference to formula. Might be <code>null</code>. |
66 | */ |
67 | public void setReference1(final String reference1) { |
68 | this.reference1 = reference1; |
69 | } |
70 | |
71 | public String getReference2() { |
72 | return reference2; |
73 | } |
74 | |
75 | /** |
76 | * Set second formula reference. |
77 | * |
78 | * @param reference2 Reference to formula. Might be <code>null</code>. |
79 | */ |
80 | public void setReference2(final String reference2) { |
81 | this.reference2 = reference2; |
82 | } |
83 | |
84 | public String[] getReferences() { |
85 | if (reference1 == null) { |
86 | if (reference2 == null) { |
87 | return ArrayUtils.EMPTY_STRING_ARRAY; |
88 | } |
89 | return new String[] {reference2 }; |
90 | } |
91 | if (reference2 == null) { |
92 | return new String[] {reference1 }; |
93 | } |
94 | return new String[] {reference1, reference2 }; |
95 | } |
96 | |
97 | public boolean equals(final Object obj) { |
98 | if (!(obj instanceof ModusPonens)) { |
99 | return false; |
100 | } |
101 | final ModusPonens other = (ModusPonens) obj; |
102 | return EqualsUtility.equals(getReference1(), other.getReference1()) |
103 | && EqualsUtility.equals(getReference2(), other.getReference2()); |
104 | } |
105 | |
106 | public int hashCode() { |
107 | return (getReference1() != null ? getReference1().hashCode() : 0) |
108 | + (getReference2() != null ? 1 ^ getReference2().hashCode() : 0); |
109 | } |
110 | |
111 | public String toString() { |
112 | StringBuffer result = new StringBuffer(); |
113 | result.append(getName()); |
114 | if (getReference1() != null || getReference2() != null) { |
115 | result.append(" ("); |
116 | if (getReference1() != null) { |
117 | result.append(getReference1()); |
118 | } |
119 | if (getReference2() != null) { |
120 | if (getReference1() != null) { |
121 | result.append(", "); |
122 | } |
123 | result.append(getReference2()); |
124 | } |
125 | result.append(")"); |
126 | } |
127 | return result.toString(); |
128 | } |
129 | |
130 | public String getName() { |
131 | return "MP"; |
132 | } |
133 | |
134 | } |