-
Notifications
You must be signed in to change notification settings - Fork 868
/
OPhysicalPosition.java
executable file
·142 lines (115 loc) · 4.44 KB
/
OPhysicalPosition.java
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
/*
*
* * Copyright 2010-2016 OrientDB LTD (http://orientdb.com)
* *
* * Licensed 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.
* *
* * For more information: http://orientdb.com
*
*/
package com.orientechnologies.orient.core.storage;
import com.orientechnologies.orient.core.exception.OSerializationException;
import com.orientechnologies.orient.core.serialization.OBinaryProtocol;
import com.orientechnologies.orient.core.serialization.OSerializableStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
public class OPhysicalPosition implements OSerializableStream, Externalizable {
private static final int binarySize = OBinaryProtocol.SIZE_LONG + OBinaryProtocol.SIZE_BYTE + OBinaryProtocol.SIZE_INT
+ OBinaryProtocol.SIZE_INT;
public long clusterPosition;
public byte recordType;
public int recordVersion = 0;
public int recordSize;
public OPhysicalPosition() {
}
public OPhysicalPosition(final long iClusterPosition) {
clusterPosition = iClusterPosition;
}
public OPhysicalPosition(final byte iRecordType) {
recordType = iRecordType;
}
public OPhysicalPosition(final long iClusterPosition, final int iVersion) {
clusterPosition = iClusterPosition;
recordVersion = iVersion;
}
private void copyTo(final OPhysicalPosition iDest) {
iDest.clusterPosition = clusterPosition;
iDest.recordType = recordType;
iDest.recordVersion = recordVersion;
iDest.recordSize = recordSize;
}
public void copyFrom(final OPhysicalPosition iSource) {
iSource.copyTo(this);
}
@Override
public String toString() {
return "rid(?:" + clusterPosition + ") record(type:" + recordType + " size:" + recordSize + " v:" + recordVersion + ")";
}
@Override
public OSerializableStream fromStream(final byte[] iStream) throws OSerializationException {
int pos = 0;
clusterPosition = OBinaryProtocol.bytes2long(iStream);
pos += OBinaryProtocol.SIZE_LONG;
recordType = iStream[pos];
pos += OBinaryProtocol.SIZE_BYTE;
recordSize = OBinaryProtocol.bytes2int(iStream, pos);
pos += OBinaryProtocol.SIZE_INT;
recordVersion = OBinaryProtocol.bytes2int(iStream, pos);
return this;
}
@Override
public byte[] toStream() throws OSerializationException {
final byte[] buffer = new byte[binarySize];
int pos = 0;
OBinaryProtocol.long2bytes(clusterPosition, buffer, pos);
pos += OBinaryProtocol.SIZE_LONG;
buffer[pos] = recordType;
pos += OBinaryProtocol.SIZE_BYTE;
OBinaryProtocol.int2bytes(recordSize, buffer, pos);
pos += OBinaryProtocol.SIZE_INT;
OBinaryProtocol.int2bytes(recordVersion, buffer, pos);
return buffer;
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof OPhysicalPosition))
return false;
final OPhysicalPosition other = (OPhysicalPosition) obj;
return clusterPosition == other.clusterPosition && recordType == other.recordType && recordVersion == other.recordVersion
&& recordSize == other.recordSize;
}
@Override
public int hashCode() {
int result = (int) (31 * clusterPosition);
result = 31 * result + (int) recordType;
result = 31 * result + recordVersion;
result = 31 * result + recordSize;
return result;
}
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
out.writeLong(clusterPosition);
out.writeByte(recordType);
out.writeInt(recordSize);
out.writeInt(recordVersion);
}
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
clusterPosition = in.readLong();
recordType = in.readByte();
recordSize = in.readInt();
recordVersion = in.readInt();
}
}