All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.rosetta.jptelections.model.SomeElectionWrapper Maven / Gradle / Ivy
package com.rosetta.jptelections.model;
import com.google.common.collect.ImmutableList;
import com.rosetta.jptelections.model.Election;
import com.rosetta.jptelections.model.SomeElectionWrapper;
import com.rosetta.jptelections.model.SomeElectionWrapper.SomeElectionWrapperBuilder;
import com.rosetta.jptelections.model.SomeElectionWrapper.SomeElectionWrapperBuilderImpl;
import com.rosetta.jptelections.model.SomeElectionWrapper.SomeElectionWrapperImpl;
import com.rosetta.jptelections.model.meta.SomeElectionWrapperMeta;
import com.rosetta.model.lib.RosettaModelObject;
import com.rosetta.model.lib.RosettaModelObjectBuilder;
import com.rosetta.model.lib.annotations.RosettaAttribute;
import com.rosetta.model.lib.annotations.RosettaDataType;
import com.rosetta.model.lib.meta.RosettaMetaData;
import com.rosetta.model.lib.path.RosettaPath;
import com.rosetta.model.lib.process.BuilderMerger;
import com.rosetta.model.lib.process.BuilderProcessor;
import com.rosetta.model.lib.process.Processor;
import com.rosetta.util.ListEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static java.util.Optional.ofNullable;
/**
* @version test
*/
@RosettaDataType(value="SomeElectionWrapper", builder=SomeElectionWrapper.SomeElectionWrapperBuilderImpl.class, version="test")
public interface SomeElectionWrapper extends RosettaModelObject {
SomeElectionWrapperMeta metaData = new SomeElectionWrapperMeta();
/*********************** Getter Methods ***********************/
String getName();
List extends Election> getConcreteElection();
/*********************** Build Methods ***********************/
SomeElectionWrapper build();
SomeElectionWrapper.SomeElectionWrapperBuilder toBuilder();
static SomeElectionWrapper.SomeElectionWrapperBuilder builder() {
return new SomeElectionWrapper.SomeElectionWrapperBuilderImpl();
}
/*********************** Utility Methods ***********************/
@Override
default RosettaMetaData extends SomeElectionWrapper> metaData() {
return metaData;
}
@Override
default Class extends SomeElectionWrapper> getType() {
return SomeElectionWrapper.class;
}
@Override
default void process(RosettaPath path, Processor processor) {
processor.processBasic(path.newSubPath("name"), String.class, getName(), this);
processRosetta(path.newSubPath("concreteElection"), processor, Election.class, getConcreteElection());
}
/*********************** Builder Interface ***********************/
interface SomeElectionWrapperBuilder extends SomeElectionWrapper, RosettaModelObjectBuilder {
Election.ElectionBuilder getOrCreateConcreteElection(int _index);
List extends Election.ElectionBuilder> getConcreteElection();
SomeElectionWrapper.SomeElectionWrapperBuilder setName(String name);
SomeElectionWrapper.SomeElectionWrapperBuilder addConcreteElection(Election concreteElection0);
SomeElectionWrapper.SomeElectionWrapperBuilder addConcreteElection(Election concreteElection1, int _idx);
SomeElectionWrapper.SomeElectionWrapperBuilder addConcreteElection(List extends Election> concreteElection2);
SomeElectionWrapper.SomeElectionWrapperBuilder setConcreteElection(List extends Election> concreteElection3);
@Override
default void process(RosettaPath path, BuilderProcessor processor) {
processor.processBasic(path.newSubPath("name"), String.class, getName(), this);
processRosetta(path.newSubPath("concreteElection"), processor, Election.ElectionBuilder.class, getConcreteElection());
}
SomeElectionWrapper.SomeElectionWrapperBuilder prune();
}
/*********************** Immutable Implementation of SomeElectionWrapper ***********************/
class SomeElectionWrapperImpl implements SomeElectionWrapper {
private final String name;
private final List extends Election> concreteElection;
protected SomeElectionWrapperImpl(SomeElectionWrapper.SomeElectionWrapperBuilder builder) {
this.name = builder.getName();
this.concreteElection = ofNullable(builder.getConcreteElection()).filter(_l->!_l.isEmpty()).map(list -> list.stream().filter(Objects::nonNull).map(f->f.build()).filter(Objects::nonNull).collect(ImmutableList.toImmutableList())).orElse(null);
}
@Override
@RosettaAttribute("name")
public String getName() {
return name;
}
@Override
@RosettaAttribute("concreteElection")
public List extends Election> getConcreteElection() {
return concreteElection;
}
@Override
public SomeElectionWrapper build() {
return this;
}
@Override
public SomeElectionWrapper.SomeElectionWrapperBuilder toBuilder() {
SomeElectionWrapper.SomeElectionWrapperBuilder builder = builder();
setBuilderFields(builder);
return builder;
}
protected void setBuilderFields(SomeElectionWrapper.SomeElectionWrapperBuilder builder) {
ofNullable(getName()).ifPresent(builder::setName);
ofNullable(getConcreteElection()).ifPresent(builder::setConcreteElection);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
SomeElectionWrapper _that = getType().cast(o);
if (!Objects.equals(name, _that.getName())) return false;
if (!ListEquals.listEquals(concreteElection, _that.getConcreteElection())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (name != null ? name.hashCode() : 0);
_result = 31 * _result + (concreteElection != null ? concreteElection.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "SomeElectionWrapper {" +
"name=" + this.name + ", " +
"concreteElection=" + this.concreteElection +
'}';
}
}
/*********************** Builder Implementation of SomeElectionWrapper ***********************/
class SomeElectionWrapperBuilderImpl implements SomeElectionWrapper.SomeElectionWrapperBuilder {
protected String name;
protected List concreteElection = new ArrayList<>();
public SomeElectionWrapperBuilderImpl() {
}
@Override
@RosettaAttribute("name")
public String getName() {
return name;
}
@Override
@RosettaAttribute("concreteElection")
public List extends Election.ElectionBuilder> getConcreteElection() {
return concreteElection;
}
public Election.ElectionBuilder getOrCreateConcreteElection(int _index) {
if (concreteElection==null) {
this.concreteElection = new ArrayList<>();
}
Election.ElectionBuilder result;
return getIndex(concreteElection, _index, () -> {
Election.ElectionBuilder newConcreteElection = Election.builder();
return newConcreteElection;
});
}
@Override
@RosettaAttribute("name")
public SomeElectionWrapper.SomeElectionWrapperBuilder setName(String name) {
this.name = name==null?null:name;
return this;
}
@Override
public SomeElectionWrapper.SomeElectionWrapperBuilder addConcreteElection(Election concreteElection) {
if (concreteElection!=null) this.concreteElection.add(concreteElection.toBuilder());
return this;
}
@Override
public SomeElectionWrapper.SomeElectionWrapperBuilder addConcreteElection(Election concreteElection, int _idx) {
getIndex(this.concreteElection, _idx, () -> concreteElection.toBuilder());
return this;
}
@Override
public SomeElectionWrapper.SomeElectionWrapperBuilder addConcreteElection(List extends Election> concreteElections) {
if (concreteElections != null) {
for (Election toAdd : concreteElections) {
this.concreteElection.add(toAdd.toBuilder());
}
}
return this;
}
@Override
@RosettaAttribute("concreteElection")
public SomeElectionWrapper.SomeElectionWrapperBuilder setConcreteElection(List extends Election> concreteElections) {
if (concreteElections == null) {
this.concreteElection = new ArrayList<>();
}
else {
this.concreteElection = concreteElections.stream()
.map(_a->_a.toBuilder())
.collect(Collectors.toCollection(()->new ArrayList<>()));
}
return this;
}
@Override
public SomeElectionWrapper build() {
return new SomeElectionWrapper.SomeElectionWrapperImpl(this);
}
@Override
public SomeElectionWrapper.SomeElectionWrapperBuilder toBuilder() {
return this;
}
@SuppressWarnings("unchecked")
@Override
public SomeElectionWrapper.SomeElectionWrapperBuilder prune() {
concreteElection = concreteElection.stream().filter(b->b!=null).map(b->b.prune()).filter(b->b.hasData()).collect(Collectors.toList());
return this;
}
@Override
public boolean hasData() {
if (getName()!=null) return true;
if (getConcreteElection()!=null && getConcreteElection().stream().filter(Objects::nonNull).anyMatch(a->a.hasData())) return true;
return false;
}
@SuppressWarnings("unchecked")
@Override
public SomeElectionWrapper.SomeElectionWrapperBuilder merge(RosettaModelObjectBuilder other, BuilderMerger merger) {
SomeElectionWrapper.SomeElectionWrapperBuilder o = (SomeElectionWrapper.SomeElectionWrapperBuilder) other;
merger.mergeRosetta(getConcreteElection(), o.getConcreteElection(), this::getOrCreateConcreteElection);
merger.mergeBasic(getName(), o.getName(), this::setName);
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof RosettaModelObject) || !getType().equals(((RosettaModelObject)o).getType())) return false;
SomeElectionWrapper _that = getType().cast(o);
if (!Objects.equals(name, _that.getName())) return false;
if (!ListEquals.listEquals(concreteElection, _that.getConcreteElection())) return false;
return true;
}
@Override
public int hashCode() {
int _result = 0;
_result = 31 * _result + (name != null ? name.hashCode() : 0);
_result = 31 * _result + (concreteElection != null ? concreteElection.hashCode() : 0);
return _result;
}
@Override
public String toString() {
return "SomeElectionWrapperBuilder {" +
"name=" + this.name + ", " +
"concreteElection=" + this.concreteElection +
'}';
}
}
}