package org.splat.dal.bo.som;
+
/**
*
* @author Daniel Brunier-Coulin
- * @copyright OPEN CASCADE 2012
+ * @copyright OPEN CASCADE 2012-2014
*/
import java.io.Serializable;
import org.splat.kernel.InvalidPropertyException;
import org.splat.service.technical.ProjectSettingsService;
-
+/**
+ * Persistent simulation context type.
+ */
public class SimulationContextType extends Persistent implements Serializable {
-
-// Persistent fields
- private String name;
- private ProgressState state;
- private int step;
-// Required by the serialization
+ /**
+ * Serialization version id.
+ */
private static final long serialVersionUID = 4819425038576161242L;
-// ==============================================================================================================================
-// Constructors
-// ==============================================================================================================================
-
-// Search properties class
- public static class Properties {
-// ------------------------------
- private ProgressState state = null;
- private ProjectSettingsService.Step step = null;
-
- public ProgressState getProgressState () {
- return state;
- }
- public ProjectSettingsService.Step getStep () {
- return step;
- }
- public Properties setProgressState (final ProgressState state) {
- this.state = state;
- return this;
- }
- public Properties setStep (final ProjectSettingsService.Step step) {
- this.step = step;
- return this;
- }
- }
-// Database fetch constructor
- protected SimulationContextType () {
- }
-// Initialization constructor
- public SimulationContextType (final String name, final ProjectSettingsService.Step step) throws InvalidPropertyException {
-// ------------------------------------------------------------------------
- super();
- this.name = name;
- this.state = ProgressState.inCHECK;
- this.step = step.getNumber();
- }
-
-// ==============================================================================================================================
-// Public member functions
-// ==============================================================================================================================
-
- @Override
+ // Persistent fields
+ /**
+ * Context type name.
+ */
+ private String name;
+ /**
+ * Context progress state.
+ */
+ private ProgressState state;
+ /**
+ * Context type first applicable step.
+ */
+ private int step;
+
+ // ==============================================================================================================================
+ // Constructors
+ // ==============================================================================================================================
+
+ /**
+ * Search properties class.
+ */
+ public static class Properties {
+ private ProgressState state = null;
+ private ProjectSettingsService.Step step = null;
+
+ public ProgressState getProgressState() {
+ return state;
+ }
+
+ public ProjectSettingsService.Step getStep() {
+ return step;
+ }
+
+ public Properties setProgressState(final ProgressState state) {
+ this.state = state;
+ return this;
+ }
+
+ public Properties setStep(final ProjectSettingsService.Step step) {
+ this.step = step;
+ return this;
+ }
+ }
+
+ /**
+ * Database fetch constructor.
+ */
+ protected SimulationContextType() {
+ super();
+ }
+
+ /**
+ * Initialization constructor.
+ *
+ * @param name
+ * context type name
+ * @param step
+ * first applicable step for this type of context
+ * @throws InvalidPropertyException
+ * from constructor of parent class
+ */
+ public SimulationContextType(final String name,
+ final ProjectSettingsService.Step step)
+ throws InvalidPropertyException {
+ super();
+ this.name = name;
+ this.state = ProgressState.inCHECK;
+ this.step = step.getNumber();
+ }
+
+ // ==============================================================================================================================
+ // Public member functions
+ // ==============================================================================================================================
+
+ /**
+ * Saved context types are equal if their persistent ids are equal. <BR>
+ * Before becoming persistent context types are compared by their names.
+ *
+ * @param entity
+ * object to compare with
+ * @return true if this context type equals to the given object
+ * @see org.splat.dal.bo.kernel.Persistent#equals(java.lang.Object)
+ */
+ @Override
public boolean equals(final Object entity) {
-// ------------------------------------
- if (entity == null) {
- return false;
+
+ if (entity == null) {
+ return false;
+ }
+ if (entity instanceof String) {
+ return this.name.equals(entity); // Names are unique
+ } else if (entity instanceof SimulationContextType) {
+ SimulationContextType object = (SimulationContextType) entity;
+ long he = object.getIndex();
+ long me = this.getIndex();
+ if (me * he == 0) {
+ return this.getName().equals(object.getName());
+ } else {
+ return (he == me);
+ }
+ } else {
+ return false;
+ }
}
- if (entity instanceof String) {
- return this.name.equals(entity); // Names are unique
- } else if (entity instanceof SimulationContextType) {
- SimulationContextType object = (SimulationContextType)entity;
- long he = object.getIndex();
- long me = this.getIndex();
- if (me*he != 0) {
- return (he == me);
- } else {
- return this.getName().equals(object.getName());
- }
- } else {
- return false;
- }
- }
-
- public String getName () {
-// ------------------------
- return name;
- }
-
- public boolean isAttachedTo (final ProjectSettingsService.Step step) {
-// -------------------------------------------------------
- if (this.step == step.getNumber()) {
- return true;
+
+ /**
+ * Get context type name.
+ *
+ * @return context type name
+ */
+ public String getName() {
+ return name;
}
- return false;
- }
-
- public boolean isApproved () {
-// ----------------------------
- return (state == ProgressState.APPROVED);
- }
- /**
+
+ /**
+ * Check if contexts of this type are attached to the given study step.
+ *
+ * @param step
+ * the study step
+ * @return true if contexts of this type are attached to the given study step
+ */
+ public boolean isAttachedTo(final ProjectSettingsService.Step step) {
+ return (this.step == step.getNumber());
+ }
+
+ /**
+ * Check if the context is approved.
+ *
+ * @return true if the context is approved
+ */
+ public boolean isApproved() {
+ return (state == ProgressState.APPROVED);
+ }
+
+ /**
* Get the state.
+ *
* @return the state
*/
public ProgressState getState() {
return state;
}
+
/**
* Set the state.
- * @param state the state to set
+ *
+ * @param state
+ * the state to set
*/
public void setState(final ProgressState state) {
this.state = state;
}
+
/**
* Get the step.
+ *
* @return the step
*/
public int getStep() {
return step;
}
+
/**
* Set the step.
- * @param step the step to set
+ *
+ * @param step
+ * the step to set
*/
public void setStep(final int step) {
this.step = step;