EMMA Coverage Report (generated Fri Feb 14 08:28:31 UTC 2014)
[all classes][org.qedeq.kernel.bo.logic.model]

COVERAGE SUMMARY FOR SOURCE FILE [FunctionVariableInterpreter.java]

nameclass, %method, %block, %line, %
FunctionVariableInterpreter.java100% (1/1)83%  (5/6)68%  (113/166)72%  (29/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FunctionVariableInterpreter100% (1/1)83%  (5/6)68%  (113/166)72%  (29/40)
toString (): String 0%   (0/1)0%   (0/53)0%   (0/11)
FunctionVariableInterpreter (Model): void 100% (1/1)100% (16/16)100% (5/5)
clear (): void 100% (1/1)100% (7/7)100% (3/3)
getFunction (FunctionVariable): Function 100% (1/1)100% (9/9)100% (1/1)
getFunctionVariableSelection (FunctionVariable): int 100% (1/1)100% (34/34)100% (8/8)
next (): boolean 100% (1/1)100% (47/47)100% (12/12)

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 
16package org.qedeq.kernel.bo.logic.model;
17 
18import java.util.ArrayList;
19import java.util.List;
20 
21import org.qedeq.base.utility.Enumerator;
22 
23 
24/**
25 * Interpret function variables.
26 *
27 * @author  Michael Meyling
28 */
29public 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    public FunctionVariableInterpreter(final Model model) {
46        this.model = model;
47        functionVariables = new ArrayList();
48        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    private int getFunctionVariableSelection(final FunctionVariable var) {
58        int selection;
59        if (functionVariables.contains(var)) {
60            final int index = functionVariables.indexOf(var);
61            selection = ((Enumerator) functionVariableCounters.get(index)).getNumber();
62        } else {
63//            System.out.println("added function variable " + var);
64            selection = 0;
65            functionVariables.add(var);
66            functionVariableCounters.add(new Enumerator());
67        }
68        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    public Function getFunction(final FunctionVariable var) {
78        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    public boolean next() {
88        boolean next = true;
89        for (int i = functionVariables.size() - 1; i >= -1; i--) {
90            if (i < 0) {
91                next = false;
92                break;
93            }
94            final FunctionVariable var = (FunctionVariable) functionVariables.get(i);
95            final Enumerator number = (Enumerator) functionVariableCounters.get(i);
96            if (number.getNumber() + 1 < model.getFunctionSize(var.getArgumentNumber())) {
97                number.increaseNumber();
98                break;
99            }
100            number.reset();
101        }
102        return next;
103    }
104 
105    public String toString() {
106        final StringBuffer buffer = new StringBuffer();
107        buffer.append("function variables {");
108        for (int i = 0; i < functionVariables.size(); i++) {
109            if (i > 0) {
110                buffer.append(", ");
111            }
112            FunctionVariable var = (FunctionVariable) functionVariables.get(i);
113            buffer.append(functionVariables.get(i));
114            buffer.append("=");
115            buffer.append(getFunction(var));
116        }
117        buffer.append("}");
118        return buffer.toString();
119    }
120 
121    /**
122     * Clear variable interpretation.
123     */
124    public void clear() {
125        functionVariables.clear();
126        functionVariableCounters.clear();
127    }
128 
129}

[all classes][org.qedeq.kernel.bo.logic.model]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov