Commit 983e2bd8 authored by Emeric Verschuur's avatar Emeric Verschuur
Browse files

Add Variant.clone() method

parent 80ab56d7
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -48,4 +48,13 @@
			</plugin>
		</plugins>
	</build>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</project>
 No newline at end of file
+22 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ import java.util.Random;
public abstract class Variant implements Comparable<Object> {

	public enum Type {
		BOOL, BYTE, BYTEARRAY, DATETIME, DOUBLE, SHORT, INT, LIST, LONG, MAP, NULL, STRING, USHORT, UINT, ULONG
		VOID, ANY, BOOL, BYTE, BYTEARRAY, DATETIME, DOUBLE, SHORT, INT, LIST, LONG, MAP, NULL, STRING, USHORT, UINT, ULONG
	}

	public enum Format {
@@ -51,8 +51,21 @@ public abstract class Variant implements Comparable<Object> {

	public static final Variant NULL = new VariantNull();

	/**
	 * Compact JSON format, without white spaces (flag used for serialization)
	 */
	public static int FORMAT_JSON_COMPACT = 0x00000020;

	/**
	 * Deep copy (flag used for clone method)
	 */
	public static int DEEP_COPY = 0x00000001;
	
	/**
	 * Make unmodifiable variant (applicable to cloned maps and lists)
	 */
	public static int UNMODIFIABLE = 0x00000002;

	public static Variant IUD_GENERATOR = new VariantString("") {
		private final long MSB = 0x8000000000000000L;

@@ -375,6 +388,14 @@ public abstract class Variant implements Comparable<Object> {
	 */
	public abstract Type type();
	
	/**
	 * Clone this variant (make a copy of)
	 * 
	 * @param flags 
	 * @return the cloned variant
	 */
	public abstract Variant clone(int flags);

	/**
	 * Abstract parser
	 */
+5 −0
Original line number Diff line number Diff line
@@ -125,4 +125,9 @@ public class VariantBool extends VariantNumber {
    public Type type() {
        return Type.BOOL;
    }

	@Override
	public Variant clone(int flags) {
		return new VariantBool(data);
	}
}
+7 −2
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public class VariantByte extends VariantNumber {
	 * Get the byte value using a binary mask
	 * 
	 * @param mask
	 * @return
	 * @return a byte value
	 */
	public byte byteValue(byte mask) {
		return (byte) (data & mask);
@@ -62,7 +62,7 @@ public class VariantByte extends VariantNumber {
	 *            sub value bit offset
	 * @param length
	 *            sub value bit length
	 * @return
	 * @return a byte value
	 */
	public byte byteValue(int offset, int length) {
		byte mask = 0;
@@ -156,4 +156,9 @@ public class VariantByte extends VariantNumber {
	public Type type() {
		return Type.BYTE;
	}

	@Override
	public Variant clone(int flags) {
		return new VariantByte(data);
	}
}
+5 −0
Original line number Diff line number Diff line
@@ -98,4 +98,9 @@ public class VariantByteArray extends Variant {
	public boolean isNull() {
		return data == null;
	}

	@Override
	public Variant clone(int flags) {
		return new VariantByteArray(data);
	}
}
Loading