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