File: instanceof.R

package info (click to toggle)
rjava 1.0-11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,184 kB
  • sloc: java: 13,223; ansic: 5,479; sh: 3,776; xml: 325; makefile: 250; perl: 33
file content (25 lines) | stat: -rw-r--r-- 632 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
`%instanceof%` <- .jinstanceof <- function( o, cl ){
	
	if( !inherits( o, "jobjRef" ) ){
		stop( "o is not a java object" )
	}
	
	# first get the class object that represents cl
	if( inherits( cl, "jobjRef" ) ){
		if( .jclass( cl ) == "java.lang.Class" ){
			clazz <- cl
		} else {
			clazz <- .jcall( cl, "Ljava/lang/Class;", "getClass" ) 
		}
	} else if( inherits( cl, "jclassName" ) ) {
		clazz <- cl@jobj
	} else if( inherits( cl, "character" ) ){
		clazz <- .jfindClass(cl)
	} else {
		return(FALSE)
	}
	
	# then find out if o is an instance of the class
	.jcall( clazz , "Z", "isInstance", .jcast(o, "java/lang/Object" ) )
}