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

com.gs.fw.common.mithra.util.MithraArrayTupleTupleSet Maven / Gradle / Ivy

There is a newer version: 18.1.0
Show newest version
/*
 Copyright 2016 Goldman Sachs.
 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 com.gs.fw.common.mithra.util;

import com.gs.fw.common.mithra.MithraBusinessException;
import com.gs.fw.common.mithra.cache.ConcurrentFullUniqueIndex;
import com.gs.fw.common.mithra.extractor.Extractor;
import com.gs.fw.common.mithra.extractor.IntExtractor;
import com.gs.fw.common.mithra.extractor.StringExtractor;
import com.gs.fw.common.mithra.tempobject.ArrayTuple;
import com.gs.fw.common.mithra.tempobject.IntIntTuple;
import com.gs.fw.common.mithra.tempobject.Tuple;
import com.gs.fw.common.mithra.tempobject.tupleextractor.*;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Iterator;
import java.util.List;


public class MithraArrayTupleTupleSet implements MithraTupleSet, Externalizable
{
    private static final long serialVersionUID = 826563429092366120L;

    private ConcurrentFullUniqueIndex fullUniqueIndex;
    private Extractor[] extractors;
    private transient int[] maxLengths;
    private transient List dataHoldersForWriteReplacement;
    private boolean readOnly = false;
    private int hashCode;
    private boolean hasNulls;

    public MithraArrayTupleTupleSet()
    {
    }

    public MithraArrayTupleTupleSet(Extractor[] dataExtractors, List dataHolders)
    {
        populateNotIgnoringNulls(dataExtractors, dataHolders);
    }

    public void addAll(Extractor[] dataExtractors, List dataHolders)
    {
        for(Object dataHolder : dataHolders)
        {
            Object[] values = getExtractedValues(dataExtractors, dataHolder);
            add(values);
        }
    }

    @Override
    public int[] getMaxLengths()
    {
        if (maxLengths == null)
        {
            for(int i=0;i max[0])
                {
                    max[0] = s.length();
                }
                return false;
            }
        });
        maxLengths[index] = max[0];
    }

    private Object[] getExtractedValues(Extractor[] dataExtractors, Object dataHolder)
    {
        Object[] values = new Object[dataExtractors.length];
        for(int i=0; i< dataExtractors.length;i++)
        {
            values[i] = dataExtractors[i].valueOf(dataHolder);
        }
        return values;
    }

    @Override
    public boolean hasNulls()
    {
        return hasNulls;
    }

    private void populateNotIgnoringNulls(Extractor[] dataExtractors, List dataHolders)
    {
        if (dataHolders.size() > 0)
        {
            Object data = dataHolders.get(0);
            Object[] values = getExtractedValues(dataExtractors, data);
            populateFromPrototypeValues(dataExtractors, dataHolders, values, 1, false);
        }
    }

    private void populateFromPrototypeValues(Extractor[] dataExtractors, List dataHolders, Object[] values, int startIndex, boolean ignoreNulls)
    {
        hasNulls = !ignoreNulls;
        determineExtractors(values);
        this.fullUniqueIndex = new ConcurrentFullUniqueIndex(this.extractors);
        if (values.length == 2 && values[0] instanceof Integer && values[1] instanceof Integer)
        {
            this.fullUniqueIndex.putIfAbsent(new IntIntTuple((Integer) values[0], (Integer) values[1]));
            IntExtractor firstExtractor = (IntExtractor) dataExtractors[0];
            IntExtractor secondExtractor = (IntExtractor) dataExtractors[1];
            for(int i=startIndex;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy