KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > services > io > FormatableLongHolder


1 /*
2
3    Derby - Class org.apache.derby.iapi.services.io.FormatableLongHolder
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.services.io;
23
24 import org.apache.derby.iapi.services.io.ArrayInputStream;
25
26 import org.apache.derby.iapi.services.io.FormatIdUtil;
27 import org.apache.derby.iapi.services.io.Formatable;
28 import org.apache.derby.iapi.services.io.StoredFormatIds;
29
30 import java.io.ObjectOutput JavaDoc;
31 import java.io.ObjectInput JavaDoc;
32 import java.io.IOException JavaDoc;
33
34 /**
35  * A formatable holder for an long.
36  */

37 public class FormatableLongHolder implements Formatable
38 {
39
40     // the int
41
private long theLong;
42     
43     /**
44      * Niladic constructor for formatable
45      */

46     public FormatableLongHolder()
47     {
48     }
49
50     /**
51      * Construct a FormatableLongHolder using the input integer.
52      *
53      * @param theLong the long to hold
54      */

55     public FormatableLongHolder(long theLong)
56     {
57         this.theLong = theLong;
58     }
59
60     /**
61      * Set the held long to the input int.
62      *
63      * @param theLong the int to hold
64      */

65     public void setLong(int theLong)
66     {
67         this.theLong = theLong;
68     }
69
70     /**
71      * Get the held int.
72      *
73      * @return The held int.
74      */

75     public long getLong()
76     {
77         return theLong;
78     }
79
80     /**
81      * Create and return an array of FormatableLongHolders
82      * given an array of ints.
83      *
84      * @param theLongs The array of longs
85      *
86      * @return An array of FormatableLongHolders
87      */

88     public static FormatableLongHolder[] getFormatableLongHolders(long[] theLongs)
89     {
90         if (theLongs == null)
91         {
92             return null;
93         }
94
95         FormatableLongHolder[] flhArray = new FormatableLongHolder[theLongs.length];
96
97         for (int index = 0; index < theLongs.length; index++)
98         {
99             flhArray[index] = new FormatableLongHolder(theLongs[index]);
100         }
101         return flhArray;
102     }
103
104     //////////////////////////////////////////////
105
//
106
// FORMATABLE
107
//
108
//////////////////////////////////////////////
109
/**
110      * Write this formatable out
111      *
112      * @param out write bytes here
113      *
114      * @exception IOException thrown on error
115      */

116     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
117     {
118         out.writeLong(theLong);
119     }
120
121     /**
122      * Read this formatable from a stream of stored objects.
123      *
124      * @param in read this.
125      *
126      * @exception IOException thrown on error
127      */

128     public void readExternal(ObjectInput JavaDoc in)
129         throws IOException JavaDoc
130     {
131         theLong = in.readLong();
132     }
133     public void readExternal(ArrayInputStream in)
134         throws IOException JavaDoc
135     {
136         theLong = in.readLong();
137     }
138     
139     /**
140      * Get the formatID which corresponds to this class.
141      *
142      * @return the formatID of this class
143      */

144     public int getTypeFormatId() { return StoredFormatIds.FORMATABLE_LONG_HOLDER_V01_ID; }
145 }
146
Popular Tags