e997349dafc6d5b31b5ee3f2ef9ed020b7d334ac
[vxquery.git] / vxquery-core / src / main / java / org / apache / vxquery / datamodel / accessors / atomic / XSDurationPointable.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.vxquery.datamodel.accessors.atomic;
18
19 import org.apache.hyracks.api.dataflow.value.ITypeTraits;
20 import org.apache.hyracks.data.std.api.AbstractPointable;
21 import org.apache.hyracks.data.std.api.IPointable;
22 import org.apache.hyracks.data.std.api.IPointableFactory;
23 import org.apache.hyracks.data.std.primitive.IntegerPointable;
24 import org.apache.hyracks.data.std.primitive.LongPointable;
25
26 public class XSDurationPointable extends AbstractPointable {
27 private final static int YEAR_MONTH_OFFSET = 0;
28 private final static int DAY_TIME_OFFSET = 4;
29
30 public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
31 private static final long serialVersionUID = 1L;
32
33 @Override
34 public boolean isFixedLength() {
35 return true;
36 }
37
38 @Override
39 public int getFixedLength() {
40 return 12;
41 }
42 };
43
44 public static final IPointableFactory FACTORY = new IPointableFactory() {
45 private static final long serialVersionUID = 1L;
46
47 @Override
48 public IPointable createPointable() {
49 return new XSDurationPointable();
50 }
51
52 @Override
53 public ITypeTraits getTypeTraits() {
54 return TYPE_TRAITS;
55 }
56 };
57
58 public static int getYearMonth(byte[] bytes, int start) {
59 return IntegerPointable.getInteger(bytes, start + YEAR_MONTH_OFFSET);
60 }
61
62 public int getYearMonth() {
63 return getYearMonth(bytes, start);
64 }
65
66 public static long getDayTime(byte[] bytes, int start) {
67 return LongPointable.getLong(bytes, start + DAY_TIME_OFFSET);
68 }
69
70 public long getDayTime() {
71 return getDayTime(bytes, start);
72 }
73
74 public static void setYearMonth(byte[] bytes, int start, int value) {
75 IntegerPointable.setInteger(bytes, start + YEAR_MONTH_OFFSET, value);
76 }
77
78 public void setYearMonth(int value) {
79 setYearMonth(bytes, start, value);
80 }
81
82 public static void setDayTime(byte[] bytes, int start, long value) {
83 LongPointable.setLong(bytes, start + DAY_TIME_OFFSET, value);
84 }
85
86 public void setDayTime(long value) {
87 setDayTime(bytes, start, value);
88 }
89 }

Copyright 2016, The Apache Software Foundation.