Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart7.png 74% of files have more coverage
37   129   12   6.17
12   66   0.32   6
6     2  
1    
 
  FunctionVariableInterpreter       Line # 29 37 12 69.1% 0.6909091
 
No Tests
 
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    * Interpret function variables.
26    *
27    * @author Michael Meyling
28    */
 
29    public final class FunctionVariableInterpreter {
30   
31    /** Model contains entities, functions, predicates. */
32    private Model model;
33   
34    /** List of function variables. */
35    private List functionVariables;
36   
37    /** List of counters for function variables. */
38    private List functionVariableCounters;
39   
40    /**
41    * Constructor.
42    *
43    * @param model Model we work on.
44    */
 
45  494 toggle public FunctionVariableInterpreter(final Model model) {
46  494 this.model = model;
47  494 functionVariables = new ArrayList();
48  494 functionVariableCounters = new ArrayList();
49    }
50   
51    /**
52    * Get selection for function of model for given function variable.
53    *
54    * @param var Function variable we want an interpretation for.
55    * @return Function selection number of model.
56    */
 
57  698 toggle private int getFunctionVariableSelection(final FunctionVariable var) {
58  698 int selection;
59  698 if (functionVariables.contains(var)) {
60  678 final int index = functionVariables.indexOf(var);
61  678 selection = ((Enumerator) functionVariableCounters.get(index)).getNumber();
62    } else {
63    // System.out.println("added function variable " + var);
64  20 selection = 0;
65  20 functionVariables.add(var);
66  20 functionVariableCounters.add(new Enumerator());
67    }
68  698 return selection;
69    }
70   
71    /**
72    * Get interpretation for function of model for given function variable.
73    *
74    * @param var Function variable we want an interpretation for.
75    * @return Function.
76    */
 
77  698 toggle public Function getFunction(final FunctionVariable var) {
78  698 return model.getFunction(var.getArgumentNumber(),
79    getFunctionVariableSelection(var));
80    }
81   
82    /**
83    * Change to next valuation.
84    *
85    * @return Is there a next new valuation?
86    */
 
87  381 toggle public boolean next() {
88  381 boolean next = true;
89  397 for (int i = functionVariables.size() - 1; i >= -1; i--) {
90  397 if (i < 0) {
91  346 next = false;
92  346 break;
93    }
94  51 final FunctionVariable var = (FunctionVariable) functionVariables.get(i);
95  51 final Enumerator number = (Enumerator) functionVariableCounters.get(i);
96  51 if (number.getNumber() + 1 < model.getFunctionSize(var.getArgumentNumber())) {
97  35 number.increaseNumber();
98  35 break;
99    }
100  16 number.reset();
101    }
102  381 return next;
103    }
104   
 
105  0 toggle public String toString() {
106  0 final StringBuffer buffer = new StringBuffer();
107  0 buffer.append("function variables {");
108  0 for (int i = 0; i < functionVariables.size(); i++) {
109  0 if (i > 0) {
110  0 buffer.append(", ");
111    }
112  0 FunctionVariable var = (FunctionVariable) functionVariables.get(i);
113  0 buffer.append(functionVariables.get(i));
114  0 buffer.append("=");
115  0 buffer.append(getFunction(var));
116    }
117  0 buffer.append("}");
118  0 return buffer.toString();
119    }
120   
121    /**
122    * Clear variable interpretation.
123    */
 
124  48 toggle public void clear() {
125  48 functionVariables.clear();
126  48 functionVariableCounters.clear();
127    }
128   
129    }