1 package com.sri.emo.dbobj.model_tree; 2 3 /*** 4 * A pseudo enumeration type for defining status of the model tree in terms 5 * of filled out slots. 6 * 7 * @author Michael Rimov 8 * @version 1.0 9 */ 10 public final class ModelFillStatus { 11 12 /*** 13 * All slots in the model (Parts) have values. 14 */ 15 public static final ModelFillStatus COMPLETE = new ModelFillStatus("Complete"); 16 17 /*** 18 * Some slots in the model have values. 19 */ 20 public static final ModelFillStatus PARTIALLY_FILLED = new ModelFillStatus("Partially Finished"); 21 22 /*** 23 * No slots in the model have values. 24 */ 25 public static final ModelFillStatus EMPTY = new ModelFillStatus("Empty"); 26 27 /*** 28 * Status string to differentiate in a friendly way the instances of 29 * ModelStatus 30 */ 31 private final String status; 32 33 /*** 34 * Only constructor that takes a friendly string. 35 * 36 * @param modelStatus String 37 */ 38 private ModelFillStatus(String modelStatus) { 39 super(); 40 status = modelStatus; 41 } 42 43 /*** 44 * {@inheritDoc} 45 * 46 * @return String 47 */ 48 public String toString() { 49 return "Model Status: " + status; 50 } 51 52 /*** 53 * Indicates whether some other object is "equal to" this one. 54 * 55 * @param obj the reference object with which to compare. 56 * @return <code>true</code> if this object is the same as the obj 57 * argument; <code>false</code> otherwise. 58 */ 59 public boolean equals(Object obj) { 60 if (!(obj instanceof ModelFillStatus)) { 61 return false; 62 } 63 64 return status.equals(((ModelFillStatus) obj).status); 65 } 66 67 /*** 68 * Returns a hash code value for the object. 69 * 70 * @return a hash code value for this object. 71 */ 72 public int hashCode() { 73 return status.hashCode(); 74 } 75 76 77 /*** 78 * Since ModelStatus represents a completion. When intersecting the different 79 * model statuses, we gain what the resulting model status is. For example: 80 * <tt>Empty.intersect(COMPLETE) == PARTIALLY_FILLED</tt> and 81 * <tt>COMPLETE.intersect(COMPLETE) == COMPLETE</tt> 82 * 83 * @param other ModelStatus 84 * @return ModelStatus 85 */ 86 public ModelFillStatus intersect(ModelFillStatus other) { 87 if (other == COMPLETE) { 88 return (this == COMPLETE) ? COMPLETE : PARTIALLY_FILLED; 89 } else if (other == EMPTY) { 90 return (this == EMPTY) ? EMPTY : PARTIALLY_FILLED; 91 } else if (other == PARTIALLY_FILLED) { 92 return PARTIALLY_FILLED; 93 } else { 94 throw new IllegalStateException("Unknown model status: " + other.status); 95 } 96 } 97 98 }