
br.com.objectos.comuns.io.xls.XlsLine Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2011 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.comuns.io.xls;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.StreamSupport;
import br.com.objectos.collections.MoreCollectors;
import br.com.objectos.comuns.io.Column;
import br.com.objectos.comuns.io.ColumnKey;
import br.com.objectos.comuns.io.Line;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
/**
* @author [email protected] (Marcio Endo)
*/
class XlsLine implements Line {
private final Map, XlsConverter>> converterMap;
private final int number;
private final Row row;
public XlsLine(Map, XlsConverter>> converterMap, int number, Row row) {
this.converterMap = converterMap;
this.number = number;
this.row = row;
}
@Override
public int getNumber() {
return number;
}
@Override
public Column column(int col) {
Cell cell = row.getCell(col, Row.CREATE_NULL_AS_BLANK);
return new XlsColumn(converterMap, cell);
}
@Override
public String getText() {
return StreamSupport.stream(row.spliterator(), false)
.map(new CellToString())
.collect(MoreCollectors.toImmutableList())
.toString();
}
@Override
public String toString() {
return String.format("%05d: %s", number, getText());
}
private static class CellToString implements Function {
@Override
public String apply(Cell input) {
String result = null;
if (input != null) {
result = input.toString();
result = result.trim();
}
return result;
}
}
} |
© 2015 - 2025 Weber Informatics LLC | Privacy Policy