View Javadoc

1   /*
2    * jGuild Project: jRPM
3    * Released under the Apache License ( http://www.apache.org/LICENSE )
4    */
5   package com.jguild.jrpm.io.datatype;
6   
7   import org.apache.log4j.Logger;
8   
9   import com.jguild.jrpm.io.IndexEntry;
10  import com.jguild.jrpm.io.constant.RPMIndexType;
11  
12  /***
13   * A representation of a rpm null array data object
14   * 
15   * @author kuss
16   */
17  public class NULL implements DataTypeIf {
18  
19      private static final Logger logger = Logger.getLogger(NULL.class);
20  
21      private Object[] data;
22  
23      NULL(int size) {
24          data = new Object[size];
25      }
26  
27      /*
28       * @see com.jguild.jrpm.io.datatype.DataTypeIf#isArray()
29       */
30      public boolean isArray() {
31          return true;
32      }
33  
34      /***
35       * Get the rpm NULL array as a java object array of null objects
36       * 
37       * @return An array of null objects
38       */
39      public Object[] getData() {
40          return data;
41      }
42  
43      /*
44       * @see com.jguild.jrpm.io.datatype.DataTypeIf#getData()
45       */
46      public Object getDataObject() {
47          return data;
48      }
49  
50      /*
51       * @see com.jguild.jrpm.io.datatype.DataTypeIf#getSize()
52       */
53      public long getSize() {
54          return 0;
55      }
56  
57      /*
58       * @see com.jguild.jrpm.io.datatype.DataTypeIf#getType()
59       */
60      public RPMIndexType getType() {
61          return RPMIndexType.NULL;
62      }
63  
64      /***
65       * Constructs a type froma stream
66       * 
67       * @param indexEntry
68       *           The index informations
69       * @return The size of the read data
70       */
71      public static NULL readFromStream(IndexEntry indexEntry) {
72          if (indexEntry.getType() != RPMIndexType.NULL) { throw new IllegalArgumentException(
73                  "Type <" + indexEntry.getType() + "> does not match <"
74                          + RPMIndexType.NULL + ">"); }
75  
76          NULL nullObject = new NULL((int) indexEntry.getCount());
77  
78          if (logger.isDebugEnabled()) {
79              logger.debug(nullObject.toString());
80          }
81  
82          //nullObject.size = indexEntry.getType().getSize() *
83          // indexEntry.getCount();
84  
85          return nullObject;
86      }
87  
88      /*
89       * @see com.jguild.jrpm.io.datatype.DataTypeIf#getElementCount()
90       */
91      public long getElementCount() {
92          return data.length;
93      }
94  
95      /*
96       * @see com.jguild.jrpm.io.datatype.DataTypeIf#get(int)
97       */
98      public Object get(int i) {
99          return data[i];
100     }
101 
102     /*
103      * @see java.lang.Object#toString()
104      */
105     public String toString() {
106         StringBuffer buf = new StringBuffer();
107 
108         if (data.length > 1) {
109             buf.append("[");
110         }
111 
112         for (int pos = 0; pos < data.length; pos++) {
113             buf.append(data[pos]);
114 
115             if (pos < (data.length - 1)) {
116                 buf.append(", ");
117             }
118         }
119 
120         if (data.length > 1) {
121             buf.append("]");
122         }
123 
124         return buf.toString();
125     }
126 }