001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2011, 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.qedeq.base.utility.EqualsUtility;
019 import org.qedeq.kernel.se.base.module.ModusPonens;
020
021
022 /**
023 * Modes Ponens usage.
024 *
025 * @author Michael Meyling
026 */
027 public class ModusPonensVo implements ModusPonens {
028
029 /** Usually reference to a formula like A -> B. */
030 private String reference1;
031
032 /** Usually reference to a formula like A. */
033 private String reference2;
034
035 /**
036 * Constructs a Modus Ponens argument.
037 *
038 * @param reference1 Usually reference to a formula like A -> B.
039 * @param reference2 Usually reference to a formula like A.
040 */
041 public ModusPonensVo(final String reference1, final String reference2) {
042 this.reference1 = reference1;
043 this.reference2 = reference2;
044 }
045
046 /**
047 * Default constructor.
048 */
049 public ModusPonensVo() {
050 // nothing to do
051 }
052
053 public ModusPonens getModusPonens() {
054 return this;
055 }
056
057 public String getReference1() {
058 return reference1;
059 }
060
061 /**
062 * Set first formula reference.
063 *
064 * @param reference1 Reference to formula.
065 */
066 public void setReference1(final String reference1) {
067 this.reference1 = reference1;
068 }
069
070 public String getReference2() {
071 return reference2;
072 }
073
074 /**
075 * Set second formula reference.
076 *
077 * @param reference2 Reference to formula.
078 */
079 public void setReference2(final String reference2) {
080 this.reference2 = reference2;
081 }
082
083 public String[] getReferences() {
084 if (reference1 == null || reference1.length() == 0) {
085 if (reference2 == null || reference2.length() == 0) {
086 return new String[] {};
087 } else {
088 return new String[] {reference2 };
089 }
090 } else {
091 if (reference2 == null || reference2.length() == 0) {
092 return new String[] {reference1 };
093 } else {
094 return new String[] {reference1, reference2 };
095 }
096 }
097 }
098
099 public boolean equals(final Object obj) {
100 if (!(obj instanceof ModusPonens)) {
101 return false;
102 }
103 final ModusPonens other = (ModusPonens) obj;
104 return EqualsUtility.equals(getReference1(), other.getReference1())
105 && EqualsUtility.equals(getReference2(), other.getReference2());
106 }
107
108 public int hashCode() {
109 return (getReference1() != null ? getReference1().hashCode() : 0)
110 + (getReference2() != null ? 1 ^ getReference2().hashCode() : 0);
111 }
112
113 public String toString() {
114 StringBuffer result = new StringBuffer();
115 result.append("MP");
116 if (getReference1() != null || getReference2() != null) {
117 result.append(" (");
118 if (getReference1() != null) {
119 result.append(getReference1());
120 }
121 if (getReference2() != null) {
122 if (getReference1() != null) {
123 result.append(", ");
124 }
125 result.append(getReference2());
126 }
127 result.append(")");
128 }
129 return result.toString();
130 }
131
132 public String getName() {
133 return "MP";
134 }
135
136 }
|