Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
63   194   19   3.94
6   122   0.3   16
16     1.19  
1    
 
  UnaryModel       Line # 29 63 19 95.3% 0.9529412
 
  (49)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, 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    import java.util.ArrayList;
19    import java.util.HashMap;
20    import java.util.List;
21    import java.util.Map;
22   
23   
24    /**
25    * A model for our mathematical world. It has only one entity.
26    *
27    * @author Michael Meyling
28    */
 
29    public final class UnaryModel implements Model {
30   
31    /** "Zero" or empty class. */
32    public static final Entity ZERO = new Entity(0, "0", "{} or empty set");
33   
34    /** Map to zero. */
35    public static final Function FUNCTION_ZERO = new Function(0, 99, "->0", "always 0") {
 
36  277 toggle public Entity map(final Entity[] entities) {
37  277 return ZERO;
38    }
39    };
40   
41    /** Always return false. */
42    public static final Predicate FALSE = new Predicate(0, 99, "F", "always false") {
 
43  8987 toggle public boolean calculate(final Entity[] entities) {
44  8987 return false;
45    }
46    };
47   
48    /** Always return true. */
49    public static final Predicate TRUE = new Predicate(0, 99, "T", "always true") {
 
50  8871 toggle public boolean calculate(final Entity[] entities) {
51  8871 return true;
52    }
53    };
54   
55    /** Are the entities ordered by < ? */
56    public static final Predicate LESS = new Predicate(0, 99, "<", "less") {
 
57  76 toggle public boolean calculate(final Entity[] entities) {
58  76 boolean result = true;
59  152 for (int i = 0; i < entities.length - 1; i++) {
60  76 result &= entities[i].getValue() < entities[i + 1].getValue();
61    }
62  76 return result;
63    }
64    };
65   
66    /** Are the entities not ordered by < ? */
67    public static final Predicate NOT_LESS = Predicate.not(LESS);
68   
69    /** Are the entities are all the same? */
70    public static final Predicate EQUAL = new Predicate(0, 99, "=", "equal") {
 
71  224 toggle public boolean calculate(final Entity[] entities) {
72  224 boolean result = true;
73  448 for (int i = 0; i < entities.length - 1; i++) {
74  224 result &= entities[i].getValue() == entities[i + 1].getValue();
75    }
76  224 return result;
77    }
78    };
79   
80    /** Are the entities are not all the same? */
81    public static final Predicate NOT_EQUAL = Predicate.not(EQUAL);
82   
83    /** List of all entities in this model. */
84    private final List entities;
85   
86    /** List of functions for different argument numbers. */
87    private final List functionPool;
88   
89    /** List of predicates for different argument numbers. */
90    private final List predicatePool;
91   
92    /** Map of predicate constants. */
93    private final Map predicateConstants;
94   
95    /**
96    * Constructor.
97    */
 
98  51 toggle public UnaryModel() {
99  51 entities = new ArrayList();
100  51 entities.add(ZERO);
101   
102  51 functionPool = new ArrayList();
103   
104  51 final List function0 = new ArrayList();
105  51 functionPool.add(function0);
106  51 function0.add(FUNCTION_ZERO);
107   
108  51 final List function1 = new ArrayList();
109  51 functionPool.add(function1);
110  51 function1.add(FUNCTION_ZERO);
111   
112  51 final List function2 = new ArrayList();
113  51 functionPool.add(function2);
114  51 function2.add(FUNCTION_ZERO);
115   
116  51 predicatePool = new ArrayList();
117   
118  51 final List predicate0 = new ArrayList();
119  51 predicatePool.add(predicate0);
120  51 predicate0.add(FALSE);
121  51 predicate0.add(TRUE);
122   
123  51 final List predicate1 = new ArrayList();
124  51 predicatePool.add(predicate1);
125  51 predicate1.add(FALSE);
126  51 predicate1.add(TRUE);
127   
128  51 final List predicate2 = new ArrayList();
129  51 predicatePool.add(predicate2);
130  51 predicate2.add(FALSE);
131  51 predicate2.add(TRUE);
132  51 predicate2.add(LESS);
133  51 predicate2.add(EQUAL);
134   
135  51 predicateConstants = new HashMap();
136  51 predicateConstants.put(new ModelPredicateConstant("TRUE", 0), TRUE);
137  51 predicateConstants.put(new ModelPredicateConstant("FALSE", 0), FALSE);
138  51 predicateConstants.put(new ModelPredicateConstant("equal", 2), EQUAL);
139  51 predicateConstants.put(new ModelPredicateConstant("notEqual", 2), NOT_EQUAL);
140  51 predicateConstants.put(new ModelPredicateConstant("in", 2), FALSE);
141  51 predicateConstants.put(new ModelPredicateConstant("notIn", 2), TRUE);
142  51 predicateConstants.put(new ModelPredicateConstant("isSet", 1), FALSE);
143  51 predicateConstants.put(new ModelPredicateConstant("subclass", 2), TRUE);
144  51 predicateConstants.put(new ModelPredicateConstant("isOrderedPair", 1), TRUE);
145  51 predicateConstants.put(new ModelPredicateConstant("isRelation", 1), TRUE);
146  51 predicateConstants.put(new ModelPredicateConstant("isFunction", 1), TRUE);
147   
148    }
149   
 
150  0 toggle public String getDescription() {
151  0 return "This model has only one entity. The \" is element of\" relation is never fullfilled.";
152    }
153   
 
154  4581 toggle public int getEntitiesSize() {
155  4581 return entities.size();
156    }
157   
 
158  4110 toggle public Entity getEntity(final int number) {
159  4110 return (Entity) entities.get(number);
160    }
161   
 
162  2359 toggle public int getPredicateSize(final int size) {
163  2359 if (predicatePool.size() <= size) {
164  0 return 0;
165    }
166  2359 return ((List) predicatePool.get(size)).size();
167    }
168   
 
169  17423 toggle public Predicate getPredicate(final int size, final int number) {
170  17423 final List predicateForSize = (List) predicatePool.get(size);
171  17423 return (Predicate) predicateForSize.get(number);
172    }
173   
 
174  779 toggle public Predicate getPredicateConstant(final ModelPredicateConstant con) {
175  779 return (Predicate) predicateConstants.get(con);
176    }
177   
 
178  4 toggle public int getFunctionSize(final int size) {
179  4 return 1;
180    }
181   
 
182  8 toggle public Function getFunction(final int size, final int number) {
183  8 return FUNCTION_ZERO;
184    }
185   
 
186  285 toggle public Function getFunctionConstant(final ModelFunctionConstant con) {
187  285 return FUNCTION_ZERO;
188    }
189   
 
190  83 toggle public Entity comprehension(final Entity[] array) {
191  83 return ZERO;
192    }
193   
194    }