You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2015/08/05 15:05:48 UTC
svn commit: r1694207 - in
/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3:
internal/Closure.java internal/Scope.java internal/Script.java
scripting/Main.java
Author: henrib
Date: Wed Aug 5 13:05:48 2015
New Revision: 1694207
URL: http://svn.apache.org/r1694207
Log:
JEXL:
Added hashCode/equals to Script/Closure
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Closure.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/Main.java
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Closure.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Closure.java?rev=1694207&r1=1694206&r2=1694207&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Closure.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Closure.java Wed Aug 5 13:05:48 2015
@@ -51,6 +51,38 @@ public class Closure extends Script {
return debug.toString();
}
+ @Override
+ public int hashCode() {
+ // CSOFF: Magic number
+ int hash = 17;
+ hash = 31 * hash + (this.jexl != null ? this.jexl.hashCode() : 0);
+ hash = 31 * hash + (this.source != null ? this.source.hashCode() : 0);
+ hash = 31 * hash + (this.frame != null ? this.frame.hashCode() : 0);
+ // CSON: Magic number
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Closure other = (Closure) obj;
+ if (this.jexl != other.jexl) {
+ return false;
+ }
+ if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) {
+ return false;
+ }
+ if (this.frame != other.frame && (this.frame == null || !this.frame.equals(other.frame))) {
+ return false;
+ }
+ return true;
+ }
+
/**
* Sets the hoisted index of a given symbol, ie the target index of a parent hoisted symbol in this closure's frame.
* <p>This is meant to allow a locally defined function to "see" and call itself as a local (hoisted) variable;
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java?rev=1694207&r1=1694206&r2=1694207&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Scope.java Wed Aug 5 13:05:48 2015
@@ -16,6 +16,7 @@
*/
package org.apache.commons.jexl3.internal;
+import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -290,6 +291,23 @@ public final class Scope {
stack = r;
}
+ @Override
+ public int hashCode() {
+ return Arrays.deepHashCode(this.stack);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Frame other = (Frame) obj;
+ return Arrays.deepEquals(this.stack, other.stack);
+ }
+
/**
* Gets a value.
* @param s the offset in this frame
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java?rev=1694207&r1=1694206&r2=1694207&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Script.java Wed Aug 5 13:05:48 2015
@@ -110,6 +110,34 @@ public class Script implements JexlScrip
}
@Override
+ public int hashCode() {
+ // CSOFF: Magic number
+ int hash = 17;
+ hash = 31 * hash + (this.jexl != null ? this.jexl.hashCode() : 0);
+ hash = 31 * hash + (this.source != null ? this.source.hashCode() : 0);
+ return hash;
+ // CSON: Magic number
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Script other = (Script) obj;
+ if (this.jexl != other.jexl) {
+ return false;
+ }
+ if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
public String toString() {
CharSequence src = source;
if (src == null) {
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/Main.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/Main.java?rev=1694207&r1=1694206&r2=1694207&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/Main.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/Main.java Wed Aug 5 13:05:48 2015
@@ -18,9 +18,11 @@
package org.apache.commons.jexl3.scripting;
import java.io.BufferedReader;
-import java.io.FileReader;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
@@ -29,6 +31,24 @@ import javax.script.ScriptException;
* @since 2.0
*/
public class Main {
+ /**
+ * Reads an input.
+ * @param charset the charset or null for default charset
+ * @param fileName the file name or null for stdin
+ * @return the reader
+ * @throws Exception if anything goes wrong
+ */
+ static BufferedReader read(Charset charset, String fileName) throws Exception {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ fileName == null
+ ? System.in
+ : new FileInputStream(new File(fileName)),
+ charset == null
+ ? Charset.defaultCharset()
+ : charset));
+ return in;
+ }
/**
* Test application for JexlScriptEngine (JSR-223 implementation).
@@ -49,10 +69,10 @@ public class Main {
ScriptEngine engine = fac.getScriptEngine();
engine.put("args", args);
if (args.length == 1){
- Object value = engine.eval(new FileReader(args[0]));
+ Object value = engine.eval(read(null, args[0]));
System.out.println("Return value: "+value);
} else {
- BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
+ BufferedReader console = read(null, null);
String line;
System.out.print("> ");
while(null != (line=console.readLine())){