All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jp.co.yahoo.yosegi.inmemory.YosegiArrayLoader 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.inmemory; import jp.co.yahoo.yosegi.binary.ColumnBinary; import jp.co.yahoo.yosegi.message.objects.PrimitiveObject; import jp.co.yahoo.yosegi.spread.Spread; import jp.co.yahoo.yosegi.spread.column.ArrayCell; import jp.co.yahoo.yosegi.spread.column.ArrayColumn; import jp.co.yahoo.yosegi.spread.column.ICell; import jp.co.yahoo.yosegi.spread.column.ICellManager; import jp.co.yahoo.yosegi.spread.column.IColumn; import jp.co.yahoo.yosegi.spread.column.SpreadArrayLink; import java.io.IOException; public class YosegiArrayLoader implements IArrayLoader { private class ArrayCellManager implements ICellManager { private final ICell[] cellArray; /** * Manage it as an Array cell. */ public ArrayCellManager( final ICell[] cellArray ) { this.cellArray = cellArray; } @Override public void add( final ICell cell , final int index ) { throw new UnsupportedOperationException( "read only." ); } @Override public ICell get( final int index , final ICell defaultCell ) { if ( cellArray.length <= index ) { return defaultCell; } if ( cellArray[index] == null ) { return defaultCell; } return cellArray[index]; } @Override public int size() { return cellArray.length; } @Override public void clear() {} } private ICell[] arrayCells; private final ArrayColumn arrayColumn; private final int loadSize; protected final Spread spread; /** * A loader that holds elements dictionary. */ public YosegiArrayLoader( final ColumnBinary columnBinary , final int loadSize ) { arrayColumn = new ArrayColumn( columnBinary.columnName ); spread = new Spread( arrayColumn ); arrayCells = new ICell[loadSize]; this.loadSize = loadSize; } @Override public int getLoadSize() { return loadSize; } @Override public void setNull( final int index ) throws IOException { arrayCells[index] = null; } @Override public void finish() throws IOException { spread.setRowCount( loadSize ); arrayColumn.setSpread( spread ); arrayColumn.setCellManager( new ArrayCellManager( arrayCells ) ); } @Override public IColumn build() throws IOException { return arrayColumn; } @Override public void setArrayIndex( final int index , final int start , final int length ) throws IOException { arrayCells[index] = new ArrayCell( new SpreadArrayLink( spread , index , start , start + length ) ); } @Override public void loadChild( final ColumnBinary columnBinary , final int childLoadSize ) throws IOException { YosegiLoaderFactory factory = new YosegiLoaderFactory(); IColumn child = factory.create( columnBinary , childLoadSize ); child.setParentsColumn( arrayColumn ); spread.addColumn( child ); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy