br.com.objectos.flat.Column Maven / Gradle / Ivy
/*
* Copyright 2015 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.flat;
import br.com.objectos.testable.Equality;
import br.com.objectos.testable.Testable;
import br.com.objectos.testable.Tester;
/**
* @author [email protected] (Marcio Endo)
*/
abstract class Column implements Testable {
private final int index;
private final int length;
Column(int index, int length) {
this.index = index;
this.length = length;
}
public CustomColumn custom(int length, CustomFormatter> formatter) {
return CustomColumn.get(nextIndex(), length, formatter);
}
public DecimalColumn decimal(int precision, int scale) {
return DecimalColumn.get(nextIndex(), precision, scale);
}
public DecimalColumn decimal(int precision, int scale, DoubleValueCondition condition, String text) {
return DecimalColumn.get(nextIndex(), precision, scale, condition, text);
}
public FixedColumn fixed(String text) {
return FixedColumn.get(nextIndex(), text);
}
public FlatEnumColumn flatEnum(int length, FlatEnumParser> parser) {
return FlatEnumColumn.get(nextIndex(), length, parser);
}
public IntegerColumn integer(int length, IntegerOption... options) {
return IntegerColumn.get(nextIndex(), length, options);
}
public IntegerColumn integer(int length, IntValueCondition condition, String text) {
return IntegerColumn.get(nextIndex(), length, condition, text);
}
public LocalDateColumn localDate(LocalDatePattern pattern) {
return LocalDateColumn.get(nextIndex(), pattern);
}
public LocalDateColumn localDate(LocalDatePattern pattern, String whenAbsent) {
return LocalDateColumn.get(nextIndex(), pattern, whenAbsent);
}
public LocalDateTimeColumn localDateTime(LocalDateTimePattern pattern) {
return LocalDateTimeColumn.get(nextIndex(), pattern);
}
public LocalDateTimeColumn localDateTime(LocalDateTimePattern pattern, String whenAbsent) {
return LocalDateTimeColumn.get(nextIndex(), pattern, whenAbsent);
}
@Override
public Equality isEqualTo(Object that) {
return Tester.of(Column.class)
.add("index", o -> o.index)
.add("length", o -> o.length)
.test(this, that);
}
public boolean keep() {
return true;
}
public final Token parse(Line line) {
int endIndex = nextIndex();
String text = line.substring(index, endIndex);
return parse(line, text);
}
public TextColumn text(int length) {
return TextColumn.get(nextIndex(), length);
}
abstract Token parse(Line line, String text);
private int nextIndex() {
return index + length;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy