New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and check array types for JSS:JMAP/J2LIST. #60

Closed
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+30 −6
Diff settings

Always

Just for now

Fix and check array types for JSS:JMAP/J2LIST.

  • Loading branch information...
Ferada committed Jul 4, 2017
commit 852463daac38615e30b6c4f1db0aeb4e32e7e2b8
@@ -142,8 +142,11 @@ arguments, key and value."
((jcall isinstance (load-time-value (ignore-errors (jclass "java.util.Dictionary"))) thing)
(iterator-run (#"elements" thing)))
(t
(let ((array (ignore-errors (#"toArray" thing))))
(if array
(let ((jarray (ignore-errors
(or (and (jclass-array-p (jclass-of thing))
thing)
(#"toArray" thing)))))
(if jarray
(loop :for i :from 0 :below (jarray-length jarray)
:do (funcall function (jarray-ref jarray i)))
(error "yet another iteration type - fix it: ~a" (jclass-name (jobject-class thing)))))))))
@@ -192,9 +195,13 @@ iterators or a Java array."
((jcall isinstance (load-time-value (ignore-errors (jclass "java.util.Dictionary"))) thing)
(iterator-collect (#"elements" thing)))
(t
(let ((array (ignore-errors (#"toArray" thing))))
(if array
(coerce array 'list)
(let ((jarray (ignore-errors
(or (and (jclass-array-p (jclass-of thing))
thing)
(#"toArray" thing)))))
(if jarray
(loop :for i :from 0 :below (jarray-length jarray)
:collect (jarray-ref jarray i))
(error "yet another iteration type - fix it: ~a" (jclass-name (jobject-class thing))))))))))
(defun to-hashset (list)
@@ -7,7 +7,24 @@
"Checking whether JSS:TO-HASHSET produces a Java object…")
(prove:ok (jss:jmap 'constantly
(java:jnew-array "java.lang.Integer" 10))
"Checking JSS:MAP on Java array of java.lang.Integer…"))
"Checking JSS:JMAP on Java array of java.lang.Integer…")
(prove:ok (jss:j2list (java:jnew-array "java.lang.Integer" 10))
"Checking JSS:J2LIST on Java array of java.langInteger…")
(prove:is (let (list)
(jss:jmap (lambda (x) (push x list))
(let ((jarray (java:jnew-array "int" 3)))
(jarray-set jarray 1 1)
(jarray-set jarray 2 2)
jarray))
(nreverse list))
'(0 1 2)
"Checking JSS:JMAP on Java array of int…")
(prove:is (jss:j2list (let ((jarray (java:jnew-array "int" 3)))
(jarray-set jarray 1 1)
(jarray-set jarray 2 2)
jarray))
'(0 1 2)
"Checking JSS:J2LIST on Java array of int…"))
(prove:finalize)