X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Floop%2Fcomponents%2Fexternal%2FExternalComponentState.java;h=a220ee1d44f94e11e7dce56dfe96eff29e1ce1be;hb=3142c70fb7530c444c891674fe55c6a9b236dfb3;hp=6a723c24ed569ec9fab27086db628e860183f8c5;hpb=5e2b077e496ca28e9f91fc12cecb872228c81816;p=clamp.git diff --git a/src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java b/src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java index 6a723c24..a220ee1d 100644 --- a/src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java +++ b/src/main/java/org/onap/clamp/loop/components/external/ExternalComponentState.java @@ -29,18 +29,26 @@ import com.google.gson.annotations.Expose; * This is a transient state reflecting the deployment status of a component. It * can be Policy, DCAE, or whatever... This is object is generic. Clamp is now * stateless, so it triggers the different components at runtime, the status per - * component is stored here. + * component is stored here. The state level is used to re-compute the global + * state when multiple sub states are required for that computation (generally + * provided sequentially to the method computeState from the camel routes. * */ -public class ExternalComponentState { +public class ExternalComponentState implements Comparable { @Expose private String stateName; @Expose private String description; + private int stateLevel; - public ExternalComponentState(String stateName, String description) { + public ExternalComponentState(String stateName, String description, int level) { this.stateName = stateName; this.description = description; + this.stateLevel = level; + } + + public ExternalComponentState(String stateName, String description) { + this(stateName, description, 0); } public ExternalComponentState() { @@ -58,4 +66,50 @@ public class ExternalComponentState { public String toString() { return stateName; } + + public int getLevel() { + return stateLevel; + } + + public void setLevel(int priority) { + this.stateLevel = priority; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((stateName == null) ? 0 : stateName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ExternalComponentState other = (ExternalComponentState) obj; + if (stateName == null) { + if (other.stateName != null) + return false; + } else if (!stateName.equals(other.stateName)) + return false; + return true; + } + + /** + * This method compares this object by using the level of them. + * + * @param stateToCompare The state to compare to the current object + * @return If the one given in input has a higher level than the current object + * it returns -1, 1 otherwise and 0 if equals. + */ + @Override + public int compareTo(ExternalComponentState stateToCompare) { + return Integer.compare(this.getLevel(), stateToCompare.getLevel()); + } + }