Clover coverage report - DrJava Test Coverage (drjava-20110828-r5448)
Coverage timestamp: Sun Aug 28 2011 03:13:33 CDT
file stats: LOC: 135   Methods: 4
NCLOC: 78   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BinaryOpProperty.java 100% 100% 100% 100%
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.Lambda;
 40    import edu.rice.cs.plt.lambda.Lambda2;
 41   
 42    /** Class representing binary operations that can be inserted as variables in external processes.
 43    * @version $Id: BinaryOpProperty.java 5175 2010-01-20 08:46:32Z mgricken $
 44    */
 45    public class BinaryOpProperty<P,Q,R> extends EagerProperty {
 46    /** Operation to perform. */
 47    protected Lambda2<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    /** Lambda to turn a string into the first operand. */
 57    protected Lambda<String, P> _parse1;
 58    /** Lambda to turn a string into the first operand. */
 59    protected Lambda<String, Q> _parse2;
 60    /** Lambda to format the result. */
 61    protected Lambda<R, String> _format;
 62   
 63    /** Create an eager property. */
 64  598 public BinaryOpProperty(String name,
 65    String help,
 66    Lambda2<P,Q,R> op,
 67    String op1Name,
 68    String op1Default,
 69    Lambda<String,P> parse1,
 70    String op2Name,
 71    String op2Default,
 72    Lambda<String,Q> parse2,
 73    Lambda<R,String> format) {
 74  598 super(name, help);
 75  598 _op = op;
 76  598 _op1Name = op1Name;
 77  598 _op1Default = op1Default;
 78  598 _parse1 = parse1;
 79  598 _op2Name = op2Name;
 80  598 _op2Default = op2Default;
 81  598 _parse2 = parse2;
 82  598 _format = format;
 83  598 resetAttributes();
 84    }
 85   
 86    /** Create an eager property. */
 87  552 public BinaryOpProperty(String name,
 88    String help,
 89    Lambda2<P,Q,R> op,
 90    Lambda<String,P> parse1,
 91    Lambda<String,Q> parse2,
 92    Lambda<R,String> format) {
 93  552 this(name,help,op,"op1",null,parse1,"op2",null,parse2,format);
 94    }
 95   
 96    /** Update the property so the value is current.
 97    * @param pm PropertyMaps used for substitution when replacing variables */
 98  159 public void update(PropertyMaps pm) {
 99  159 P op1;
 100  159 if (_attributes.get(_op1Name) == null) {
 101  57 _value = "(" + _name + " Error...)";
 102  57 return;
 103    }
 104    else {
 105  102 try {
 106  102 op1 = _parse1.value(_attributes.get(_op1Name));
 107    }
 108    catch(Exception e) {
 109  8 _value = "(" + _name + " Error...)";
 110  8 return;
 111    }
 112    }
 113  94 Q op2;
 114  94 if (_attributes.get(_op2Name) == null) {
 115  12 _value = "(" + _name + " Error...)";
 116  12 return;
 117    }
 118    else {
 119  82 try {
 120  82 op2 = _parse2.value(_attributes.get(_op2Name));
 121    }
 122    catch(Exception ee) {
 123  8 _value = "(" + _name + " Error...)";
 124  8 return;
 125    }
 126    }
 127  74 _value = _format.value(_op.value(op1,op2));
 128    }
 129   
 130  1208 public void resetAttributes() {
 131  1208 _attributes.clear();
 132  1208 _attributes.put(_op1Name, _op1Default);
 133  1208 _attributes.put(_op2Name, _op2Default);
 134    }
 135    }