001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.kernel.se.dto.module;
017
018 import org.apache.commons.lang.ArrayUtils;
019 import org.qedeq.base.utility.EqualsUtility;
020 import org.qedeq.kernel.se.base.module.ModusPonens;
021
022
023 /**
024 * Modes Ponens usage.
025 *
026 * @author Michael Meyling
027 */
028 public class ModusPonensVo implements ModusPonens {
029
030 /** Usually reference to a formula like A -> B. */
031 private String reference1;
032
033 /** Usually reference to a formula like A. */
034 private String reference2;
035
036 /**
037 * Constructs a Modus Ponens argument.
038 *
039 * @param reference1 Usually reference to a formula like A -> B. Might be <code>null</code>.
040 * @param reference2 Usually reference to a formula like A. Might be <code>null</code>.
041 */
042 public ModusPonensVo(final String reference1, final String reference2) {
043 this.reference1 = reference1;
044 this.reference2 = reference2;
045 }
046
047 /**
048 * Default constructor.
049 */
050 public ModusPonensVo() {
051 // nothing to do
052 }
053
054 public ModusPonens getModusPonens() {
055 return this;
056 }
057
058 public String getReference1() {
059 return reference1;
060 }
061
062 /**
063 * Set first formula reference.
064 *
065 * @param reference1 Reference to formula. Might be <code>null</code>.
066 */
067 public void setReference1(final String reference1) {
068 this.reference1 = reference1;
069 }
070
071 public String getReference2() {
072 return reference2;
073 }
074
075 /**
076 * Set second formula reference.
077 *
078 * @param reference2 Reference to formula. Might be <code>null</code>.
079 */
080 public void setReference2(final String reference2) {
081 this.reference2 = reference2;
082 }
083
084 public String[] getReferences() {
085 if (reference1 == null) {
086 if (reference2 == null) {
087 return ArrayUtils.EMPTY_STRING_ARRAY;
088 } else {
089 return new String[] {reference2 };
090 }
091 } else {
092 if (reference2 == null) {
093 return new String[] {reference1 };
094 } else {
095 return new String[] {reference1, reference2 };
096 }
097 }
098 }
099
100 public boolean equals(final Object obj) {
101 if (!(obj instanceof ModusPonens)) {
102 return false;
103 }
104 final ModusPonens other = (ModusPonens) obj;
105 return EqualsUtility.equals(getReference1(), other.getReference1())
106 && EqualsUtility.equals(getReference2(), other.getReference2());
107 }
108
109 public int hashCode() {
110 return (getReference1() != null ? getReference1().hashCode() : 0)
111 + (getReference2() != null ? 1 ^ getReference2().hashCode() : 0);
112 }
113
114 public String toString() {
115 StringBuffer result = new StringBuffer();
116 result.append(getName());
117 if (getReference1() != null || getReference2() != null) {
118 result.append(" (");
119 if (getReference1() != null) {
120 result.append(getReference1());
121 }
122 if (getReference2() != null) {
123 if (getReference1() != null) {
124 result.append(", ");
125 }
126 result.append(getReference2());
127 }
128 result.append(")");
129 }
130 return result.toString();
131 }
132
133 public String getName() {
134 return "MP";
135 }
136
137 }
|