io.legaldocml.akn.element.Restrictions 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.Source;
import io.legaldocml.akn.type.AgentRef;
import io.legaldocml.akn.util.AknList;
import io.legaldocml.akn.util.XmlReaderHelper;
import io.legaldocml.io.AttributeGetterSetter;
import io.legaldocml.io.XmlReader;
import io.legaldocml.io.XmlWriter;
import io.legaldocml.io.impl.Buffers;
import java.io.IOException;
import java.util.function.Supplier;
import static io.legaldocml.akn.AknAttributes.SOURCE;
import static io.legaldocml.akn.AknElements.RESTRICTION;
import static io.legaldocml.akn.AknElements.RESTRICTIONS;
import static io.legaldocml.akn.element.Attributes.attributeGetterSetter4AgentRef;
import static io.legaldocml.akn.util.XmlWriterHelper.writeSource;
import static io.legaldocml.unsafe.UnsafeHelper.getFieldOffset;
/**
*
*
*
*
*
*
*
*
*
*
*
* @author Jacques Militello
*/
public final class Restrictions implements Source {
/**
* Memory address.
*/
private static final long ADDRESS_RESTRICTIONS = Buffers.address(RESTRICTIONS);
private static final ImmutableMap> ATTRIBUTES;
private static final ImmutableMap> ELEMS;
static {
ATTRIBUTES = ImmutableMap.>builder()
.put(SOURCE, attributeGetterSetter4AgentRef(SOURCE, getFieldOffset(Restrictions.class, "source")))
.build();
ELEMS = ImmutableMap.>builder()
.put(RESTRICTION, Restriction::new)
.build();
}
// Mandatory (min 1)
private final AknList elems = new AknList<>(new Restriction[2]);
// Mandatory
private AgentRef source;
/**
* {@inheritDoc}
*/
public AgentRef getSource() {
return this.source;
}
/**
* {@inheritDoc}
*/
public void setSource(AgentRef source) {
this.source = source;
}
/**
* {@inheritDoc}
*/
@Override
public void write(XmlWriter writer) throws IOException {
writer.writeStart(ADDRESS_RESTRICTIONS, 12);
writeSource(writer, this);
this.elems.write(writer);
writer.writeEnd(ADDRESS_RESTRICTIONS, 12);
}
/**
* {@inheritDoc}
*/
@Override
public void read(XmlReader reader) {
Attributes.read(reader, this);
XmlReaderHelper.read(reader, this.elems, ELEMS);
}
/**
* {@inheritDoc}
*/
@Override
public String name() {
return RESTRICTIONS;
}
/**
* {@inheritDoc}
*/
@Override
public ImmutableMap> attributes() {
return ATTRIBUTES;
}
}