BSimple
is the base class for all atomic data types
in Niagara. As an atomic data type, BSimples
store
a simple piece of data which cannot be decomposed. All simples are
immutable, that is once an instance is created it may never change
its state. Concrete subclasses of BSimples
must meet
the following requirements:
BObjects
;
public static final
field named
DEFAULT
which contains a reference to the default
instance for the BSimple
;
BSimples
must be immutable! Under no circumstances
should there be any way for an instance of BSimple
to
have its state changed after construction;
BSimple
must be
declared final;
BSimple
must implement the equals()
method to compare the equality of its atomic data;
BSimple
must implement binary serialization:
public abstract void encode(DataOutput out);
public abstract BObject decode(DataInput in);
BSimple
must implement text serialization:
public abstract String encodeToString();
public abstract BObject decodeFromString(String s);
make
.
/*
* Copyright 2000 Tridium, Inc. All Rights Reserved.
*/
package javax.baja.sys;
import java.io.*;
/**
* The BInteger is the wrapper class for Java primitive
* int objects.
*/
public final class BInteger
extends BNumber
{
public static BInteger make(int value)
{
if (value == 0) return DEFAULT;
return new BInteger(value);
}
private BInteger(int value)
{
this.value = value;
}
public int getInt()
{
return value;
}
public float getFloat()
{
return (float)value;
}
public int hashCode()
{
return value;
}
public boolean equals(Object obj)
{
if (obj instanceof BInteger)
return ((BInteger)obj).value == value;
return false;
}
public String toString(Context context)
{
return String.valueOf(value);
}
public void encode(DataOutput out)
throws IOException
{
out.writeInt(value);
}
public BObject decode(DataInput in)
throws IOException
{
return new BInteger( in.readInt() );
}
public String encodeToString()
throws IOException
{
return String.valueOf(value);
}
public BObject decodeFromString(String s)
throws IOException
{
try
{
return new BInteger( Integer.parseInt(s) );
}
catch(Exception e)
{
throw new IOException("Invalid integer: " + s);
}
}
public static final BInteger DEFAULT = new BInteger(0);
public Type getType() { return TYPE; }
public static final Type TYPE = Sys.loadType(BInteger.class);
private int value;
}
Copyright © 2000-2019 Tridium Inc. All rights reserved.