ingo@807: package de.intevation.flys.client.shared.model;
ingo@807:
sascha@845:
sascha@845: import java.util.List;
sascha@845: import java.util.Map;
sascha@845: import java.util.HashMap;
sascha@845:
ingo@807: import java.io.Serializable;
ingo@807:
ingo@807: /**
felix@1442: * Information bundle to let client create/clone an artifact with facets.
ingo@807: * @author Ingo Weinzierl
ingo@807: */
sascha@839: public class Recommendation implements Serializable {
ingo@807:
felix@1271: /** Index and name of a facet. */
sascha@845: public static class Facet implements Serializable {
sascha@845:
felix@1442: /** Facet name. */
sascha@845: protected String name;
felix@1543:
felix@1543: /** Facet index. */
sascha@845: protected String index;
sascha@845:
sascha@845: public Facet() {
sascha@845: }
sascha@845:
sascha@845: public Facet(String name, String index) {
sascha@845: this.name = name;
sascha@845: this.index = index;
sascha@845: }
sascha@845:
sascha@845: public String getName() {
sascha@845: return name;
sascha@845: }
sascha@845:
sascha@845: public String getIndex() {
sascha@845: return index;
sascha@845: }
felix@1271:
felix@1271:
felix@1271: @Override
felix@1271: public int hashCode() {
felix@1271: int hash = 0;
felix@1271: if (getName() != null) {
felix@1271: hash += getName().hashCode();
felix@1271: }
felix@1271: if (getIndex() != null) {
felix@1271: hash += getIndex().hashCode();
felix@1271: }
felix@1271: return hash;
felix@1271: }
felix@1271:
felix@1271:
felix@1271: @Override
felix@1271: public boolean equals(Object other) {
felix@1271: if (!(other instanceof Facet) || other == null) {
felix@1271: return false;
felix@1271: }
felix@1271: Facet facet = (Facet) other;
felix@1271: return (same(facet.getIndex(), this.getIndex()))
felix@1271: && (same(facet.getName(), this.getName()));
felix@1271: }
sascha@845: } // class Facet
sascha@845:
felix@1271:
felix@1271: /** Mapping of outnames to Facet-Lists. */
sascha@845: public static class Filter implements Serializable {
sascha@845:
sascha@845: protected Map> outs;
sascha@845:
sascha@845: public Filter() {
sascha@845: outs = new HashMap>();
sascha@845: }
sascha@845:
sascha@845: public void add(String out, List facets) {
sascha@845: outs.put(out, facets);
sascha@845: }
sascha@845:
sascha@845: public Map> getOuts() {
sascha@845: return outs;
sascha@845: }
felix@1271:
felix@1271:
felix@1271: @Override
felix@1271: public int hashCode() {
felix@1271: if (getOuts() != null) {
felix@1271: return getOuts().hashCode();
felix@1271: }
felix@1271: return 0;
felix@1271: }
felix@1271:
felix@1271:
felix@1271: @Override
felix@1271: public boolean equals(Object other) {
felix@1271: if (!(other instanceof Filter) || other == null) {
felix@1271: return false;
felix@1271: }
felix@1271: Filter filter = (Filter) other;
felix@1271: return Recommendation.same(filter.getOuts(), this.getOuts());
felix@1271: }
sascha@845: } // class Filter
sascha@845:
felix@1442: /** Factory to speak to when creating/cloning. */
sascha@839: protected String factory;
felix@1442: /** Sometimes database ids, sometimes other freeform text. */
sascha@839: protected String ids;
felix@1543: /** Artifacts uuid that should serve as master artifact. */
sascha@844: protected String masterArtifact;
felix@1442: /** Optional facet filter. */
sascha@845: protected Filter filter;
felix@1352: protected String displayName = null;
sascha@839:
sascha@839: public Recommendation() {
sascha@839: }
sascha@839:
sascha@839: public Recommendation(String factory, String ids) {
sascha@845: this(factory, ids, null, null);
sascha@839: }
sascha@839:
sascha@845: public Recommendation(
sascha@845: String factory,
sascha@845: String ids,
sascha@845: String masterArtifact,
sascha@845: Filter filter
sascha@845: ) {
sascha@845: this.factory = factory;
sascha@845: this.ids = ids;
sascha@845: this.masterArtifact = masterArtifact;
sascha@845: this.filter = filter;
sascha@845: }
sascha@839:
sascha@839: public String getFactory() {
sascha@839: return factory;
sascha@839: }
sascha@839:
felix@1349: public void setFactory(String factory) {
felix@1349: this.factory = factory;
felix@1349: }
felix@1349:
felix@1352: public void setDisplayName(String displayName) {
felix@1352: this.displayName = displayName;
felix@1352: }
felix@1352:
felix@1352: public String getDisplayName() {
felix@1352: return this.displayName;
felix@1352: }
felix@1352:
sascha@839: public String getIDs() {
sascha@839: return ids;
sascha@839: }
sascha@844:
sascha@844: public String getMasterArtifact() {
sascha@844: return masterArtifact;
sascha@844: }
sascha@844:
sascha@844: public void setMasterArtifact(String masterArtifact) {
sascha@844: this.masterArtifact = masterArtifact;
sascha@844: }
sascha@845:
sascha@845: public Filter getFilter() {
sascha@845: return filter;
sascha@845: }
sascha@845:
sascha@845: public void setFilter(Filter filter) {
sascha@845: this.filter = filter;
sascha@845: }
felix@1271:
felix@1271:
felix@1271: @Override
felix@1271: public int hashCode() {
felix@1271: int hash = 0;
felix@1271: hash += (getFactory() != null)
felix@1271: ? getFactory().hashCode()
felix@1271: : 0;
felix@1271: hash += (getIDs() != null)
felix@1271: ? getIDs().hashCode()
felix@1271: : 0;
felix@1271: hash += (getFilter() != null)
felix@1271: ? getFilter().hashCode()
felix@1271: : 0;
felix@1271: hash += (getMasterArtifact() != null)
felix@1271: ? getMasterArtifact().hashCode()
felix@1271: : 0;
felix@1271: return hash;
felix@1271: }
felix@1271:
felix@1271:
felix@1271: /**
felix@1271: * Null-pointer guarded equals.
felix@1271: * Two null's are assumed equal (returns true);
felix@1271: * @param a Object to compare against parameter b.
felix@1271: * @param b Object to compare against parameter a.
felix@1271: * @return true if either a and b are null or a.equals(b) returns true.
felix@1271: */
felix@1271: protected static boolean same(Object a, Object b) {
felix@1271: // Do null-check.
felix@1271: if (a == null) {
felix@1271: return b == null;
felix@1271: } else if (b == null) {
felix@1271: return false;
felix@1271: }
felix@1271: return a.equals(b);
felix@1271: }
felix@1271:
felix@1271:
felix@1271: @Override
felix@1271: public boolean equals(Object other) {
felix@1271: if (!(other instanceof Recommendation) || other == null) {
felix@1271: return false;
felix@1271: }
felix@1271: Recommendation rec = (Recommendation) other;
felix@1271: return (same(this.getFactory(), rec.getFactory()))
felix@1271: && (same(this.getIDs(), rec.getIDs()))
felix@1271: && (same(this.getFilter(), rec.getFilter()))
felix@1271: && (same(this.getMasterArtifact(), rec.getMasterArtifact()));
felix@1271: }
ingo@807: }
ingo@807: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :