Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename Java API package

  • Loading branch information...
commit 2fcbda771dd5a603c7264d527b2ff9fdfbd6bfbb 1 parent e996a6a
@xerial authored
View
6 README.md
@@ -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
```
View
2  project/Build.scala
@@ -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
),
View
24 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);
+ }
+
+
+}
View
39 src/main/java/xerial/larray/java/LArray.java
@@ -1,39 +0,0 @@
-package xerial.larray.java;
-
-/**
- * Java interface of LArray
- * @author Taro L. Saito
- */
-public interface LArray<A> {
-
-// /**
-// * Get an element at the given index
-// * @param i index
-// * @return element
-// */
-// public A get(long i);
-//
-// /**
-// * Set the element at the specified index
-// * @param i index
-// * @param v value to set
-// * @return new value that is set
-// */
-// public A set(long i, A v);
-
- /**
- * Array size
- */
- public long size();
-
- /**
- * Release the memory resource held by this LArray
- */
- public void free();
-
- /**
- * Byte length of this LArray
- * @return
- */
- public long byteLength();
-}
View
45 src/main/java/xerial/larray/java/LByteArray.java
@@ -1,45 +0,0 @@
-package xerial.larray.java;
-
-import xerial.larray.Memory;
-
-/**
- * @author Taro L. Saito
- */
-public class LByteArray implements LArray<Byte> {
-
- private final long size;
- private final Memory m;
-
- public LByteArray(long size) {
- this(size, MemoryAllocator.defaultAllocator.allocate(size));
- }
-
- LByteArray(long size, Memory m) {
- this.size = size;
- this.m = m;
- }
-
- public byte get(long i) {
- return m.getByte(i);
- }
-
- public byte set(long i, byte v) {
- m.putByte(i, v);
- return v;
- }
-
- @Override
- public long size() {
- return size;
- }
-
- @Override
- public void free() {
- m.free();
- }
-
- @Override
- public long byteLength() {
- return size;
- }
-}
View
10 src/main/java/xerial/larray/java/MemoryAllocator.java
@@ -1,10 +0,0 @@
-package xerial.larray.java;
-
-import xerial.larray.DefaultAllocator;
-
-/**
- * @author Taro L. Saito
- */
-class MemoryAllocator {
- static xerial.larray.MemoryAllocator defaultAllocator = new DefaultAllocator();
-}
View
6 src/main/scala/xerial/larray/LArray.scala
@@ -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]]
@@ -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 = {
View
24 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) }
+
+}
View
28 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();
+ }
+}
View
3  src/test/scala/xerial/larray/LArraySpec.scala
@@ -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
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.