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.bo.logic.model; |
17 | |
18 | /** |
19 | * One function for our model. |
20 | * |
21 | * @author Michael Meyling |
22 | */ |
23 | public abstract class Function { |
24 | |
25 | |
26 | /** Minimum number of arguments this function has. */ |
27 | private final int minimum; |
28 | |
29 | /** Maximum number of arguments this function has. */ |
30 | private final int maximum; |
31 | |
32 | /** Display text. */ |
33 | private final String display; |
34 | |
35 | /** Description for this function. */ |
36 | private final String description; |
37 | |
38 | static Function createConstant(final Entity entity) { |
39 | return new Function(0, 90, "->" + entity, "contant " + entity.getDescription()) { |
40 | public Entity map(final Entity[] entities) { |
41 | return entity; |
42 | } |
43 | }; |
44 | } |
45 | |
46 | /** |
47 | * Constructor. |
48 | * |
49 | * @param minimum Minimum number of arguments this function has. |
50 | * @param maximum Maximum number of arguments this function has. |
51 | * @param display Show this to represent the function within outputs. |
52 | * @param description Description for this function. |
53 | */ |
54 | public Function(final int minimum, final int maximum, final String display, |
55 | final String description) { |
56 | this.minimum = minimum; |
57 | this.maximum = maximum; |
58 | this.display = display; |
59 | this.description = description; |
60 | } |
61 | |
62 | /** |
63 | * Get minimum number of arguments this function has. |
64 | * |
65 | * @return Minimum number of arguments for this function. |
66 | */ |
67 | public int getMinimumArgumentNumber() { |
68 | return minimum; |
69 | } |
70 | |
71 | /** |
72 | * Get maximum number of arguments this function has. |
73 | * |
74 | * @return Maximum number of arguments for this function. |
75 | */ |
76 | public int getMaximumArgumentNumber() { |
77 | return maximum; |
78 | } |
79 | |
80 | /** |
81 | * Get display text. |
82 | * |
83 | * @return Representation of this function for textual output. |
84 | */ |
85 | public String toString() { |
86 | return display; |
87 | } |
88 | |
89 | /** |
90 | * Get description. |
91 | * |
92 | * @return Description of this function. |
93 | */ |
94 | public String getDescription() { |
95 | return description; |
96 | } |
97 | |
98 | /** |
99 | * 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 | } |