1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.types;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.classification.InterfaceStability;
22 import org.apache.hadoop.hbase.util.Order;
23 import org.apache.hadoop.hbase.util.PositionedByteRange;
24
25 /**
26 * The {@code Union} family of {@link DataType}s encode one of a fixed
27 * collection of Objects. They provide convenience methods which handle type
28 * casting on your behalf.
29 */
30 @SuppressWarnings("unchecked")
31 @InterfaceAudience.Public
32 @InterfaceStability.Evolving
33 public abstract class Union4<A, B, C, D> extends Union3<A, B, C> {
34
35 protected final DataType<D> typeD;
36
37 /**
38 * Create an instance of {@code Union4} over the set of specified
39 * types.
40 */
41 public Union4(DataType<A> typeA, DataType<B> typeB, DataType<C> typeC, DataType<D> typeD) {
42 super(typeA, typeB, typeC);
43 this.typeD = typeD;
44 }
45
46 @Override
47 public boolean isOrderPreserving() {
48 return super.isOrderPreserving() && typeD.isOrderPreserving();
49 }
50
51 @Override
52 public Order getOrder() { return null; }
53
54 @Override
55 public boolean isNullable() {
56 return super.isNullable() && typeD.isNullable();
57 }
58
59 @Override
60 public boolean isSkippable() {
61 return super.isSkippable() && typeD.isSkippable();
62 }
63
64 /**
65 * Read an instance of the fourth type parameter from buffer {@code src}.
66 */
67 public D decodeD(PositionedByteRange src) {
68 return (D) decode(src);
69 }
70 }