Class TextualObjects

java.lang.Object
nl.vpro.domain.TextualObjects

public class TextualObjects extends Object
Utilities related to TextualObjects
Since:
5.1
Author:
Michiel Meeuwissen
  • Method Details

    • getOptional

      public static <OT extends TypedText> Optional<String> getOptional(Collection<OT> titles, TextualType... types)
      Finds the first text in a collection of TypedTexts with one of the given types. Wrapped in an optional, so never returns null
    • get

      public static <OT extends TypedText> String get(Collection<? extends OT> titles, String defaultValue, TextualType... types)
    • expand

      public static <OT extends OwnedText> SortedSet<OT> expand(Collection<OT> texts, org.meeuw.functional.TriFunction<String,nl.vpro.domain.media.support.OwnerType,TextualType,OT> creator, List<TextualType> types, List<nl.vpro.domain.media.support.OwnerType> owners)
    • expandTitles

      public static <OT extends OwnedText> SortedSet<OT> expandTitles(Collection<OT> texts, org.meeuw.functional.TriFunction<String,nl.vpro.domain.media.support.OwnerType,TextualType,OT> creator)
      Creates a new sorted set of titles where:
      • All Textual Types from TextualType.TITLES are filled according to the business logic of POMs. This means mainly that the value for LEXICO is filled with MAIN if empty otherwise
      • For all those fields it is assured that values with owner types OwnerType.ENTRIES are added if they are not present yet, according to the business logic of POMS. This means that if there is title of a certain type, than at least it is present for owners BROADCASTER and NPO too.
    • expandTitles

      public static <T extends OwnedText> SortedSet<T> expandTitles(TextualObject<T,?,?> textualObject)
    • expandTitlesMajorOwnerTypes

      public static <T extends OwnedText> SortedSet<T> expandTitlesMajorOwnerTypes(TextualObject<T,?,?> textualObject)
    • expandTitlesAsMap

      public static <T extends OwnedText> Map<nl.vpro.domain.media.support.OwnerType,SortedSet<BasicTypedText>> expandTitlesAsMap(TextualObject<T,?,?> textualObject)
    • expandDescriptions

      public static <OT extends OwnedText> SortedSet<OT> expandDescriptions(Collection<OT> texts, org.meeuw.functional.TriFunction<String,nl.vpro.domain.media.support.OwnerType,TextualType,OT> creator)
    • expandDescriptions

      public static <D extends OwnedText> SortedSet<D> expandDescriptions(TextualObject<?,D,?> textualObject)
    • getOptional

      public static <OT extends OwnedText> Optional<String> getOptional(Collection<OT> titles, nl.vpro.domain.media.support.OwnerType owner, TextualType type)
    • get

      public static <OT extends OwnedText> Optional<String> get(Collection<OT> titles, Comparator<nl.vpro.domain.media.support.OwnerType> ownerType, TextualType... type)
    • getObject

      public static <OT extends TypedText> OT getObject(Collection<OT> titles, TextualType... types)
    • getObjects

      public static Collection<? extends OwnedText> getObjects(Collection<? extends OwnedText> titles, TextualType... types)
    • getComparator

      protected static <OT extends OwnedText> Comparator<OT> getComparator(Comparator<nl.vpro.domain.media.support.OwnerType> ownerTypeComparator)
    • getObjects

      public static <OT extends OwnedText> Collection<? extends OwnedText> getObjects(Collection<? extends OT> titles, Comparator<nl.vpro.domain.media.support.OwnerType> ownerTypeComparator, TextualType... types)
    • findOwnersForTextFields

      public static <T extends OwnedText, D extends OwnedText, TO extends TextualObject<T, D, TO>> nl.vpro.domain.media.support.OwnerType[] findOwnersForTextFields(TO media)
    • getTitle

      public static <T extends OwnedText, D extends OwnedText, TO extends TextualObject<T, D, TO>> String getTitle(@NonNull TO media, @NonNull nl.vpro.domain.media.support.OwnerType owner, @NonNull TextualType type)
    • getDescription

      public static <T extends OwnedText, D extends OwnedText, TO extends TextualObject<T, D, TO>> String getDescription(@NonNull TO media, @NonNull nl.vpro.domain.media.support.OwnerType owner, @NonNull TextualType type)
    • getDescription

      public static <T extends OwnedText, D extends OwnedText, TO extends TextualObject<T, D, TO>> String getDescription(@NonNull TO media, @NonNull TextualType... types)
    • forOwner

      public static <T extends OwnedText, D extends OwnedText, TO extends TextualObject<T, D, TO>> void forOwner(@NonNull TO media, @NonNull nl.vpro.domain.media.support.OwnerType owner)
      Sets the owner of all titles, descriptions, locations and images found in given MediaObject
    • filter

      public static <T extends nl.vpro.domain.media.support.MutableOwnable> List<T> filter(Collection<T> ownables, nl.vpro.domain.media.support.OwnerType owner)
    • sorted

      public static <S extends Comparable<?>> SortedSet<@NonNull S> sorted(Set<@NonNull S> set)
    • get

      public static <OT extends TypedText> String get(Collection<OT> titles, TextualType... work)
    • expand

      public static <OT extends OwnedText> Optional<OT> expand(@NonNull Collection<OT> titles, @NonNull TextualType textualType, @NonNull nl.vpro.domain.media.support.OwnerType ownerType)
      Returns the value for a certain TextualType and OwnerType. This implements a fall back mechanism. It takes the first value with matching owner and type. If none found, it will fall back to the highest OwnerType (OwnerType.BROADCASTER and degrades until one is found.

      Furthermore if no 'LEXICO' typed values if found, the value for 'MAIN' will be used.

    • expand

      public static <OT extends OwnedText> Optional<OT> expand(Collection<OT> titles, TextualType textualType)
    • addOrUpdate

      public static <OT extends TypedText> boolean addOrUpdate(Collection<OT> titles, OT add)
      Give a collection, find the first object which equals the object we want to be in it. If one found, the 'value' is copied to it. If not, then the object is added to the collection.

      TypedText's are commonly stored in SortedSet's, where equals matches only owner and type, not the value itself.

      Parameters:
      titles - Collection
      add - the object to add or update.
    • copy

      public static <T1 extends OwnedText, D1 extends OwnedText, TO1 extends TextualObject<T1, D1, TO1>, T2 extends OwnedText, D2 extends OwnedText, TO2 extends TextualObject<T2, D2, TO2>> void copy(TO1 from, TO2 to)
      Copies all titles and descriptions from one TextualObject to another.
      Since:
      5.3
    • updateTitlesForOwner

      public static <T extends AbstractOwnedText<T>, D1 extends AbstractOwnedText<D1>, TO1 extends TextualObject<T, D1, TO1>, D2 extends AbstractOwnedText<D2>, TO2 extends TextualObject<T, D2, TO2>> void updateTitlesForOwner(TO1 incomingMedia, TO2 mediaToUpdate, nl.vpro.domain.media.support.OwnerType owner, nl.vpro.domain.media.support.OwnerType... similarOwnerTypes)
      Copies all titles from one object to another.

      Moved from ImportUtil, SecureUpdateImpl, MediaUpdaterImpl

      Parameters:
      owner - The owner type of the titles to consider
      similarOwnerTypes - If this array is given, a new title is not created if there is no title with the given owner, but there _is_ one with one of these owner types (and it has the same value)*
      Since:
      5.6
    • updateDescriptionsForOwner

      public static <T1 extends AbstractOwnedText<T1>, D extends AbstractOwnedText<D>, TO1 extends TextualObject<T1, D, TO1>, T2 extends AbstractOwnedText<T2>, TO2 extends TextualObject<T2, D, TO2>> void updateDescriptionsForOwner(TO1 incomingMedia, TO2 mediaToUpdate, nl.vpro.domain.media.support.OwnerType owner, nl.vpro.domain.media.support.OwnerType... similarOwnerTypes)
      Copies all descriptions from one object to another.

      Moved from ImportUtil, SecureUpdateImpl, MediaUpdaterImpl

      Since:
      5.6
    • copy

      public static <T1 extends TypedText, D1 extends TypedText, TO1 extends TextualObjectUpdate<T1, D1, TO1>, T2 extends OwnedText, D2 extends OwnedText, TO2 extends TextualObject<T2, D2, TO2>> void copy(TO1 from, TO2 to, nl.vpro.domain.media.support.OwnerType owner)
      Copies all titles and descriptions from one TextualObjectUpdate to a TextualObject.
      Parameters:
      owner - The owner of the fields in the destination
      Since:
      5.3
    • copy

      public static <T1 extends TypedText, D1 extends TypedText, TO1 extends TextualObjectUpdate<T1, D1, TO1>, T2 extends TypedText, D2 extends TypedText, TO2 extends TextualObjectUpdate<T2, D2, TO2>> void copy(TO1 from, TO2 to)
      Copies all titles and descriptions from one TextualObjectUpdate to a TextualObject.
      Since:
      5.11
    • copyAndRemove

      public static <T1 extends TypedText, D1 extends TypedText, TO1 extends TextualObjectUpdate<T1, D1, TO1>, T2 extends OwnedText, D2 extends OwnedText, TO2 extends TextualObject<T2, D2, TO2>> void copyAndRemove(TO1 from, TO2 to, nl.vpro.domain.media.support.OwnerType owner)
      Copies all titles and descriptions from one TextualObjectUpdate to a TextualObject. Then, remove all titles and descriptions (of the given owner) which were not in the source object.
      Parameters:
      owner - The owner of the fields in the destination
      Since:
      5.3
    • retainAll

      public static <TO extends TypedText, TO2 extends OwnedText> void retainAll(Collection<TO2> collection, Collection<TO> toRetain, nl.vpro.domain.media.support.OwnerType owner)
      From a collection of OwnedText's remove all all elements with certain owner, which are not in the source collection of TypedText's.
      Parameters:
      collection - The collection to remove objects from
      toRetain - The collection of texts which are to be retained in collection
      Since:
      5.3
    • retainAll

      public static <TO extends TypedText, TO2 extends TypedText> void retainAll(Collection<TO2> collection, Collection<TO> toRetain)
      Parameters:
      collection - The collection to remove objects from
      toRetain - The collection of texts which are to be retained in collection
      Since:
      5.3
    • copyToUpdate

      public static <T1 extends TypedText, D1 extends TypedText, TO1 extends TextualObjectUpdate<T1, D1, TO1>, T2 extends TypedText, D2 extends TypedText, TO2 extends TextualObjectUpdate<T2, D2, TO2>> void copyToUpdate(@NonNull TO1 from, @NonNull TO2 to)
      Copy all texts from one collection of TextualObjectUpdate to another. If the target collection is a TextualObject then you want to use copy(TextualObjectUpdate, TextualObject, OwnerType)
      Since:
      5.3
    • copyToUpdate

      public static <OT1 extends OwnedText, OD1 extends OwnedText, TO1 extends TextualObject<OT1, OD1, TO1>, T2 extends TypedText, D2 extends TypedText, TO2 extends TextualObjectUpdate<T2, D2, TO2>> void copyToUpdate(@NonNull TO1 from, @NonNull TO2 to, @NonNull nl.vpro.domain.media.support.OwnerType owner)
      Copy all texts from a TextualObject to a TextualObjectUpdate. You can to specify an owner. Preferred are then values with owners equals or lower then this given owner, or if there are none, it will fall back from the top again.

      In principal if the owner is OwnerType.BROADCASTER youu could also use copyToUpdate(TextualObjectUpdate, TextualObjectUpdate)

      Since:
      5.9
    • forUpdate

      protected static <T extends TypedText> void forUpdate(Collection<T> collection, Consumer<T> consumer, Runnable ifNull)
      Since:
      5.8
    • forUpdate

      protected static <T extends OwnedText> void forUpdate(Collection<T> collection, Consumer<T> consumer, Runnable ifNull, nl.vpro.domain.media.support.OwnerType owner)
      Since:
      5.9
    • removeEmptyValues

      public static <T extends OwnedText, D extends OwnedText, TO extends TextualObject<T, D, TO>> void removeEmptyValues(@NonNull TO textualObject)