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

Alachisoft.NCache.Common.DataReader.RowCollection Maven / Gradle / Ivy

package Alachisoft.NCache.Common.DataReader;

import com.alachisoft.ncache.serialization.core.io.InternalCompactSerializable;
import com.alachisoft.ncache.serialization.standard.io.CompactReader;
import com.alachisoft.ncache.serialization.standard.io.CompactWriter;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

//  Copyright (c) 2020 Alachisoft
//  
//  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

public class RowCollection implements InternalCompactSerializable {
    private ColumnCollection _columns;
    private Map _rows;
    private int _lastRow = -1;

    public RowCollection(ColumnCollection columns) {
        _rows = new HashMap();
        _columns = columns;
    }

    public final int getCount() {
        return _rows.size();
    }

    public final RecordRow get(int index) {
        return (RecordRow) _rows.get(index);
    }

    public final RecordRow getRow(int index) {
        return _rows.get(index) != null ? (RecordRow) _rows.get(index) : null;
    }


    public final void add(RecordRow row) {
        _rows.put(++_lastRow, row);
    }

    public final boolean contains(int rowID) {
        return _rows.get(rowID) != null;
    }

    public final boolean removeRow(int rowID) {
        boolean ret;
        ret = _rows.get(rowID) != null;
        if (ret) {
            _rows.remove(rowID);
        }
        return ret;
    }


    public final Map getRowsVector() {
        return _rows;
    }

    @Override
    public void Deserialize(CompactReader reader) throws IOException, ClassNotFoundException {
        Object tempVar = reader.ReadObject();
        _columns = tempVar instanceof ColumnCollection ? (ColumnCollection) tempVar : null;

        _rows = new HashMap();
        int rowCount = reader.ReadInt32();
        for (int i = 0; i < rowCount; i++) {
            Object tempVar2 = reader.ReadObject();
            _rows.put(reader.ReadInt32(), tempVar2 instanceof RecordRow ? (RecordRow) tempVar2 : null);
        }
    }

    @Override
    public void Serialize(CompactWriter writer) throws IOException {
        writer.WriteObject(_columns);
        writer.Write(_rows.size());
        for (Object kv : _rows.entrySet()) {
            Map.Entry entry = (Map.Entry) kv;
            writer.Write((int) entry.getKey());
            writer.WriteObject(entry.getValue());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy