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

io.legaldocml.akn.element.AbstractId Maven / Gradle / Ivy

The newest version!
package io.legaldocml.akn.element;

import com.google.common.collect.ImmutableMap;
import io.legaldocml.akn.AknObject;
import io.legaldocml.akn.attribute.Id;
import io.legaldocml.akn.type.NoWhiteSpace;
import io.legaldocml.io.AttributeGetterSetter;
import io.legaldocml.io.XmlReader;
import io.legaldocml.util.ToStringBuilder;

import static io.legaldocml.akn.AknAttributes.EID;
import static io.legaldocml.akn.AknAttributes.EVOLVING_ID;
import static io.legaldocml.akn.AknAttributes.GUID;
import static io.legaldocml.akn.AknAttributes.ID;
import static io.legaldocml.akn.AknAttributes.WID;
import static io.legaldocml.akn.element.Attributes.attributeGetterSetter4NoWhiteSpace;
import static io.legaldocml.unsafe.UnsafeHelper.getFieldOffset;

public abstract class AbstractId implements AknObject, Id {

    protected static final ImmutableMap> ATTRIBUTES;

    static {
        ATTRIBUTES = ImmutableMap.>builder()
                .put(ID, attributeGetterSetter4NoWhiteSpace(ID, getFieldOffset(AbstractId.class, "eId")))
                .put(EVOLVING_ID, attributeGetterSetter4NoWhiteSpace(EVOLVING_ID, getFieldOffset(AbstractId.class, "wId")))
                .put(EID, attributeGetterSetter4NoWhiteSpace(EID, getFieldOffset(AbstractId.class, "eId")))
                .put(WID, attributeGetterSetter4NoWhiteSpace(WID, getFieldOffset(AbstractId.class, "wId")))
                .put(GUID, attributeGetterSetter4NoWhiteSpace(GUID, getFieldOffset(AbstractId.class, "guid")))
                .build();
    }

    /**
     * Attribute "id" for v2 or "eId" for "v3".
     */
    private NoWhiteSpace eId;

    /**
     * Attribute "evolvingId" for v2 or "wid" for "v3".
     */
    private NoWhiteSpace wId;


    private NoWhiteSpace guid;

    /**
     * {@inheritDoc}
     */
    public final String getId() {
        if (this.eId == null) {
            return null;
        }
        return this.eId.toString();
    }

    /**
     * {@inheritDoc}
     */
    public final void setId(String id) {
        this.eId = NoWhiteSpace.valueOf(id);
    }

    /**
     * {@inheritDoc}
     */
    public final String getEvolvingId() {
        if (this.wId == null) {
            return null;
        }
        return this.wId.toString();
    }

    /**
     * {@inheritDoc}
     */
    public final void setEvolvingId(String evolvingId) {
        this.wId = NoWhiteSpace.valueOf(evolvingId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public NoWhiteSpace getEid() {
        return this.eId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setEid(NoWhiteSpace eId) {
        this.eId = eId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public NoWhiteSpace getWid() {
        return this.wId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setWid(NoWhiteSpace wId) {
        this.wId = wId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public NoWhiteSpace getGUID() {
        return this.guid;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setGUID(NoWhiteSpace guid) {
        this.guid = guid;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void read(XmlReader reader) {
        Attributes.read(reader, this);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ImmutableMap> attributes() {
        return ATTRIBUTES;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final String toString() {
        ToStringBuilder builder = new ToStringBuilder(this, false);
        builder.append(EID, this.eId);
        builder.append(WID, this.wId);
        toString(builder);
        return builder.toString();
    }

    protected void toString(ToStringBuilder builder) {
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy