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

com.epam.deltix.qsrv.hf.pub.md.SimpleClassSet Maven / Gradle / Ivy

There is a newer version: 6.1.25
Show newest version
/*
 * Copyright 2021 EPAM Systems, Inc
 *
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership. 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.epam.deltix.qsrv.hf.pub.md;

import com.epam.deltix.qsrv.hf.pub.md.RecordClassDescriptor;
import com.epam.deltix.qsrv.hf.pub.md.ClassDescriptor;
import com.epam.deltix.util.collections.Visitor;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
import java.io.Serializable;
import java.util.*;

@XmlRootElement(name = "ClassSet")
public class SimpleClassSet implements com.epam.deltix.qsrv.hf.pub.md.ClassSet, Serializable {

    @XmlElement(name = "classDescriptor")
    private HashSet classDescriptors;

    @XmlElement (name = "contentClass")
    private List contentClasses; // define class descriptors order

    public SimpleClassSet() {
    }

    public SimpleClassSet(RecordClassDescriptor[] classes) {
        defineClasses(classes);
    }

    public void                         addContentClasses(RecordClassDescriptor... cds) {
        defineClasses(cds);
    }

    @Override
    public ClassDescriptor[]            getClasses() {
        return classDescriptors.toArray(new ClassDescriptor[classDescriptors.size()]);
    }

    public RecordClassDescriptor[] getContentClasses() {

        if (contentClasses == null)
            return null;

        List  result = new ArrayList(contentClasses.size());

        for (String guid : contentClasses) {
            for (ClassDescriptor descriptor : classDescriptors) {
                if (descriptor instanceof RecordClassDescriptor && guid.equals(descriptor.getGuid()))
                    result.add((RecordClassDescriptor) descriptor);
            }
        }

        return result.toArray(new RecordClassDescriptor[result.size()]);
    }

    private void                 defineClasses (RecordClassDescriptor[] cds) {

        if (contentClasses == null)
            contentClasses = new ArrayList  ();

        for (RecordClassDescriptor cd : cds) {
            if (!contentClasses.contains(cd.getGuid()))
                contentClasses.add (cd.getGuid());
        }

        final Queue addQueue = new ArrayDeque();

        for (ClassDescriptor cd : cds)
            addQueue.offer (cd);

        final Visitor adder =
            new Visitor  () {
                @Override
                public boolean                      visit (ClassDescriptor cd) {
                    addQueue.offer (cd);
                    return (true);
                }
            };

        for (;;) {
            ClassDescriptor             cd = addQueue.poll ();

            if (cd == null)
                break;

            if (classDescriptors == null)
                classDescriptors = new HashSet();

            if (!classDescriptors.add (cd))
                continue;

            cd.visitDependencies (adder);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy