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 * @see Union2
30 */
31 @SuppressWarnings("unchecked")
32 @InterfaceAudience.Public
33 @InterfaceStability.Evolving
34 public abstract class Union3<A, B, C> extends Union2<A, B> {
35
36 protected final DataType<C> typeC;
37
38 /**
39 * Create an instance of {@code Union3} over the set of specified
40 * types.
41 */
42 public Union3(DataType<A> typeA, DataType<B> typeB, DataType<C> typeC) {
43 super(typeA, typeB);
44 this.typeC = typeC;
45 }
46
47 @Override
48 public boolean isOrderPreserving() {
49 return super.isOrderPreserving() && typeC.isOrderPreserving();
50 }
51
52 @Override
53 public Order getOrder() { return null; }
54
55 @Override
56 public boolean isNullable() {
57 return super.isNullable() && typeC.isNullable();
58 }
59
60 @Override
61 public boolean isSkippable() {
62 return super.isSkippable() && typeC.isSkippable();
63 }
64
65 /**
66 * Read an instance of the third type parameter from buffer {@code src}.
67 */
68 public C decodeC(PositionedByteRange src) {
69 return (C) decode(src);
70 }
71 }