-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathExampleObject.java
More file actions
161 lines (159 loc) · 5.01 KB
/
ExampleObject.java
File metadata and controls
161 lines (159 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//package org.apache.geode.cache.query.data;
package javaobject;
import java.util.*;
import java.io.*;
import org.apache.geode.*;
import org.apache.geode.cache.Declarable;
/**
* @brief Example 13.8 Implementing Complex Data Types Using the Java API.
*/
public class ExampleObject implements DataSerializable {
private double double_field;
private long long_field;
private float float_field;
private int int_field;
private short short_field;
private java.lang.String string_field;
private Vector string_vector;
static {
Instantiator.register(new Instantiator(ExampleObject.class, (byte) 46)
{
public DataSerializable newInstance() {
return new ExampleObject();
}
});
}
public ExampleObject( ) {
this.double_field = 0.0D;
this.long_field = 0L;
this.float_field = 0.0F;
this.int_field = 0;
this.short_field = 0;
this.string_field = null;
this.string_vector = null;
}
public ExampleObject(int id) {
this.int_field = id;
this.string_field = String.valueOf(id);
this.short_field = Short.parseShort(string_field);
this.double_field = Double.parseDouble(string_field);
this.float_field = Float.parseFloat(string_field);
this.long_field = Long.parseLong(string_field);
this.string_vector = new Vector();
for (int i=0; i<3; i++) {
this.string_vector.addElement(string_field);
}
}
public ExampleObject(String id_str) {
this.int_field = Integer.parseInt(id_str);
this.string_field = id_str;
this.short_field = Short.parseShort(string_field);
this.double_field = Double.parseDouble(string_field);
this.float_field = Float.parseFloat(string_field);
this.long_field = Long.parseLong(string_field);
this.string_vector = new Vector();
for (int i=0; i<3; i++) {
this.string_vector.addElement(string_field);
}
}
public double getDouble_field( ) {
return this.double_field;
}
public void setDouble_field( double double_field ) {
this.double_field = double_field;
}
public long getLong_field( ) {
return this.long_field;
}
public void setLong_field( long long_field ) {
this.long_field = long_field;
}
public float getFloat_field( ) {
return this.float_field;
}
public void setFloat_field( float float_field ) {
this.float_field = float_field;
}
public int getInt_field( ) {
return this.int_field;
}
public void setInt_field( int int_field ) {
this.int_field = int_field;
}
public short getShort_field( ) {
return this.short_field;
}
public void setShort_field( short short_field ) {
this.short_field = short_field;
}
public java.lang.String getString_field( ) {
return this.string_field;
}
public void setString_field( java.lang.String string_field ) {
this.string_field = string_field;
}
public Vector getString_vector( ) {
return this.string_vector;
}
public void setString_vector( Vector string_vector ) {
this.string_vector = string_vector;
}
public void toData(DataOutput out) throws IOException
{
out.writeDouble(double_field);
out.writeFloat(float_field);
out.writeLong(long_field);
out.writeInt(int_field);
out.writeShort(short_field);
out.writeUTF(string_field);
out.writeInt(string_vector.size());
for (int i = 0; i < string_vector.size(); i++)
{
out.writeUTF((String)string_vector.elementAt(i));
}
}
public void fromData(DataInput in) throws IOException,
ClassNotFoundException
{
this.double_field = in.readDouble();
this.float_field = in.readFloat();
this.long_field = in.readLong();
this.int_field = in.readInt();
this.short_field = in.readShort();
this.string_field = in.readUTF();
this.string_vector = new Vector();
int size = in.readInt();
for (int i = 0; i < size; i++)
{
String s = in.readUTF();
string_vector.add(i, s);
}
}
public boolean equals(ExampleObject o)
{
if (this.double_field != o.double_field) return false;
if (this.float_field != o.float_field) return false;
if (this.long_field != o.long_field) return false;
if (this.int_field != o.int_field) return false;
if (this.short_field != o.short_field) return false;
if (!this.string_field.equals(o.string_field)) return false;
if (!this.string_vector.equals(o.string_vector)) return false;
return true;
}
}