com.dlsc.flexgantt.model.scheduling

## Class AbstractConstraint<T,S extends IGranularity>

- java.lang.Object
- - com.dlsc.flexgantt.model.gantt.DefaultRelationship<T>
  - - com.dlsc.flexgantt.model.scheduling.AbstractConstraint<T,S>

- Type Parameters:
    `T` - the type of the timeline objects
    `S` - the time granularity
  All Implemented Interfaces:
    IRelationship<T>, IConstraint<T,S>
  Direct Known Subclasses:
    SimpleGranularityConstraint, TimeGranularityConstraint

      public abstract class AbstractConstraint<T,S extends IGranularity>
      extends DefaultRelationship<T>
      implements IConstraint<T,S>

  An abstract constraint superclass, which can be used by both built-in time granularities `SimpleGranularity` and `TimeGranularity`.
  Since:
    2.1
  Author:
    Dirk Lemmermann

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractConstraint(TimelineObjectPath<T> sourcePath, TimelineObjectPath<T> targetPath)` Constructs a new constraint.
    `protected` | `AbstractConstraint(TimelineObjectPath<T> sourcePath, TimelineObjectPath<T> targetPath, RelationshipType type)` Constructs a new constraint.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getBufferDuration()` Returns the duration of the buffer.
    `S` | `getBufferGranularity()` Returns the buffer granularity (days, hours, weeks).
    `BufferType` | `getBufferType()` Returns the buffer type (=, <=, <, >, >=).
    `ConstraintType` | `getConstraintType()` Returns the `ConstraintType` which determines if the constraint is a hard or a soft constraint.
    `protected abstract double` | `getDelta(long time1, long time2, S granularity)` Calculates the difference between the two time points for the given granularity.
    `Violation` | `getViolation(long time1, long time2)` Checks whether a violation of the constraint exists for the given two time points.
    `void` | `setBufferDuration(int bufferDuration)` Sets the duration of the buffer.
    `void` | `setBufferGranularity(S granularity)` Sets the buffer granularity (days, hours, weeks).
    `void` | `setBufferType(BufferType type)` Sets the buffer type (=, <=, <, >, >=).
    `void` | `setConstraintType(ConstraintType type)` Sets the `ConstraintType` which determines if the constraint is a hard or a soft constraint.
    `String` | `toString()`

    - ### Methods inherited from class com.dlsc.flexgantt.model.gantt.DefaultRelationship

      `getLabel, getPopupObject, getPopupTitleObject, getSourcePath, getTargetPath, getType, isDeletable, isSelectable, setDeletable, setLabel, setPopupObject, setPopupTitleObject, setSelectable, setSourcePath, setTargetPath, setType`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface com.dlsc.flexgantt.model.gantt.IRelationship

      `getLabel, getPopupObject, getPopupTitleObject, getSourcePath, getTargetPath, getType, isDeletable, isSelectable, setSourcePath, setTargetPath, setType`

