File: 0classes.R

package info (click to toggle)
rjava 1.0-14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,188 kB
  • sloc: java: 13,223; ansic: 5,503; sh: 3,776; xml: 325; makefile: 250; perl: 33
file content (56 lines) | stat: -rw-r--r-- 1,884 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
## S4 classes (jobjRef is re-defined in .First.lib to contain valid jobj)                                                                                                  
#' java object reference
setClass("jobjRef", representation(jobj="externalptr", jclass="character"), 
	prototype=list(jobj=NULL, jclass="java/lang/Object"))

#' rugged arrays
setClass("jarrayRef", representation("jobjRef", jsig="character"))

#' rectangular java arrays double[][] d = new double[m][n]
setClass("jrectRef", 
	representation("jarrayRef", dimension="integer" ) ) 



# we extend array here so that we can keep dimensions
# in the helper functions below, the storage mode is 
# set when the objects are built
# TODO: maybe an initialize method is needed here
# TODO: maybe a validate method is needed here as well
setClass("jfloat", representation("array" ) )
setClass("jlong", representation("array" )  )
setClass("jbyte", representation("array" )  )
setClass("jshort", representation("array" ) )
setClass("jchar", representation("array" )  )

# there is no way to distinguish between double and float in R, so we need to mark floats specifically
.jfloat <- function(x) {
	storage.mode( x ) <- "double"
	new("jfloat", x )
}
# the same applies to long
.jlong <- function(x) {
	storage.mode( x ) <- "double"
	new("jlong", x)
}
# and byte
.jbyte <- function(x) {
	storage.mode( x ) <- "integer"
	new("jbyte", x)
}
# and short
.jshort <- function(x){
	storage.mode( x ) <- "integer"
	new("jshort", x)
}
# and char (experimental)
.jchar <- function(x){
    if (is.character(x)) {
        if (length(x) != 1L || is.na(x))
            stop(".jchar() supports only (non-NA) character vectors of length one (aka strings)")
        ## use Java to actually do the conversion
        x <- .jcall(.jnew("java.lang.String", x), "[C", "toCharArray")
    }
    storage.mode( x ) <- "integer"
    new("jchar", x)
}