[PPL-devel] [GIT] ppl/ppl(master): Modified signature of method maps() in Java Partial_Function interface.

Enea Zaffanella zaffanella at cs.unipr.it
Thu Apr 22 10:16:31 CEST 2010


Module: ppl/ppl
Branch: master
Commit: c30a06c1bbee850d1ef6d74e23e6d77073578911
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=c30a06c1bbee850d1ef6d74e23e6d77073578911

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Thu Apr 22 10:05:12 2010 +0200

Modified signature of method maps() in Java Partial_Function interface.
Modified test implementation in tests/Test_Partial_Function.java
accordingly (note though that TreeMap still uses Long objects).

---

 interfaces/Java/jni/ppl_java_common.inlines.hh     |   20 ++++----------------
 .../parma_polyhedra_library/Partial_Function.java  |    8 ++++----
 interfaces/Java/tests/Test_Partial_Function.java   |   11 +++++------
 3 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/interfaces/Java/jni/ppl_java_common.inlines.hh b/interfaces/Java/jni/ppl_java_common.inlines.hh
index d96681b..f449495 100644
--- a/interfaces/Java/jni/ppl_java_common.inlines.hh
+++ b/interfaces/Java/jni/ppl_java_common.inlines.hh
@@ -278,24 +278,12 @@ inline bool
 Partial_Function::maps(dimension_type i, dimension_type& j) const {
   jclass j_p_func_class = env->GetObjectClass(j_p_func);
   CHECK_RESULT_ASSERT(env, j_p_func_class);
-  jobject coeff = j_long_to_j_long_class(env, 0);
-  jobject new_by_ref = env->NewObject(cached_classes.By_Reference,
-                                      cached_FMIDs.By_Reference_init_ID,
-                                      coeff);
-  CHECK_RESULT_THROW(env, new_by_ref);
-  jmethodID j_maps_id
-    = env->GetMethodID(j_p_func_class, "maps",
-                       "(Ljava/lang/Long;"
-                       "Lparma_polyhedra_library/By_Reference;)Z");
+  jmethodID j_maps_id = env->GetMethodID(j_p_func_class, "maps", "(J)J");
   CHECK_RESULT_ASSERT(env, j_maps_id);
-  jboolean b = env->CallBooleanMethod(j_p_func, j_maps_id,
-                                      j_long_to_j_long_class(env, i),
-                                      new_by_ref);
+  jlong j_long_value = env->CallLongMethod(j_p_func, j_maps_id, i);
   CHECK_EXCEPTION_THROW(env);
-  if (b) {
-    jobject long_value = get_by_reference(env, new_by_ref);
-    j = jtype_to_unsigned<dimension_type>(j_long_class_to_j_long(env,
-                                                                 long_value));
+  if (j_long_value >= 0) {
+    j = jtype_to_unsigned<dimension_type>(j_long_value);
     return true;
   }
   return false;
diff --git a/interfaces/Java/parma_polyhedra_library/Partial_Function.java b/interfaces/Java/parma_polyhedra_library/Partial_Function.java
index 782731d..323a352 100644
--- a/interfaces/Java/parma_polyhedra_library/Partial_Function.java
+++ b/interfaces/Java/parma_polyhedra_library/Partial_Function.java
@@ -50,10 +50,10 @@ public interface Partial_Function {
     long max_in_codomain();
 
     /*! \brief
-      Sets \p j to the value (if any) of the partial function on index \p i.
+      If the partial function is defined on index \p i, returns its value.
 
-      The function returns \c true if and only if the partial function
-      is defined on domain value \p i.
+      The function returns a negative value if the partial function
+      is not defined on domain value \p i.
     */
-    boolean maps(Long i, By_Reference<Long> j);
+    long maps(long i);
 }
diff --git a/interfaces/Java/tests/Test_Partial_Function.java b/interfaces/Java/tests/Test_Partial_Function.java
index cdff40b..7375851 100644
--- a/interfaces/Java/tests/Test_Partial_Function.java
+++ b/interfaces/Java/tests/Test_Partial_Function.java
@@ -37,12 +37,11 @@ public class Test_Partial_Function implements Partial_Function {
 	max  = 0;
     }
 
-    public boolean maps(Long i, By_Reference<Long> j) {
-	if (map.containsKey(i)) {
-	    j.set(map.get(i));
-	    return true;
-	}
-        return false;
+    public long maps(long i) {
+	if (map.containsKey(i))
+	    return map.get(i);
+        else
+            return -1;
     }
 
     public long max_in_codomain() {




More information about the PPL-devel mailing list