]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/StructOrListWriterImpl.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / vector / src / main / java / org / apache / arrow / vector / complex / impl / StructOrListWriterImpl.java
CommitLineData
1d09f67e
TL
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
18package org.apache.arrow.vector.complex.impl;
19
20import org.apache.arrow.vector.complex.writer.BaseWriter;
21import org.apache.arrow.vector.complex.writer.BaseWriter.StructOrListWriter;
22import org.apache.arrow.vector.complex.writer.BigIntWriter;
23import org.apache.arrow.vector.complex.writer.BitWriter;
24import org.apache.arrow.vector.complex.writer.Float4Writer;
25import org.apache.arrow.vector.complex.writer.Float8Writer;
26import org.apache.arrow.vector.complex.writer.IntWriter;
27import org.apache.arrow.vector.complex.writer.VarBinaryWriter;
28import org.apache.arrow.vector.complex.writer.VarCharWriter;
29
30/**
31 * Concrete implementation of {@link StructOrListWriter}.
32 */
33public class StructOrListWriterImpl implements StructOrListWriter {
34
35 public final BaseWriter.StructWriter struct;
36 public final BaseWriter.ListWriter list;
37
38 /**
39 * Constructs a new instance using a {@link BaseWriter.StructWriter}
40 * (instead of an {@link BaseWriter.ListWriter}).
41 */
42 public StructOrListWriterImpl(final BaseWriter.StructWriter writer) {
43 this.struct = writer;
44 this.list = null;
45 }
46
47 /**
48 * Constructs a new instance using a {@link BaseWriter.ListWriter}
49 * (instead of a {@link BaseWriter.StructWriter}).
50 */
51 public StructOrListWriterImpl(final BaseWriter.ListWriter writer) {
52 this.struct = null;
53 this.list = writer;
54 }
55
56 /**
57 * Start writing to either the list or the struct.
58 */
59 public void start() {
60 if (struct != null) {
61 struct.start();
62 } else {
63 list.startList();
64 }
65 }
66
67 /**
68 * Finish writing to the list or struct.
69 */
70 public void end() {
71 if (struct != null) {
72 struct.end();
73 } else {
74 list.endList();
75 }
76 }
77
78 /**
79 * Creates a new writer for a struct with the given name.
80 */
81 public StructOrListWriter struct(final String name) {
82 assert struct != null;
83 return new StructOrListWriterImpl(struct.struct(name));
84 }
85
86 /**
87 * Creates a new writer for a list of structs.
88 *
89 * @param name Unused.
90 */
91 public StructOrListWriter listoftstruct(final String name) {
92 assert list != null;
93 return new StructOrListWriterImpl(list.struct());
94 }
95
96 public StructOrListWriter list(final String name) {
97 assert struct != null;
98 return new StructOrListWriterImpl(struct.list(name));
99 }
100
101 public boolean isStructWriter() {
102 return struct != null;
103 }
104
105 public boolean isListWriter() {
106 return list != null;
107 }
108
109 public VarCharWriter varChar(final String name) {
110 return (struct != null) ? struct.varChar(name) : list.varChar();
111 }
112
113 public IntWriter integer(final String name) {
114 return (struct != null) ? struct.integer(name) : list.integer();
115 }
116
117 public BigIntWriter bigInt(final String name) {
118 return (struct != null) ? struct.bigInt(name) : list.bigInt();
119 }
120
121 public Float4Writer float4(final String name) {
122 return (struct != null) ? struct.float4(name) : list.float4();
123 }
124
125 public Float8Writer float8(final String name) {
126 return (struct != null) ? struct.float8(name) : list.float8();
127 }
128
129 public BitWriter bit(final String name) {
130 return (struct != null) ? struct.bit(name) : list.bit();
131 }
132
133 public VarBinaryWriter binary(final String name) {
134 return (struct != null) ? struct.varBinary(name) : list.varBinary();
135 }
136
137}