File: comparison.R

package info (click to toggle)
rjava 0.9-3-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,196 kB
  • sloc: java: 7,733; ansic: 4,947; sh: 2,878; makefile: 137; perl: 33
file content (49 lines) | stat: -rw-r--r-- 1,669 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#' if a and b are compatable, 
#' in the sense of the java.util.Comparable interface
#' then the result of the compareTo method is returned
#' otherwise an error message is generated
.jcompare <- function(a, b) {
  if (is.null(a)) a <- new("jobjRef")
  if (is.null(b)) b <- new("jobjRef")
  
  if( isJavaArray(a) || isJavaArray(b) ){
  	  stop( "comparison (<,>,<=,>=) is not implemented for java arrays yet" )
  }
  
  if( !is(a, "jobjRef" ) ) a <- ._java_valid_object( a )
  if( !is(b, "jobjRef" ) ) b <- ._java_valid_object( b )
  
  .jcall( "RJavaComparator", "I", "compare", .jcast(a), .jcast(b) )
  
}
._lower <- function(e1, e2){
	.jcompare( e1, e2 ) <= 0L
}
._greater <- function(e1, e2 ){
	.jcompare( e1, e2 ) >= 0L
}
._strictly_lower <- function(e1, e2 ){
	.jcompare( e1, e2 ) < 0L
}
._strictly_greater <- function(e1, e2 ){
	.jcompare( e1, e2 ) > 0L
}

setMethod("<" , c(e1="jobjRef",e2="jobjRef"), ._strictly_lower )
setMethod("<" , c(e1="jobjRef")             , ._strictly_lower )
setMethod("<" , c(e2="jobjRef")             , ._strictly_lower )
              
setMethod(">" , c(e1="jobjRef",e2="jobjRef"), ._strictly_greater )
setMethod(">" , c(e1="jobjRef")             , ._strictly_greater )
setMethod(">" , c(e2="jobjRef")             , ._strictly_greater )

setMethod("<=", c(e1="jobjRef",e2="jobjRef"), ._lower )
setMethod("<=", c(e1="jobjRef")             , ._lower )
setMethod("<=", c(e2="jobjRef")             , ._lower )
                                               
setMethod(">=", c(e1="jobjRef",e2="jobjRef"), ._greater )
setMethod(">=", c(e1="jobjRef")             , ._greater )
setMethod(">=", c(e2="jobjRef")             , ._greater )