- - ### Constructor Detail

    - #### AbstractConstraint

          protected AbstractConstraint(TimelineObjectPath<T> sourcePath,
                                       TimelineObjectPath<T> targetPath)

      Constructs a new constraint.
      Parameters:
        `sourcePath` - the path to the source timeline object
        `targetPath` - the path to the target timeline object
      Since:
        2.1

    - #### AbstractConstraint

          protected AbstractConstraint(TimelineObjectPath<T> sourcePath,
                                       TimelineObjectPath<T> targetPath,
                                       RelationshipType type)

      Constructs a new constraint.
      Parameters:
        `sourcePath` - the path to the source timeline object
        `targetPath` - the path to the target timeline object
        `type` - the relationship type (S-E, E-S, S-S, E-E)
      Since:
        2.1

  - ### Method Detail

    - #### getViolation

          public Violation getViolation(long time1,
                                        long time2)

      Description copied from interface: `IConstraint`
      Checks whether a violation of the constraint exists for the given two time points.
      - If the constraint is of type `RelationshipType.END_TO_START` then `time1`will be the end time of the first timeline object and `time2` will be the start time of the second timeline object.
      - If the constraint is of type `RelationshipType.END_TO_END` then `time1`will be the end time of the first timeline object and `time2` will be the end time of the second timeline object.
      - If the constraint is of type `RelationshipType.START_TO_START` then `time1`will be the start time of the first timeline object and `time2` will be the start time of the second timeline object.
      - If the constraint is of type `RelationshipType.START_TO_END` then `time1`will be the start time of the first timeline object and `time2` will be the end time of the second timeline object.
      Specified by:
        `getViolation` in interface `IConstraint<T,S extends IGranularity>`
      Returns:
        a violation message

    - #### getDelta

          protected abstract double getDelta(long time1,
                                             long time2,
                                             S granularity)

      Calculates the difference between the two time points for the given granularity. This method needs to be implemented by the subclasses based on the time granularity used by them (e.g. TimeGranularity or SimpleGranularity).
      Parameters:
        `time1` - the relevant time point of the first timeline object (might be start or end time)
        `time2` - the relevant time point of the second timeline object (might be start or end time)
        `granularity` - the time granularity (e.g. HOURS, DAYS, ...)
      Returns:
        the delta between the two given time points
      Since:
        2.1

    - #### setBufferType

          public void setBufferType(BufferType type)

      Description copied from interface: `IConstraint`
      Sets the buffer type (=, <=, <, >, >=).
      Specified by:
        `setBufferType` in interface `IConstraint<T,S extends IGranularity>`
      Parameters:
        `type` - the buffer type

    - #### getBufferType

          public BufferType getBufferType()

      Description copied from interface: `IConstraint`
      Returns the buffer type (=, <=, <, >, >=).
      Specified by:
        `getBufferType` in interface `IConstraint<T,S extends IGranularity>`
      Returns:
        the buffer type

    - #### setConstraintType

          public void setConstraintType(ConstraintType type)

      Description copied from interface: `IConstraint`
      Sets the `ConstraintType` which determines if the constraint is a hard or a soft constraint.
      Specified by:
        `setConstraintType` in interface `IConstraint<T,S extends IGranularity>`
      Parameters:
        `type` - the constraint type

    - #### getConstraintType

          public ConstraintType getConstraintType()

      Description copied from interface: `IConstraint`
      Returns the `ConstraintType` which determines if the constraint is a hard or a soft constraint.
      Specified by:
        `getConstraintType` in interface `IConstraint<T,S extends IGranularity>`
      Returns:
        the type of the constraint (hard, soft)

    - #### getBufferDuration

          public int getBufferDuration()

      Description copied from interface: `IConstraint`
      Returns the duration of the buffer.
      Specified by:
        `getBufferDuration` in interface `IConstraint<T,S extends IGranularity>`
      Returns:
        the buffer duration

    - #### setBufferDuration

          public void setBufferDuration(int bufferDuration)

      Description copied from interface: `IConstraint`
      Sets the duration of the buffer.
      Specified by:
        `setBufferDuration` in interface `IConstraint<T,S extends IGranularity>`
      Parameters:
        `bufferDuration` - the buffer duration

    - #### getBufferGranularity

          public S getBufferGranularity()

      Description copied from interface: `IConstraint`
      Returns the buffer granularity (days, hours, weeks).
      Specified by:
        `getBufferGranularity` in interface `IConstraint<T,S extends IGranularity>`
      Returns:
        the buffer granularity

    - #### setBufferGranularity

          public void setBufferGranularity(S granularity)

      Description copied from interface: `IConstraint`
      Sets the buffer granularity (days, hours, weeks).
      Specified by:
        `setBufferGranularity` in interface `IConstraint<T,S extends IGranularity>`
      Parameters:
        `granularity` - the buffer granularity

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `DefaultRelationship<T>`

Copyright © 2006–2020 Dirk Lemmermann Software & Consulting. All rights reserved.