nl.vpro.domain.LocalizedObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of media-domain Show documentation
Show all versions of media-domain Show documentation
The basic domain classes for 'media', the core of POMS. Also, the 'update' XML bindings for it.
It also contains some closely related domain classes like the enum to contain NICAM kijkwijzer settings.
package nl.vpro.domain;
import java.util.*;
import java.util.function.Supplier;
import nl.vpro.domain.media.*;
import nl.vpro.domain.media.support.Tag;
/**
* An object that can be translated. The is valid for the fields of {@link TextualObject}, but also for {@link Tag}, {@link Website}, and {@link nl.vpro.domain.media.TwitterRef} references.
*
* @author Michiel Meeuwissen
* @since 5.1
* @param The type of one title
* @param The type of one description
* @param The type of one website object
* @param The type of one twitter reference
* @param This type itself
*/
public interface LocalizedObject<
T extends OwnedText,
D extends OwnedText,
WS extends Supplier & UpdatableIdentifiable,
TR extends Supplier,
TO extends LocalizedObject>
extends TextualObject {
SortedSet getTags();
void setTags(Set tags);
default TO addTag(Tag tag) {
getTags().add(tag);
return self();
}
default boolean removeTag(Tag tag) {
SortedSet tags = getTags();
return tags != null && tags.remove(tag);
}
List getWebsites();
TO setWebsites(List websites);
default WS getMainWebsite() {
return getWebsites().stream().findFirst().orElse(null);
}
default WS findWebsite(Long id) {
for (WS website : getWebsites()) {
if (id.equals(website.getId())) {
return website;
}
}
return null;
}
default WS findWebsite(WS website) {
List websites = getWebsites();
int index = websites.indexOf(website);
if (index >= 0) {
return websites.get(index);
}
return null;
}
default WS getWebsite(final WS website) {
for (WS existing : getWebsites()) {
if (existing.equals(website)) {
return existing;
}
}
return null;
}
default void addWebsite(final WS website) {
if (website != null) {
getWebsites().remove(website);
getWebsites().add(website);
}
}
default void addWebsite(int index, final WS website) {
if (website != null) {
List websites = getWebsites();
websites.remove(website);
if (index < websites.size()) {
websites.add(index, website);
} else {
websites.add(website);
}
}
}
default boolean removeWebsite(final Long id) {
for (Iterator iterator = getWebsites().iterator(); iterator.hasNext(); ) {
WS website = iterator.next();
if (id.equals(website.getId())) {
iterator.remove();
return true;
}
}
return false;
}
default boolean removeWebsite(final WS website) {
return getWebsites().remove(website);
}
List getTwitterRefs();
void setTwitterRefs(List twitterRefs);
default void addTwitterRef(TR ref) {
List twitterRefs = getTwitterRefs();
if (twitterRefs == null) {
twitterRefs = new ArrayList<>();
}
if (!twitterRefs.contains(ref)) {
twitterRefs.add(ref);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy