1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client;
19
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.classification.InterfaceStability;
28 import org.apache.hadoop.hbase.util.Bytes;
29
30
31
32
33
34
35
36
37
38
39
40 @InterfaceAudience.Public
41 @InterfaceStability.Evolving
42 public class RowMutations implements Row {
43 private final List<Mutation> mutations = new ArrayList<Mutation>();
44 private byte [] row;
45
46
47 public RowMutations() {}
48
49
50
51
52
53 public RowMutations(byte [] row) {
54 Mutation.checkRow(row);
55 this.row = Bytes.copy(row);
56 }
57
58
59
60
61
62
63 public void add(Put p) throws IOException {
64 internalAdd(p);
65 }
66
67
68
69
70
71
72 public void add(Delete d) throws IOException {
73 internalAdd(d);
74 }
75
76 private void internalAdd(Mutation m) throws IOException {
77 int res = Bytes.compareTo(this.row, m.getRow());
78 if (res != 0) {
79 throw new WrongRowIOException("The row in the recently added Put/Delete <" +
80 Bytes.toStringBinary(m.getRow()) + "> doesn't match the original one <" +
81 Bytes.toStringBinary(this.row) + ">");
82 }
83 mutations.add(m);
84 }
85
86 @Override
87 public int compareTo(Row i) {
88 return Bytes.compareTo(this.getRow(), i.getRow());
89 }
90
91 @Override
92 public boolean equals(Object obj) {
93 if (obj == this) return true;
94 if (obj instanceof RowMutations) {
95 RowMutations other = (RowMutations)obj;
96 return compareTo(other) == 0;
97 }
98 return false;
99 }
100
101 @Override
102 public int hashCode(){
103 return Arrays.hashCode(row);
104 }
105
106 @Override
107 public byte[] getRow() {
108 return row;
109 }
110
111
112
113
114 public List<Mutation> getMutations() {
115 return Collections.unmodifiableList(mutations);
116 }
117 }