[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r2907 - in freeway/src/org/gnu/freeway/cwrappers: . util
From: |
mdonoughe |
Subject: |
[GNUnet-SVN] r2907 - in freeway/src/org/gnu/freeway/cwrappers: . util |
Date: |
Fri, 26 May 2006 12:41:30 -0700 (PDT) |
Author: mdonoughe
Date: 2006-05-26 12:41:26 -0700 (Fri, 26 May 2006)
New Revision: 2907
Added:
freeway/src/org/gnu/freeway/cwrappers/util/ConstCWrapper.java
Modified:
freeway/src/org/gnu/freeway/cwrappers/CInt.java
freeway/src/org/gnu/freeway/cwrappers/CUnsignedInt.java
freeway/src/org/gnu/freeway/cwrappers/CUnsignedIntTest.java
freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java
freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java
freeway/src/org/gnu/freeway/cwrappers/util/CWrapper.java
Log:
Made CUnsignedInt.validate(long) constant
changed private values to protected in CUnsignedInt and CInt
made serializeToByteArray functions into one liners
removed longToUnsignedInt(long)
made a new wrapper interface ConstCWrapper. CWrapper is now a subinterface of
this.
implementations of CWrapper are now subclasses of their ConstCWrapper
equivalents.
Modified: freeway/src/org/gnu/freeway/cwrappers/CInt.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/CInt.java 2006-05-26 18:49:23 UTC
(rev 2906)
+++ freeway/src/org/gnu/freeway/cwrappers/CInt.java 2006-05-26 19:41:26 UTC
(rev 2907)
@@ -26,36 +26,18 @@
* @brief A wrapper for using integers with JNI
* @author mdonoughe
*/
-public class CInt implements CWrapper {
+public class CInt extends ConstCInt implements CWrapper {
- private int value;
-
public CInt(int value) {
- this.value = value;
+ super(value);
}
-
- /**
- * Returns a byte array containing the integer in big endian format
- */
- public byte[] serializeToByteArray() {
- byte[] retValue = {(byte) (value >> 24), (byte) (value >> 16),
(byte) (value >> 8), (byte) value};
- return retValue;
- }
public void deserializeFromByteArray(byte[] serializedData) {
// those bitmasks seem to keep the sign bit from moving around
value = ((serializedData[0] & 0xff) << 24) |
((serializedData[1] & 0xff) << 16) | ((serializedData[2] & 0xff) << 8) |
((serializedData[3] & 0xff));
}
-
- public int getValue() {
- return value;
- }
public void setValue(int value) {
this.value = value;
}
-
- public int getSerializedSize() {
- return 4;
- }
}
Modified: freeway/src/org/gnu/freeway/cwrappers/CUnsignedInt.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/CUnsignedInt.java 2006-05-26
18:49:23 UTC (rev 2906)
+++ freeway/src/org/gnu/freeway/cwrappers/CUnsignedInt.java 2006-05-26
19:41:26 UTC (rev 2907)
@@ -26,56 +26,19 @@
* @brief A wrapper for using unsigned integers with JNI
* @author mdonoughe
*/
-public class CUnsignedInt implements CWrapper {
+public class CUnsignedInt extends ConstCUnsignedInt implements CWrapper {
- private long value;
-
public CUnsignedInt(long value) {
- validate(value);
- this.value = value;
+ super(value);
}
-
- private void validate(long value) {
- if(value < 0 || value > 4294967295l)
- throw new IllegalArgumentException("Unsigned integers
cannot be less than 0 or more than 4,294,967,295.");
- return;
- }
-
- /**
- * Returns a byte array containing the integer in big endian format
- */
- public byte[] serializeToByteArray() {
- byte[] retValue = {(byte) (value >> 24), (byte) (value >> 16),
(byte) (value >> 8), (byte) value};
- return retValue;
- }
public void deserializeFromByteArray(byte[] serializedData) {
// those bitmasks seem to keep the sign bit from moving around
value = ((serializedData[0] & 0xffl) << 24) |
((serializedData[1] & 0xffl) << 16) | ((serializedData[2] & 0xffl) << 8) |
((serializedData[3] & 0xffl));
}
-
- public long getValue() {
- return value;
- }
public void setValue(long value) {
validate(value);
this.value = value;
}
-
- public int getSerializedSize() {
- return 4;
- }
-
- public static CUnsignedInt boxSignedInt(int value) {
- return new CUnsignedInt(unsignedIntToLong(value));
- }
-
- public static long unsignedIntToLong(int value) {
- return value & 0xFFFFFFFFl;
- }
-
- public static int longToUnsignedInt(long value) {
- return (int) (value & 0xFFFFFFFFl);
- }
}
Modified: freeway/src/org/gnu/freeway/cwrappers/CUnsignedIntTest.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/CUnsignedIntTest.java 2006-05-26
18:49:23 UTC (rev 2906)
+++ freeway/src/org/gnu/freeway/cwrappers/CUnsignedIntTest.java 2006-05-26
19:41:26 UTC (rev 2907)
@@ -89,14 +89,4 @@
assertTrue(CUnsignedInt.unsignedIntToLong(-1) == 4294967295l);
assertTrue(CUnsignedInt.unsignedIntToLong(0xffffffff) ==
0xffffffffl);
}
-
- /*
- * Test method for
'org.gnu.freeway.cwrappers.CUnsignedInt.longToUnsignedInt(long)'
- */
- public void testLongToUnsignedInt() {
- assertTrue(CUnsignedInt.longToUnsignedInt(1l) == 1);
- assertTrue(CUnsignedInt.longToUnsignedInt(4294967295l) == -1);
- assertTrue(CUnsignedInt.longToUnsignedInt(0xffffffffl) ==
0xffffffff);
- }
-
}
Modified: freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java 2006-05-26
18:49:23 UTC (rev 2906)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java 2006-05-26
19:41:26 UTC (rev 2907)
@@ -19,17 +19,17 @@
package org.gnu.freeway.cwrappers;
-import org.gnu.freeway.cwrappers.util.CWrapper;
+import org.gnu.freeway.cwrappers.util.ConstCWrapper;
/**
* @file freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java
* @brief A wrapper for using constant integers with JNI
* @author mdonoughe
*/
-public class ConstCInt implements CWrapper {
-
- private int value;
+public class ConstCInt implements ConstCWrapper {
+ protected int value;
+
public ConstCInt(int value) {
this.value = value;
}
@@ -38,14 +38,9 @@
* Returns a byte array containing the integer in big endian format
*/
public byte[] serializeToByteArray() {
- byte[] retValue = {(byte) (value >> 24), (byte) (value >> 16),
(byte) (value >> 8), (byte) value};
- return retValue;
+ return new byte[] {(byte) (value >> 24), (byte) (value >> 16),
(byte) (value >> 8), (byte) value};
}
- public void deserializeFromByteArray(byte[] serializedData) {
- return; // this is a constant type
- }
-
public int getValue() {
return value;
}
Modified: freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java
2006-05-26 18:49:23 UTC (rev 2906)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java
2006-05-26 19:41:26 UTC (rev 2907)
@@ -19,40 +19,34 @@
package org.gnu.freeway.cwrappers;
-import org.gnu.freeway.cwrappers.util.CWrapper;
+import org.gnu.freeway.cwrappers.util.ConstCWrapper;
/**
* @file freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java
* @brief A wrapper for using constant unsigned integers with JNI
* @author mdonoughe
*/
-public class ConstCUnsignedInt implements CWrapper {
+public class ConstCUnsignedInt implements ConstCWrapper {
- private long value;
+ protected long value;
public ConstCUnsignedInt(long value) {
validate(value);
this.value = value;
}
- private void validate(long value) {
+ protected static void validate(long value) {
if(value < 0 || value > 4294967295l)
throw new IllegalArgumentException("Unsigned integers
cannot be less than 0 or more than 4,294,967,295.");
- return;
}
/**
* Returns a byte array containing the integer in big endian format
*/
public byte[] serializeToByteArray() {
- byte[] retValue = {(byte) (value >> 24), (byte) (value >> 16),
(byte) (value >> 8), (byte) value};
- return retValue;
+ return new byte[] {(byte) (value >> 24), (byte) (value >> 16),
(byte) (value >> 8), (byte) value};
}
- public void deserializeFromByteArray(byte[] serializedData) {
- return; // this is a constant type
- }
-
public long getValue() {
return value;
}
@@ -61,15 +55,11 @@
return 4;
}
- public static ConstCUnsignedInt boxSignedInt(int value) {
- return new ConstCUnsignedInt(unsignedIntToLong(value));
+ public static CUnsignedInt boxSignedInt(int value) {
+ return new CUnsignedInt(unsignedIntToLong(value));
}
public static long unsignedIntToLong(int value) {
return value & 0xFFFFFFFFl;
}
-
- public static int longToUnsignedInt(long value) {
- return (int) (value & 0xFFFFFFFFl);
- }
}
Modified: freeway/src/org/gnu/freeway/cwrappers/util/CWrapper.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/util/CWrapper.java 2006-05-26
18:49:23 UTC (rev 2906)
+++ freeway/src/org/gnu/freeway/cwrappers/util/CWrapper.java 2006-05-26
19:41:26 UTC (rev 2907)
@@ -21,24 +21,12 @@
/**
- * @file freeway/src/org/gnu/freeway/cwrappers/util/CWrapper.java
+ * @file freeway/src/org/gnu/freeway/cwrappers/util/ConstCWrapper.java
* @brief A wrapper for use with JNI
* @author mdonoughe
* Implementations of this interface are used to pass arguments between
* Freeway and plugins that may be written in C.
*/
-public interface CWrapper {
- /**
- * Returns a byte array representation of the contained object.
- */
- public byte[] serializeToByteArray();
- /**
- * Decodes the given byte array and updates the contained object.
- * This function may be ignored by nonmutable types.
- */
+public interface CWrapper extends ConstCWrapper {
public void deserializeFromByteArray(byte[] serializedData);
- /**
- * Returns the size of the byte array created when serialized.
- */
- public int getSerializedSize();
}
Added: freeway/src/org/gnu/freeway/cwrappers/util/ConstCWrapper.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/util/ConstCWrapper.java
2006-05-26 18:49:23 UTC (rev 2906)
+++ freeway/src/org/gnu/freeway/cwrappers/util/ConstCWrapper.java
2006-05-26 19:41:26 UTC (rev 2907)
@@ -0,0 +1,39 @@
+ /*
+ This file is part of Freeway
+
+ Freeway is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ Freeway is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Freeway; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers.util;
+
+
+/**
+ * @file freeway/src/org/gnu/freeway/cwrappers/util/CWrapper.java
+ * @brief A wrapper for use with JNI
+ * @author mdonoughe
+ * Implementations of this interface are used to pass arguments between
+ * Freeway and plugins that may be written in C.
+ */
+public interface ConstCWrapper {
+ /**
+ * Returns a byte array representation of the contained object.
+ */
+ public byte[] serializeToByteArray();
+ /**
+ * Returns the size of the byte array created when serialized.
+ */
+ public int getSerializedSize();
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r2907 - in freeway/src/org/gnu/freeway/cwrappers: . util,
mdonoughe <=