You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2008/08/22 10:30:31 UTC
svn commit: r688018 - in /incubator/hama/trunk/src:
java/org/apache/hama/AbstractMatrix.java
test/org/apache/hama/util/TestNumeric.java
Author: edwardyoon
Date: Fri Aug 22 01:30:30 2008
New Revision: 688018
URL: http://svn.apache.org/viewvc?rev=688018&view=rev
Log: (empty)
Added:
incubator/hama/trunk/src/test/org/apache/hama/util/TestNumeric.java
Modified:
incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
Modified: incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java?rev=688018&r1=688017&r2=688018&view=diff
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java (original)
+++ incubator/hama/trunk/src/java/org/apache/hama/AbstractMatrix.java Fri Aug 22 01:30:30 2008
@@ -79,12 +79,11 @@
/** {@inheritDoc} */
public double get(int i, int j) {
- String row = String.valueOf(i);
- String column = Constants.COLUMN + String.valueOf(j);
Cell c;
double result = -1;
try {
- c = table.get(row, column);
+ c = table
+ .get(Bytes.toBytes(String.valueOf(i)), Numeric.getColumnIndex(j));
if (c != null) {
result = Numeric.bytesToDouble(c.getValue());
}
Added: incubator/hama/trunk/src/test/org/apache/hama/util/TestNumeric.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/util/TestNumeric.java?rev=688018&view=auto
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/util/TestNumeric.java (added)
+++ incubator/hama/trunk/src/test/org/apache/hama/util/TestNumeric.java Fri Aug 22 01:30:30 2008
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.util;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hama.Constants;
+
+public class TestNumeric extends TestCase {
+ final static int TEST_INT = 3;
+ final double TEST_DOUBLE = 0.4;
+
+ /**
+ * Integer conversion test
+ */
+ public void testInteger() {
+ assertEquals(Numeric.bytesToInt(Numeric.intToBytes(TEST_INT)), TEST_INT);
+ }
+
+ /**
+ * Double conversion test
+ */
+ public void testDouble() {
+ assertEquals(Numeric.bytesToDouble(Numeric.doubleToBytes(TEST_DOUBLE)),
+ TEST_DOUBLE);
+ }
+
+ /**
+ * Get the column index from hbase.
+ */
+ public void testGetColumnIndex() {
+ byte[] result = Numeric.getColumnIndex(3);
+ assertEquals(Bytes.toString(result), Constants.COLUMN
+ + Numeric.getColumnIndex(result));
+ }
+}