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

org.umlg.runtime.collection.persistent.UmlgOrderedSetImpl Maven / Gradle / Ivy

There is a newer version: 2.0.15
Show newest version
package org.umlg.runtime.collection.persistent;

import org.umlg.runtime.collection.UmlgOrderedSet;
import org.umlg.runtime.collection.UmlgRuntimeProperty;
import org.umlg.runtime.domain.UmlgNode;

import java.util.Collection;

public class UmlgOrderedSetImpl extends UmlgBaseOrderedSet implements UmlgOrderedSet {


    @SuppressWarnings("unchecked")
    public UmlgOrderedSetImpl(UmlgNode owner, UmlgRuntimeProperty runtimeProperty) {
        super(owner, runtimeProperty);
    }

    @Override
    public boolean addAll(int index, Collection c) {
        maybeLoad();
        int indexOf = index;
        for (E e : c) {
            this.add(indexOf++, e);
        }
        return true;
    }

    @Override
    public void add(int indexOf, E e) {
        maybeLoad();
        if (indexOf == getInternalList().size()) {
            add(e);
        } else if (indexOf > getInternalList().size()) {
            throw new IndexOutOfBoundsException("Index: " + indexOf + ", Size: " + getInternalList().size());
        } else if (!this.getInternalListOrderedSet().contains(e)) {
            if (isEmbedded()) {
                //The BaseCollection.addInternal expects the element to have been loaded already
                if (this.loaded) {
                    getInternalList().add(indexOf, e);
                }
                addInternal(e);
            } else {
                this.edge = addToListAtIndex(indexOf, e);
                if (this.loaded) {
                    getInternalList().add(indexOf, e);
                }
                if (isInverseOrdered()) {
                    this.addToInverseLinkedList(this.edge);
                }
            }
        }
    }

    @Override
    public E set(int index, E element) {
        E removedElement = this.remove(index);
        this.add(index, element);
        return removedElement;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy