Class StringCollectionProperty

All Implemented Interfaces:
io.github.mmm.event.EventSource<ObservableEvent<String>,ObservableEventListener<? super String>>, io.github.mmm.marshall.MarshallableObject, io.github.mmm.marshall.Marshaller<Object>, io.github.mmm.marshall.Marshalling<Object>, io.github.mmm.marshall.MarshallingObject, io.github.mmm.marshall.UnmarshallableObject, io.github.mmm.marshall.Unmarshaller<Object>, AttributeReadOnly, io.github.mmm.property.comparable.ReadableComparableProperty<String>, io.github.mmm.property.comparable.WritableComparableProperty<String>, ReadableSimpleProperty<String>, WritableSimpleProperty<String>, ReadableProperty<String>, ReadableStringProperty, WritableStringProperty, WritableProperty<String>, Validatable, io.github.mmm.value.CriteriaObject<String>, ComparableExpression<String>, Expression<String>, ObservableSimpleValue<String>, ReadableSimpleValue<String>, WritableSimpleValue<String>, ObservableValue<String>, ObservableStringValue, ReadableStringValue, StringExpression, WritableStringValue, WritableObservableValue<String>, io.github.mmm.value.PropertyPath<String>, io.github.mmm.value.ReadablePath, io.github.mmm.value.ReadableTypedValue<String>, io.github.mmm.value.ReadableValue<String>, io.github.mmm.value.TypedPropertyPath<String>, io.github.mmm.value.WritableValue<String>, Cloneable, Comparable<ReadableProperty<?>>, Supplier<String>
Direct Known Subclasses:
StringListProperty, StringSetProperty

public abstract class StringCollectionProperty extends StringProperty
This is an extension of StringProperty that stores a Collection of Strings as a simple String in a CSV like format. Since it needs a separator character that shall not occur inside the contained String elements, it is only suitable for limited use-cases such as representing a set of tags or synonyms. For a generic collection of arbitrary Strings (or other elements) please consider using CollectionProperty. However, in cases where this implementation is applicable, it can be a pragmatic simplification compared to relational associations.
Please note that null elements will be silently ignored by operations such as add or remove while the empty String is not.
Since:
1.0.0
  • Constructor Details

    • StringCollectionProperty

      public StringCollectionProperty(String name)
      The constructor.
      Parameters:
      name - the name.
    • StringCollectionProperty

      public StringCollectionProperty(String name, PropertyMetadata<String> metadata)
      The constructor.
      Parameters:
      name - the name.
      metadata - the metadata.
  • Method Details

    • getCollection

      protected Collection<String> getCollection()
      Returns:
      the potential Collection to redundantly manage the elements efficiently or null if all information is only maintained in the String value. Please note that binding may cause undesired effects if backed by a Collection.
    • getSeparator

      protected String getSeparator()
      Returns:
      the separator character (e.g. "|", ";", "," - may also be something exotic like "$&%" to avoid collision with elements).
    • isEncloseWithSeparator

      protected boolean isEncloseWithSeparator()
      Determines if the elements shall be enclosed with the separator (e.g. "|one|two|three|") or not (e.g. "one|two|three"). Enclosing can be used as a pragmatic approach to store lists or sets in a database while still being able to search with SQL using contains (e.g. WHERE x.tags CONTAINS '|one|'). Also enclosing is increasing the efficiency of add and remove operations. Therefore, it is highly recommended to stick with the default (true for activated enclosing). To display the value to end-users you can use getCsv(String, boolean).
      Returns:
      true if the String value shall be enclosed with the separator, false otherwise.
    • setWithChange

      protected void setWithChange(String oldValue, String value)
      Overrides:
      setWithChange in class Property<String>
    • contains

      public boolean contains(String element)
      Parameters:
      element - the element to check.
      Returns:
      true if the given element is contained in this collection of Strings.
      See Also:
    • add

      public boolean add(String element)
      Parameters:
      element - the element to add to this collection of Strings.
      Returns:
      true if the value has changed, false otherwise (if the given element was already present and this property ensures distinct elements).
      See Also:
    • remove

      public boolean remove(String element)
      Parameters:
      element - the element to remove from this String collection.
      Returns:
      true if the given element was previously present and is now removed so the value actually has changed, false otherwise (if not present and no change).
      See Also:
    • set

      public void set(Collection<String> collection)
      Parameters:
      collection - the Collection of elements to set as separated string value.
    • getCsv

      public String getCsv(String separator, boolean enclose)
      Parameters:
      separator - the custom separator to use (e.g. ";" for CSV).
      enclose - the custom enclose with separator flag.
      Returns:
      the value as CSV with the given parameters.
    • setCsv

      public void setCsv(String csv, String separator, boolean enclose)
      Parameters:
      csv - the new value with elements separated by the given separator.
      separator - the custom separator to use (e.g. ";" for CSV).
      enclose - the custom enclose with separator flag.
    • setCsv

      public void setCsv(String csv, String separator, boolean enclose, boolean trim)
      Parameters:
      csv - the new value with elements separated by the given separator.
      separator - the custom separator to use (e.g. ";" for CSV).
      enclose - the custom enclose with separator flag.
      trim - true if the elements from the given csv should be trimmed, false otherwise.
    • collect

      protected <C extends Collection<String>> C collect(C collection)
      Type Parameters:
      C - type of the Collection.
      Parameters:
      collection - the Collection where to add the elements from this property.
      Returns:
      the given Collection.
    • readValue

      protected void readValue(io.github.mmm.marshall.StructuredReader reader)
      Description copied from class: Property
      Reads the value of this Property from the given StructuredReader and sets it.
      Overrides:
      readValue in class SimpleProperty<String>
      Parameters:
      reader - the StructuredReader to read the value from.
      See Also:
    • write

      public void write(io.github.mmm.marshall.StructuredWriter writer)
      Specified by:
      write in interface io.github.mmm.marshall.MarshallableObject
      Overrides:
      write in class SimpleProperty<String>