help-jel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-jel] Variable argument list


From: Philip Jonkergouw
Subject: Re: [Help-jel] Variable argument list
Date: Tue, 08 Dec 2015 17:43:28 -0500

Hello again,

I do wonder whether there is anyone out there... :)

I have a slight improvement to my "Decode" function below, as follows:

public class Util {
public static <T> T Decode(Object o, Object o1, T t1, Object... b) {
if (o.equals(o1)) return t1;
int i = 1;
while (i < b.length) {
if (o.equals(b[i-1])) return (T)b[i];
i += 2;
}
if (b.length%2 > 0) return (T)b[i-1];
return null;
}
}

Note how the object received as the 3rd argument now determines the return type of the method. It simplifies use of this method in numeric expressions.

It's my Java interpretation of the Oracle decode function for those of you familiar with it. It works a treat in Java, but as before JEL is unable to match the method's signature (under any circumstances I assume) and crashes at the parse stage.

As before, would it be possible to "switch" off checking for matching signatures by JEL? I would look at doing this myself in the code, but fear that JEL is many levels beyond my Java coding skills. However, any pointers that could allow me to test some modifications would also be very much appreciated!

Best regards,
Phil



-------- Original Message --------
Subject: Variable argument list
Local Time: December 7 2015 10:43 pm
UTC Time: December 7 2015 10:43 pm
From: address@hidden
To: address@hidden

Hi,

I'm new to JEL and am considering using it for my project, so first of all, thank you for creating it! Very impressive performance benchmarks (also including my own tests).

I'm playing around in my home made JEL sandbox and have come across a problem for which I would like to find a workaround. Consider this scenario:

public class Util {
public static Object Decode(Object... b) {
if (b.length < 2) throw new IllegalArgumentException("Too few arguments.");
int i = 2;
while (i < b.length) {
if (b[0] == b[i-1]) return b[i];
i += 2;
}
return null;
}
}

public class MySandBox {
    public static void main(java.lang.String[] args) throws Throwable {
Object o = Util.Decode("Hello", "World", 2.0, "Hello", 3.0);
System.out.println("decode(\"Hello\", \"World\", 2.0, \"Hello\", 3.0): " + java.lang.String.valueOf(o));

Class[] stLib = new Class[1];
stLib[0] = Util.class;
gnu.jel.Library lib = new gnu.jel.Library(stLib,null,null,null,null);
gnu.jel.CompiledExpression expr;
expr = gnu.jel.Evaluator.compile("Decode(\"Hello\", \"World\", 2.0, \"Hello\", 3.0)",lib, java.lang.Double.TYPE);
    };
};

The error I get during execution is:

Exception in thread "main" gnu.jel.CompilationException: Function "Decode" exists but parameters "Decode(class java.lang.String,class java.lang.String,double,class java.lang.String,double)" can not be accepted by it.

I can understand why this is happening.

However, might there be a way to disable this type of checking and "simply" execute the code through the JEL library? Or could you suggest a workaround? I realise there's nothing "simple" about the inner workings of JEL, please don't get me wrong! The Java function "Decode" is meant to be extremely flexible, passing any number and types of arguments. It can handle all sorts of string comparisons, integer comparisons and return a number of types including doubles, ints and strings. Creating strongly typed overrides isn't an option.

Thanks in advance for the consideration.

Best regards,
Phil



reply via email to

[Prev in Thread] Current Thread [Next in Thread]