jp.co.yahoo.yosegi.spread.expand.ExpandSpread Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 jp.co.yahoo.yosegi.spread.expand;
import jp.co.yahoo.yosegi.message.design.IField;
import jp.co.yahoo.yosegi.message.design.StructContainerField;
import jp.co.yahoo.yosegi.message.parser.IParser;
import jp.co.yahoo.yosegi.spread.Spread;
import jp.co.yahoo.yosegi.spread.column.ICell;
import jp.co.yahoo.yosegi.spread.column.IColumn;
import jp.co.yahoo.yosegi.spread.column.NullColumn;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
public class ExpandSpread extends Spread {
private final Map expandColumn;
private final List expandColumnList;
private final Map expandColumnIndexMap;
private int[] spreadIndexArray;
private Spread innnerSpread;
/**
* Initialize.
*/
public ExpandSpread() {
super();
expandColumn = new LinkedHashMap<>();
expandColumnList = new ArrayList<>();
expandColumnIndexMap = new HashMap<>();
}
/**
* Set the original Spread.
*/
public void setOriginalSpread( final Spread original , final int[] spreadIndexArray ) {
innnerSpread = original;
this.spreadIndexArray = spreadIndexArray;
}
/**
* Add expanded columns.
*/
public void addExpandLeafColumn( final String linkColumnName , final IColumn arrayColumn ) {
expandColumn.put( linkColumnName , arrayColumn );
expandColumnList.add( arrayColumn );
expandColumnIndexMap.put( linkColumnName , expandColumnIndexMap.size() );
}
/**
* Add expanded columns.
*/
public void addExpandColumn(
final String linkColumnName , final IColumn arrayColumn , final int[] indexArray ) {
IColumn column = new ExpandColumn( arrayColumn , indexArray );
expandColumn.put( linkColumnName , column );
expandColumnList.add( column );
expandColumnIndexMap.put( linkColumnName , expandColumnIndexMap.size() );
}
@Override
public Map getLine(final Map previous , final int index ) {
Map result = innnerSpread.getLine( previous , spreadIndexArray[index] );
for ( Map.Entry entry : expandColumn.entrySet() ) {
result.put( entry.getKey() , entry.getValue().get( index ) );
}
return result;
}
@Override
public int addRow( final String key , final Object row ) throws IOException {
throw new UnsupportedOperationException( getReadOnlyExceptionMessage() );
}
@Override
public int addRow( final Map row ) {
throw new UnsupportedOperationException( getReadOnlyExceptionMessage() );
}
@Override
public int addParserRow( final IParser parser )throws IOException {
throw new UnsupportedOperationException( getReadOnlyExceptionMessage() );
}
@Override
public int addRows( final List