View Javadoc

1   // -- FILE ------------------------------------------------------------------
2   // name       : AsnByteArrayValueBase.java
3   // project    : Panter: LI
4   // created    : lep - 2007.01.16
5   // language   : java
6   // environment: JDK 1.5.0
7   // copyright  : (c) 2006 by Panter llc, Switzerland
8   // license    : this is free software licensed under the GPL. see COPYING
9   // --------------------------------------------------------------------------
10  package ch.panter.li.bi.asn.value;
11  
12  import ch.panter.li.bi.asn.model.AsnType;
13  import ch.panter.li.bi.util.HashCodeTool;
14  
15  import java.util.Arrays;
16  
17  
18  public abstract class AsnByteArrayValueBase extends AsnSimpleValueBase
19  {
20  
21    /* package protected */ AsnByteArrayValueBase( final AsnType type )
22    {
23      super( type );
24    } // AsnByteArrayValueBase
25  
26    /* package protected */ AsnByteArrayValueBase( final AsnByteArrayValueBase copy )
27    {
28      super( copy );
29      this.data = copy.data != null ? copy.data.clone() : null;
30    } // AsnByteArrayValueBase
31  
32    protected final byte[] getData()
33    {
34      return data;
35    } // getData
36  
37    protected final void setData( final byte[] data )
38    {
39      this.data = data;
40    } // setData
41  
42    protected boolean isEqualTo( final Object compare )
43    {
44      final AsnByteArrayValueBase comp = (AsnByteArrayValueBase)compare;
45      return super.isEqualTo( compare ) &&
46        Arrays.equals( this.data, comp.data );
47    } // isEqualTo
48  
49    protected int computeHashCode( final int baseHash )
50    {
51      int hash = super.computeHashCode( baseHash );
52      hash = HashCodeTool.addHashCode( hash, data );
53      return hash;
54    } // computeHashCode
55  
56    public String toString()
57    {
58      // TODO: encode bits to human readable hex format
59      return "[" + ( data == null ? "" :  data  ) + "]";
60    } // toString
61  
62    // members
63    private byte[] data;
64  
65  } // class AsnByteArrayValueBase
66  
67  // -- EOF -------------------------------------------------------------------