JESS: [EXTERNAL] Issue with static methods (or generics?)
Aurélien Mazurie <[email protected]> Wed, 7 Aug 2013 17:11:02 -0600
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_4B5C8BFC-DA96-453E-897A-E6199C640233 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 Dear Jess users, I am having trouble instantiating a Java class from within a rule's RHS, = and cannot figure out how to solve this problem. The code in my RHS creates an instance of a class from the JGraphT = library. As seen in = https://github.com/jgrapht/jgrapht/blob/master/jgrapht-demo/src/main/java/= org/jgrapht/demo/HelloJGraphT.java (lines 91-92), the creation of a = DefaultDirectedGraph instance require another class as argument; here, = DefaultEdge. I couldn't find an example in the Jess documentation about how to do = that. For example, I tried the following: (bind ?edge-class org.jgrapht.graph.DefaultEdge) (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph = ?edge-class)) I also tried variations such as (bind ?edge-class org.jgrapht.graph.DefaultEdge) (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph = (?edge-class getClass)) or (bind ?edge-class (new org.jgrapht.graph.DefaultEdge)) (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph = ?edge-class)) Any idea about what the syntax should be to properly instantiate the = DefaultDirectedGraph class? For information (but not certain how = relevant it is here), I succeeded in the past in using = java.util.regex.Pattern and its static method 'compile' by typing (bind ?pattern-class java.util.regex.Pattern) (bind ?matches ((?pattern-class compile "...") matcher ?string)) Best, Aur=E9lien= --Apple-Mail=_4B5C8BFC-DA96-453E-897A-E6199C640233 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=iso-8859-1 <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html = charset=3Diso-8859-1"></head><body style=3D"word-wrap: break-word; = -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Dear = Jess users,<div>I am having trouble instantiating a Java class from = within a rule's RHS, and cannot figure out how to solve this = problem.</div><div><br></div><div>The code in my RHS creates an instance = of a class from the JGraphT library. As seen in <a = href=3D"https://github.com/jgrapht/jgrapht/blob/master/jgrapht-demo/src/ma= in/java/org/jgrapht/demo/HelloJGraphT.java">https://github.com/jgrapht/jgr= apht/blob/master/jgrapht-demo/src/main/java/org/jgrapht/demo/HelloJGraphT.= java</a> (lines 91-92), the creation of a DefaultDirectedGraph = instance require another class as argument; here, = DefaultEdge.</div><div><br></div><div>I couldn't find an example in the = Jess documentation about how to do that. For example, I tried the = following:</div><div><br></div><div><span class=3D"Apple-tab-span" = style=3D"white-space:pre"> </span>(bind ?edge-class = org.jgrapht.graph.DefaultEdge)</div><div><span class=3D"Apple-tab-span" = style=3D"white-space:pre"> </span>(bind ?graph (new = org.jgrapht.graph.DefaultDirectedGraph = ?edge-class))</div><div><br></div><div>I also tried variations such = as</div><div><br></div><div><div><span class=3D"Apple-tab-span" = style=3D"white-space: pre; "> </span>(bind ?edge-class = org.jgrapht.graph.DefaultEdge)</div><div><span class=3D"Apple-tab-span" = style=3D"white-space: pre; "> </span>(bind ?graph (new = org.jgrapht.graph.DefaultDirectedGraph (?edge-class = getClass))</div></div><div><br></div><div>or</div><div><br></div><div><div= ><span class=3D"Apple-tab-span" style=3D"white-space: pre; "> = </span>(bind ?edge-class (new = org.jgrapht.graph.DefaultEdge))</div><div><span class=3D"Apple-tab-span" = style=3D"white-space: pre; "> </span>(bind ?graph (new = org.jgrapht.graph.DefaultDirectedGraph = ?edge-class))</div></div><div><br></div><div>Any idea about what the = syntax should be to properly instantiate the DefaultDirectedGraph class? = For information (but not certain how relevant it is here), I succeeded = in the past in using java.util.regex.Pattern and its static method = 'compile' by typing</div><div><br></div><div><div><span = class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>(bind = ?pattern-class java.util.regex.Pattern)</div><div><span = class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>(bind = ?matches ((?pattern-class compile "...") matcher = ?string))</div></div><div><br></div><div>Best,</div><div>Aur=E9lien</div><= /body></html>= --Apple-Mail=_4B5C8BFC-DA96-453E-897A-E6199C640233--