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.bo.logic.model;
017
018 /**
019 * One function for our model.
020 *
021 * @author Michael Meyling
022 */
023 public abstract class Function {
024
025
026 /** Minimum number of arguments this function has. */
027 private final int minimum;
028
029 /** Maximum number of arguments this function has. */
030 private final int maximum;
031
032 /** Display text. */
033 private final String display;
034
035 /** Description for this function. */
036 private final String description;
037
038 static Function createConstant(final Entity entity) {
039 return new Function(0, 90, "->" + entity, "contant " + entity.getDescription()) {
040 public Entity map(final Entity[] entities) {
041 return entity;
042 }
043 };
044 }
045
046 /**
047 * Constructor.
048 *
049 * @param minimum Minimum number of arguments this function has.
050 * @param maximum Maximum number of arguments this function has.
051 * @param display Show this to represent the function within outputs.
052 * @param description Description for this function.
053 */
054 public Function(final int minimum, final int maximum, final String display,
055 final String description) {
056 this.minimum = minimum;
057 this.maximum = maximum;
058 this.display = display;
059 this.description = description;
060 }
061
062 /**
063 * Get minimum number of arguments this function has.
064 *
065 * @return Minimum number of arguments for this function.
066 */
067 public int getMinimumArgumentNumber() {
068 return minimum;
069 }
070
071 /**
072 * Get maximum number of arguments this function has.
073 *
074 * @return Maximum number of arguments for this function.
075 */
076 public int getMaximumArgumentNumber() {
077 return maximum;
078 }
079
080 /**
081 * Get display text.
082 *
083 * @return Representation of this function for textual output.
084 */
085 public String toString() {
086 return display;
087 }
088
089 /**
090 * Get description.
091 *
092 * @return Description of this function.
093 */
094 public String getDescription() {
095 return description;
096 }
097
098 /**
099 * Calculate truth value.
100 *
101 * @param entities Calculate function for this entities.
102 * @return Truth value.
103 */
104 public abstract Entity map(Entity[] entities);
105
106 }
|