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 String getReference1() {
054 return reference1;
055 }
056
057 /**
058 * Set first formula reference.
059 *
060 * @param reference1 Reference to formula.
061 */
062 public void setReference1(final String reference1) {
063 this.reference1 = reference1;
064 }
065
066 public String getReference2() {
067 return reference2;
068 }
069
070 /**
071 * Set second formula reference.
072 *
073 * @param reference2 Reference to formula.
074 */
075 public void setReference2(final String reference2) {
076 this.reference2 = reference2;
077 }
078
079 public String[] getReferences() {
080 if (reference1 == null || reference1.length() == 0) {
081 if (reference2 == null || reference2.length() == 0) {
082 return new String[] {};
083 } else {
084 return new String[] {reference2 };
085 }
086 } else {
087 if (reference2 == null || reference2.length() == 0) {
088 return new String[] {reference1 };
089 } else {
090 return new String[] {reference1, reference2 };
091 }
092 }
093 }
094
095 public boolean equals(final Object obj) {
096 if (!(obj instanceof ModusPonens)) {
097 return false;
098 }
099 final ModusPonens other = (ModusPonens) obj;
100 return EqualsUtility.equals(getReference1(), other.getReference1())
101 && EqualsUtility.equals(getReference2(), other.getReference2());
102 }
103
104 public int hashCode() {
105 return (getReference1() != null ? getReference1().hashCode() : 0)
106 + (getReference2() != null ? 1 ^ getReference2().hashCode() : 0);
107 }
108
109 public String toString() {
110 StringBuffer result = new StringBuffer();
111 result.append("MP");
112 if (getReference1() != null || getReference2() != null) {
113 result.append(" (");
114 if (getReference1() != null) {
115 result.append(getReference1());
116 }
117 if (getReference2() != null) {
118 if (getReference1() != null) {
119 result.append(", ");
120 }
121 result.append(getReference2());
122 }
123 result.append(")");
124 }
125 return result.toString();
126 }
127
128 public String getName() {
129 return "MP";
130 }
131
132 }
|