Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart7.png 74% of files have more coverage
37   124   12   6.17
12   66   0.32   6
6     2  
1    
 
  PredicateVariableInterpreter       Line # 29 37 12 69.1% 0.6909091
 
  (286)
 
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.List;
20   
21    import org.qedeq.base.utility.Enumerator;
22   
23   
24    /**
25    * This class calculates a new truth value for a given formula for a given interpretation.
26    *
27    * @author Michael Meyling
28    */
 
29    public final class PredicateVariableInterpreter {
30   
31    /** List of predicate variables. */
32    private List predicateVariables;
33   
34    /** List of counters for predicate variables. */
35    private List predicateVariableCounters;
36   
37    /** Model contains entities. */
38    private Model model;
39   
40    /**
41    * Constructor.
42    *
43    * @param model Model we work on.
44    */
 
45  494 toggle public PredicateVariableInterpreter(final Model model) {
46  494 this.model = model;
47  494 predicateVariables = new ArrayList();
48  494 predicateVariableCounters = new ArrayList();
49    }
50   
 
51  525199 toggle private int getPredicateVariableSelection(final PredicateVariable var) {
52  525199 int selection;
53  525199 if (predicateVariables.contains(var)) {
54  524745 final int index = predicateVariables.indexOf(var);
55  524745 selection = ((Enumerator) predicateVariableCounters.get(index)).getNumber();
56    } else {
57    // System.out.println("added predicate variable " + var);
58  454 selection = 0;
59  454 predicateVariables.add(var);
60  454 predicateVariableCounters.add(new Enumerator());
61    }
62  525199 return selection;
63    }
64   
65    /**
66    * Get model predicate for predicate variable.
67    *
68    * @param var For this predicate variable.
69    * @return Predicate for model.
70    */
 
71  525199 toggle public Predicate getPredicate(final PredicateVariable var) {
72  525199 return model.getPredicate(var.getArgumentNumber(),
73    getPredicateVariableSelection(var));
74    }
75   
76    /**
77    * Change to next valuation.
78    *
79    * @return Is there a next new valuation?
80    */
 
81  10291 toggle public boolean next() {
82  10291 boolean next = true;
83  18049 for (int i = predicateVariables.size() - 1; i >= -1; i--) {
84  18049 if (i < 0) {
85  381 next = false;
86  381 break;
87    }
88  17668 final PredicateVariable var = (PredicateVariable) predicateVariables.get(i);
89  17668 final Enumerator number = (Enumerator) predicateVariableCounters.get(i);
90  17668 if (number.getNumber() + 1 < model.getPredicateSize(var.getArgumentNumber())) {
91  9910 number.increaseNumber();
92  9910 break;
93    }
94  7758 number.reset();
95    }
96  10291 return next;
97    }
98   
 
99  0 toggle public String toString() {
100  0 final StringBuffer buffer = new StringBuffer();
101  0 buffer.append("predicate variables {");
102  0 for (int i = 0; i < predicateVariables.size(); i++) {
103  0 if (i > 0) {
104  0 buffer.append(", ");
105    }
106  0 PredicateVariable var = (PredicateVariable) predicateVariables.get(i);
107  0 buffer.append(predicateVariables.get(i));
108  0 buffer.append("=");
109  0 buffer.append(getPredicate(var));
110    }
111  0 buffer.append("}");
112  0 return buffer.toString();
113    }
114   
115    /**
116    * Clear variable interpretation.
117    */
 
118  48 toggle public void clear() {
119  48 predicateVariables.clear();
120  48 predicateVariableCounters.clear();
121    }
122   
123   
124    }