001/** 002 * Copyright (C) 2006-2025 Talend Inc. - www.talend.com 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.talend.sdk.component.runtime.record; 017 018import static java.util.Collections.emptyList; 019import static java.util.Collections.emptyMap; 020 021import java.util.Comparator; 022import java.util.List; 023import java.util.Map; 024import java.util.stream.Stream; 025 026import javax.json.bind.annotation.JsonbTransient; 027 028import org.talend.sdk.component.api.record.Schema; 029 030public abstract class Schemas implements Schema, Schema.Builder { 031 032 public static final Schemas STRING = new Schemas() { 033 034 @Override 035 public Type getType() { 036 return Type.STRING; 037 } 038 }; 039 040 public static final Schemas BYTES = new Schemas() { 041 042 @Override 043 public Type getType() { 044 return Type.BYTES; 045 } 046 }; 047 048 public static final Schemas INT = new Schemas() { 049 050 @Override 051 public Type getType() { 052 return Type.INT; 053 } 054 }; 055 056 public static final Schemas LONG = new Schemas() { 057 058 @Override 059 public Type getType() { 060 return Type.LONG; 061 } 062 }; 063 064 public static final Schemas FLOAT = new Schemas() { 065 066 @Override 067 public Type getType() { 068 return Type.FLOAT; 069 } 070 }; 071 072 public static final Schemas DOUBLE = new Schemas() { 073 074 @Override 075 public Type getType() { 076 return Type.DOUBLE; 077 } 078 }; 079 080 public static final Schemas BOOLEAN = new Schemas() { 081 082 @Override 083 public Type getType() { 084 return Type.BOOLEAN; 085 } 086 }; 087 088 public static final Schemas DATETIME = new Schemas() { 089 090 @Override 091 public Type getType() { 092 return Type.DATETIME; 093 } 094 }; 095 096 public static final Schemas DECIMAL = new Schemas() { 097 098 @Override 099 public Type getType() { 100 return Type.DECIMAL; 101 } 102 }; 103 104 public static final Schemas EMPTY_RECORD = new Schemas() { 105 106 @Override 107 public Type getType() { 108 return Type.RECORD; 109 } 110 }; 111 112 public static Builder valueOf(final String name) { 113 switch (name) { 114 case "STRING": 115 return STRING; 116 case "BYTES": 117 return BYTES; 118 case "INT": 119 return INT; 120 case "LONG": 121 return LONG; 122 case "FLOAT": 123 return FLOAT; 124 case "DOUBLE": 125 return DOUBLE; 126 case "BOOLEAN": 127 return BOOLEAN; 128 case "DATETIME": 129 return DATETIME; 130 case "DECIMAL": 131 return DECIMAL; 132 case "EMPTY_RECORD": 133 return EMPTY_RECORD; 134 default: 135 throw new IllegalArgumentException(name); 136 } 137 } 138 139 @Override 140 public Schema build() { 141 return this; 142 } 143 144 @Override 145 public Builder withElementSchema(final Schema schema) { 146 throw new UnsupportedOperationException("Not allowed for a primitive"); 147 } 148 149 @Override 150 public Builder withType(final Type type) { 151 throw new UnsupportedOperationException("Not allowed for a primitive"); 152 } 153 154 @Override 155 public Builder withEntry(final Entry entry) { 156 throw new UnsupportedOperationException("Not allowed for a primitive"); 157 } 158 159 @Override 160 public Schema getElementSchema() { 161 return null; 162 } 163 164 @Override 165 public List<Entry> getEntries() { 166 return emptyList(); 167 } 168 169 @Override 170 public List<Entry> getMetadata() { 171 return emptyList(); 172 } 173 174 @Override 175 @JsonbTransient 176 public Stream<Entry> getAllEntries() { 177 return Stream.empty(); 178 } 179 180 @Override 181 @JsonbTransient 182 public List<Entry> getEntriesOrdered() { 183 throw new UnsupportedOperationException("#getEntriesOrdered()"); 184 } 185 186 @Override 187 @JsonbTransient 188 public Builder moveBefore(final String before, final String name) { 189 throw new UnsupportedOperationException("#moveBefore()"); 190 } 191 192 @Override 193 public Builder moveAfter(final String after, final String name) { 194 throw new UnsupportedOperationException("#moveAfter()"); 195 } 196 197 @Override 198 public Builder swap(final String name, final String with) { 199 throw new UnsupportedOperationException("#swap()"); 200 } 201 202 @Override 203 public Builder withProps(final Map<String, String> props) { 204 throw new UnsupportedOperationException("#withProps()"); 205 } 206 207 @Override 208 public Builder withProp(final String key, final String value) { 209 throw new UnsupportedOperationException("#withProp()"); 210 } 211 212 @Override 213 public Map<String, String> getProps() { 214 return emptyMap(); 215 } 216 217 @Override 218 public Builder toBuilder() { 219 return null; 220 } 221 222 @Override 223 public String getProp(final String property) { 224 throw new UnsupportedOperationException("#getProp()"); 225 } 226 227 @Override 228 public Type getType() { 229 return null; 230 } 231 232 @Override 233 public Builder withEntryAfter(final String before, final Entry entry) { 234 throw new UnsupportedOperationException("#withEntryAfter()"); 235 } 236 237 @Override 238 public Builder withEntryBefore(final String after, final Entry entry) { 239 throw new UnsupportedOperationException("#withEntryBefore()"); 240 } 241 242 @Override 243 public Builder remove(final String name) { 244 throw new UnsupportedOperationException("#remove()"); 245 } 246 247 @Override 248 public Builder remove(final Entry entry) { 249 throw new UnsupportedOperationException("#remove()"); 250 } 251 252 @Override 253 public List<Entry> getEntriesOrdered(final Comparator<Entry> comparator) { 254 throw new UnsupportedOperationException("#getEntriesOrdered()"); 255 } 256 257 @Override 258 public EntriesOrder naturalOrder() { 259 throw new UnsupportedOperationException("#naturalOrder()"); 260 } 261}