Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.io.flat;
import br.com.objectos.core.testing.Testable;
import br.com.objectos.core.testing.Testables;
import br.com.objectos.io.flat.annotation.IntegerOption;
import br.com.objectos.io.flat.annotation.LocalDatePattern;
/**
* @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);
}
@Override
public boolean isEqual(Column o) {
return Testables.isEqualHelper()
.equal(index, o.index)
.equal(length, o.length)
.result();
}
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;
}
}