|
1 | | -/*BEGIN_COPYRIGHT_BLOCK |
2 | | - * |
3 | | - * Copyright (c) 2001-2008, 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.drjava.DrJava; |
40 | | -import edu.rice.cs.plt.lambda.Lambda2; |
41 | | -import edu.rice.cs.util.Lambda; |
42 | | - |
43 | | -import java.util.HashSet; |
44 | | -import java.util.Iterator; |
45 | | - |
46 | | -import static edu.rice.cs.util.HashUtilities.hash; |
47 | | - |
48 | | -/** Class representing binary operations that can be inserted as variables in external processes. |
49 | | - * @version $Id$ |
50 | | - */ |
51 | | -public class BinaryOpProperty<P,Q,R> extends EagerProperty { |
52 | | - /** Operation to perform. */ |
53 | | - protected Lambda2<P,Q,R> _op; |
54 | | - /** Operator 1 name */ |
55 | | - protected String _op1Name; |
56 | | - /** Operator 1 default */ |
57 | | - protected String _op1Default; |
58 | | - /** Operator 2 name */ |
59 | | - protected String _op2Name; |
60 | | - /** Operator 2 default */ |
61 | | - protected String _op2Default; |
62 | | - /** Lambda to turn a string into the first operand. */ |
63 | | - protected Lambda<P,String> _parse1; |
64 | | - /** Lambda to turn a string into the first operand. */ |
65 | | - protected Lambda<Q,String> _parse2; |
66 | | - /** Lambda to format the result. */ |
67 | | - protected Lambda<String,R> _format; |
68 | | - |
69 | | - /** Create an eager property. */ |
70 | | - public BinaryOpProperty(String name, |
71 | | - String help, |
72 | | - Lambda2<P,Q,R> op, |
73 | | - String op1Name, |
74 | | - String op1Default, |
75 | | - Lambda<P,String> parse1, |
76 | | - String op2Name, |
77 | | - String op2Default, |
78 | | - Lambda<Q,String> parse2, |
79 | | - Lambda<String,R> format) { |
80 | | - super(name, help); |
81 | | - _op = op; |
82 | | - _op1Name = op1Name; |
83 | | - _op1Default = op1Default; |
84 | | - _parse1 = parse1; |
85 | | - _op2Name = op2Name; |
86 | | - _op2Default = op2Default; |
87 | | - _parse2 = parse2; |
88 | | - _format = format; |
89 | | - resetAttributes(); |
90 | | - } |
91 | | - |
92 | | - /** Create an eager property. */ |
93 | | - public BinaryOpProperty(String name, |
94 | | - String help, |
95 | | - Lambda2<P,Q,R> op, |
96 | | - Lambda<P,String> parse1, |
97 | | - Lambda<Q,String> parse2, |
98 | | - Lambda<String,R> format) { |
99 | | - this(name,help,op,"op1",null,parse1,"op2",null,parse2,format); |
100 | | - } |
101 | | - |
102 | | - /** Update the property so the value is current. |
103 | | - * @param pm PropertyMaps used for substitution when replacing variables */ |
104 | | - public void update(PropertyMaps pm) { |
105 | | - P op1; |
106 | | - if (_attributes.get(_op1Name)==null) { |
107 | | - _value = "("+_name+" Error...)"; |
108 | | - return; |
109 | | - } |
110 | | - else { |
111 | | - try { |
112 | | - op1 = _parse1.apply(_attributes.get(_op1Name)); |
113 | | - } |
114 | | - catch(Exception e) { |
115 | | - _value = "("+_name+" Error...)"; |
116 | | - return; |
117 | | - } |
118 | | - } |
119 | | - Q op2; |
120 | | - if (_attributes.get(_op2Name)==null) { |
121 | | - _value = "("+_name+" Error...)"; |
122 | | - return; |
123 | | - } |
124 | | - else { |
125 | | - try { |
126 | | - op2 = _parse2.apply(_attributes.get(_op2Name)); |
127 | | - } |
128 | | - catch(Exception ee) { |
129 | | - _value = "("+_name+" Error...)"; |
130 | | - return; |
131 | | - } |
132 | | - } |
133 | | - _value = _format.apply(_op.value(op1,op2)); |
134 | | - } |
135 | | - |
136 | | - public void resetAttributes() { |
137 | | - _attributes.clear(); |
138 | | - _attributes.put(_op1Name, _op1Default); |
139 | | - _attributes.put(_op2Name, _op2Default); |
140 | | - } |
141 | | -} |
| 1 | +/*BEGIN_COPYRIGHT_BLOCK |
| 2 | + * |
| 3 | + * Copyright (c) 2001-2008, 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.drjava.DrJava; |
| 40 | +import edu.rice.cs.plt.lambda.Lambda; |
| 41 | +import edu.rice.cs.plt.lambda.Lambda2; |
| 42 | + |
| 43 | +import java.util.HashSet; |
| 44 | +import java.util.Iterator; |
| 45 | + |
| 46 | +import static edu.rice.cs.util.HashUtilities.hash; |
| 47 | + |
| 48 | +/** Class representing binary operations that can be inserted as variables in external processes. |
| 49 | + * @version $Id$ |
| 50 | + */ |
| 51 | +public class BinaryOpProperty<P,Q,R> extends EagerProperty { |
| 52 | + /** Operation to perform. */ |
| 53 | + protected Lambda2<P,Q,R> _op; |
| 54 | + /** Operator 1 name */ |
| 55 | + protected String _op1Name; |
| 56 | + /** Operator 1 default */ |
| 57 | + protected String _op1Default; |
| 58 | + /** Operator 2 name */ |
| 59 | + protected String _op2Name; |
| 60 | + /** Operator 2 default */ |
| 61 | + protected String _op2Default; |
| 62 | + /** Lambda to turn a string into the first operand. */ |
| 63 | + protected Lambda<String, P> _parse1; |
| 64 | + /** Lambda to turn a string into the first operand. */ |
| 65 | + protected Lambda<String, Q> _parse2; |
| 66 | + /** Lambda to format the result. */ |
| 67 | + protected Lambda<R, String> _format; |
| 68 | + |
| 69 | + /** Create an eager property. */ |
| 70 | + public BinaryOpProperty(String name, |
| 71 | + String help, |
| 72 | + Lambda2<P,Q,R> op, |
| 73 | + String op1Name, |
| 74 | + String op1Default, |
| 75 | + Lambda<String,P> parse1, |
| 76 | + String op2Name, |
| 77 | + String op2Default, |
| 78 | + Lambda<String,Q> parse2, |
| 79 | + Lambda<R,String> format) { |
| 80 | + super(name, help); |
| 81 | + _op = op; |
| 82 | + _op1Name = op1Name; |
| 83 | + _op1Default = op1Default; |
| 84 | + _parse1 = parse1; |
| 85 | + _op2Name = op2Name; |
| 86 | + _op2Default = op2Default; |
| 87 | + _parse2 = parse2; |
| 88 | + _format = format; |
| 89 | + resetAttributes(); |
| 90 | + } |
| 91 | + |
| 92 | + /** Create an eager property. */ |
| 93 | + public BinaryOpProperty(String name, |
| 94 | + String help, |
| 95 | + Lambda2<P,Q,R> op, |
| 96 | + Lambda<String,P> parse1, |
| 97 | + Lambda<String,Q> parse2, |
| 98 | + Lambda<R,String> format) { |
| 99 | + this(name,help,op,"op1",null,parse1,"op2",null,parse2,format); |
| 100 | + } |
| 101 | + |
| 102 | + /** Update the property so the value is current. |
| 103 | + * @param pm PropertyMaps used for substitution when replacing variables */ |
| 104 | + public void update(PropertyMaps pm) { |
| 105 | + P op1; |
| 106 | + if (_attributes.get(_op1Name)==null) { |
| 107 | + _value = "("+_name+" Error...)"; |
| 108 | + return; |
| 109 | + } |
| 110 | + else { |
| 111 | + try { |
| 112 | + op1 = _parse1.value(_attributes.get(_op1Name)); |
| 113 | + } |
| 114 | + catch(Exception e) { |
| 115 | + _value = "("+_name+" Error...)"; |
| 116 | + return; |
| 117 | + } |
| 118 | + } |
| 119 | + Q op2; |
| 120 | + if (_attributes.get(_op2Name)==null) { |
| 121 | + _value = "("+_name+" Error...)"; |
| 122 | + return; |
| 123 | + } |
| 124 | + else { |
| 125 | + try { |
| 126 | + op2 = _parse2.value(_attributes.get(_op2Name)); |
| 127 | + } |
| 128 | + catch(Exception ee) { |
| 129 | + _value = "("+_name+" Error...)"; |
| 130 | + return; |
| 131 | + } |
| 132 | + } |
| 133 | + _value = _format.value(_op.value(op1,op2)); |
| 134 | + } |
| 135 | + |
| 136 | + public void resetAttributes() { |
| 137 | + _attributes.clear(); |
| 138 | + _attributes.put(_op1Name, _op1Default); |
| 139 | + _attributes.put(_op2Name, _op2Default); |
| 140 | + } |
| 141 | +} |
0 commit comments