Skip to content

Commit

Permalink
Rename Java API package
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Mar 21, 2013
1 parent e996a6a commit 2fcbda7
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 101 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -67,9 +67,13 @@ l2(0) // The result of accessing released LArray is undefined
In Java we cannot provide concise syntaxes as in Scala. Instead, use `apply` and `update` methods to read/write values in arrays.

```java
import xerial.larray.japi.LArray;
import xerial.larray.LIntArray;

LIntArray l = new LIntArray(10000L);
LIntArray l = LArray.newLIntArray(10000L);
l.update(0L, 20) // Set l[0L] = 20
l.apply(0L) // Get l[0L]

// release
l.free
```
2 changes: 2 additions & 0 deletions project/Build.scala
Expand Up @@ -47,6 +47,8 @@ object Build extends sbt.Build {
libraryDependencies ++= Seq(
// Add dependent jars here
"org.xerial" % "xerial-core" % "3.1",
"junit" % "junit" % "4.10" % "test",
"com.novocode" % "junit-interface" % "0.10-M2" % "test",
"org.scalatest" %% "scalatest" % "2.0.M5b" % "test",
"org.scala-lang" % "scala-reflect" % SCALA_VERSION
),
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/xerial/larray/japi/LArray.java
@@ -0,0 +1,24 @@
package xerial.larray.japi;

import xerial.larray.DefaultAllocator;
import xerial.larray.LByteArray;
import xerial.larray.LIntArray;

/**
* Java interface of LArray
* @author Taro L. Saito
*/
public class LArray {

static xerial.larray.MemoryAllocator defaultAllocator = new DefaultAllocator();

public static LIntArray newLIntArray(long size) {
return new LIntArray(size, defaultAllocator);
}

public static LByteArray newLByteArray(long size) {
return new LByteArray(size, defaultAllocator);
}


}
39 changes: 0 additions & 39 deletions src/main/java/xerial/larray/java/LArray.java

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/java/xerial/larray/java/LByteArray.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/xerial/larray/java/MemoryAllocator.java

This file was deleted.

6 changes: 2 additions & 4 deletions src/main/scala/xerial/larray/LArray.scala
Expand Up @@ -95,8 +95,7 @@ object LArray {

def apply() = EmptyArray


import java.{lang=>jl}
import _root_.java.{lang=>jl}

private[larray] def wrap[A:ClassTag](size:Long, m:Memory) : LArray[A] = {
val tag = implicitly[ClassTag[A]]
Expand Down Expand Up @@ -351,8 +350,7 @@ class LIntArray(val size: Long, private[larray] val m:Memory)(implicit alloc: Me
extends LArray[Int]
with UnsafeArray[Int]
{
def this(size: Long)(implicit alloc: MemoryAllocator) = this(size, alloc.allocate(size << 2))

def this(size: Long)(implicit alloc: MemoryAllocator = MemoryAllocator.default) = this(size, alloc.allocate(size << 2))
import UnsafeUtil.unsafe

def apply(i: Long): Int = {
Expand Down
24 changes: 24 additions & 0 deletions src/main/scala/xerial/larray/Logger.scala
@@ -0,0 +1,24 @@
//--------------------------------------
//
// Logger.scala
// Since: 2013/03/22 2:32
//
//--------------------------------------

package xerial.larray

/**
* Logger wrapper for using [[xerial.core.log.Logger]] in Java
* @author Taro L. Saito
*/
class Logger(cl:Class[_]) {
private val _logger = xerial.core.log.LoggerFactory(cl)

def trace(m:String) { _logger.trace(m) }
def debug(m:String) { _logger.debug(m) }
def info(m:String) { _logger.info(m) }
def warn(m:String) { _logger.warn(m) }
def error(m:String) { _logger.error(m) }
def fatal(m:String) { _logger.fatal(m) }

}
28 changes: 28 additions & 0 deletions src/test/java/xerial/larray/japi/JLArrayTest.java
@@ -0,0 +1,28 @@
package xerial.larray.japi;

import junit.framework.Assert;
import org.junit.Test;
import xerial.larray.LIntArray;
import xerial.larray.Logger;

/**
* @author Taro L. Saito
*/
public class JLArrayTest {

Logger _logger = new Logger(this.getClass());

@Test
public void constructor() {

LIntArray l = LArray.newLIntArray(5L);
for (long i = 0; i < l.size(); ++i) l.update(i, (int) i * 2);
_logger.debug(l.mkString(", "));
for (long i = 0; i < l.size(); ++i) l.update(i, (int) (i * i));
_logger.debug(l.mkString(", "));

Assert.assertEquals(5L, l.size());

l.free();
}
}
3 changes: 1 addition & 2 deletions src/test/scala/xerial/larray/LArraySpec.scala
Expand Up @@ -9,7 +9,6 @@ package xerial.larray

import org.scalatest.matchers.{MustMatchers, ShouldMatchers}
import xerial.core.util.Timer
import xerial.core.log.Logger
import org.scalatest._
import java.io.ByteArrayOutputStream
import scala.language.implicitConversions
Expand All @@ -19,7 +18,7 @@ import xerial.core.io.Resource
/**
* @author leo
*/
trait LArraySpec extends WordSpec with ShouldMatchers with MustMatchers with GivenWhenThen with OptionValues with Resource with Timer with Logger
trait LArraySpec extends WordSpec with ShouldMatchers with MustMatchers with GivenWhenThen with OptionValues with Resource with Timer with xerial.core.log.Logger
with BeforeAndAfterAll with BeforeAndAfter with BeforeAndAfterEach {

implicit def toTag(t:String) = Tag(t)
Expand Down

0 comments on commit 2fcbda7

Please sign in to comment.