Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 163   Methods: 4
NCLOC: 103   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TernaryOpProperty.java 100% 83.7% 75% 84.9%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK
 2    *
 3    * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    * * Redistributions of source code must retain the above copyright
 9    * notice, this list of conditions and the following disclaimer.
 10    * * Redistributions in binary form must reproduce the above copyright
 11    * notice, this list of conditions and the following disclaimer in the
 12    * documentation and/or other materials provided with the distribution.
 13    * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
 14    * names of its contributors may be used to endorse or promote products
 15    * derived from this software without specific prior written permission.
 16    *
 17    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 21    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 25    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 26    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28    *
 29    * This software is Open Source Initiative approved Open Source Software.
 30    * Open Source Initative Approved is a trademark of the Open Source Initiative.
 31    *
 32    * This file is part of DrJava. Download the current version of this project
 33    * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
 34    *
 35    * END_COPYRIGHT_BLOCK*/
 36   
 37    package edu.rice.cs.drjava.config;
 38   
 39    import edu.rice.cs.plt.lambda.Lambda3;
 40    import edu.rice.cs.plt.lambda.Lambda;
 41   
 42    /** Class representing ternary operations that can be inserted as variables in external processes.
 43    * @version $Id: TernaryOpProperty.java 5175 2010-01-20 08:46:32Z mgricken $
 44    */
 45    public class TernaryOpProperty<O,P,Q,R> extends EagerProperty {
 46    /** Operation to perform. */
 47    protected Lambda3<O,P,Q,R> _op;
 48    /** Operator 1 name */
 49    protected String _op1Name;
 50    /** Operator 1 default */
 51    protected String _op1Default;
 52    /** Operator 2 name */
 53    protected String _op2Name;
 54    /** Operator 2 default */
 55    protected String _op2Default;
 56    /** Operator 3 name */
 57    protected String _op3Name;
 58    /** Operator 3 default */
 59    protected String _op3Default;
 60    /** Lambda to turn a string into the first operand. */
 61    protected Lambda<String,O> _parse1;
 62    /** Lambda to turn a string into the second operand. */
 63    protected Lambda<String,P> _parse2;
 64    /** Lambda to turn a string into the third operand. */
 65    protected Lambda<String,Q> _parse3;
 66    /** Lambda to format the result. */
 67    protected Lambda<R,String> _format;
 68   
 69    /** Create an eager property. */
 70  92 public TernaryOpProperty(String name,
 71    String help,
 72    Lambda3<O,P,Q,R> op,
 73    String op1Name,
 74    String op1Default,
 75    Lambda<String,O> parse1,
 76    String op2Name,
 77    String op2Default,
 78    Lambda<String,P> parse2,
 79    String op3Name,
 80    String op3Default,
 81    Lambda<String,Q> parse3,
 82    Lambda<R,String> format) {
 83  92 super(name, help);
 84  92 _op = op;
 85  92 _op1Name = op1Name;
 86  92 _op1Default = op1Default;
 87  92 _parse1 = parse1;
 88  92 _op2Name = op2Name;
 89  92 _op2Default = op2Default;
 90  92 _parse2 = parse2;
 91  92 _op3Name = op3Name;
 92  92 _op3Default = op3Default;
 93  92 _parse3 = parse3;
 94  92 _format = format;
 95  92 resetAttributes();
 96    }
 97   
 98    /** Create an eager property. */
 99  0 public TernaryOpProperty(String name,
 100    String help,
 101    Lambda3<O,P,Q,R> op,
 102    Lambda<String,O> parse1,
 103    Lambda<String,P> parse2,
 104    Lambda<String,Q> parse3,
 105    Lambda<R,String> format) {
 106  0 this(name,help,op,"op1",null,parse1,"op2",null,parse2,"op3",null,parse3,format);
 107    }
 108   
 109    /** Update the property so the value is current.
 110    * @param pm PropertyMaps used for substitution when replacing variables */
 111  43 public void update(PropertyMaps pm) {
 112  43 O op1;
 113  43 if (_attributes.get(_op1Name) == null) {
 114  8 _value = "(" + _name + " Error...)";
 115  8 return;
 116    }
 117    else {
 118  35 try {
 119  35 op1 = _parse1.value(_attributes.get(_op1Name));
 120    }
 121    catch(Exception e) {
 122  0 _value = "(" + _name + " Error...)";
 123  0 return;
 124    }
 125    }
 126  35 P op2;
 127  35 if (_attributes.get(_op2Name) == null) {
 128  4 _value = "(" + _name + " Error...)";
 129  4 return;
 130    }
 131    else {
 132  31 try {
 133  31 op2 = _parse2.value(_attributes.get(_op2Name));
 134    }
 135    catch(Exception e) {
 136  0 _value = "(" + _name + " Error...)";
 137  0 return;
 138    }
 139    }
 140  31 Q op3;
 141  31 if (_attributes.get(_op3Name) == null) {
 142  2 _value = "(" + _name + " Error...)";
 143  2 return;
 144    }
 145    else {
 146  29 try {
 147  29 op3 = _parse3.value(_attributes.get(_op3Name));
 148    }
 149    catch(Exception ee) {
 150  0 _value = "(" + _name + " Error...)";
 151  0 return;
 152    }
 153    }
 154  29 _value = _format.value(_op.value(op1,op2,op3));
 155    }
 156   
 157  194 public void resetAttributes() {
 158  194 _attributes.clear();
 159  194 _attributes.put(_op1Name, _op1Default);
 160  194 _attributes.put(_op2Name, _op2Default);
 161  194 _attributes.put(_op3Name, _op3Default);
 162    }
 163    }