/** * Returns a human-readable string representation of the given object. * * @see java.lang.Object#toString() * @param o * the object to represent as string * @return a string representation of the object */ public static String toString(MonolingualTextValue o) { return "\"" + o.getText().replace("\"", "\\\"") + "\" (" + o.getLanguageCode() + ")"; }
protected static Map<String, MonolingualTextValue> constructTermMap(List<MonolingualTextValue> terms) { Map<String, MonolingualTextValue> map = new HashMap<>(); for(MonolingualTextValue term : terms) { String language = term.getLanguageCode(); if(map.containsKey(language)) { throw new IllegalArgumentException("Multiple terms provided for the same language."); } map.put(language, toTerm(term)); } return map; }
private static Map<String, List<MonolingualTextValue>> constructTermListMap(List<MonolingualTextValue> terms) { Map<String, List<MonolingualTextValue>> map = new HashMap<>(); for(MonolingualTextValue term : terms) { String language = term.getLanguageCode(); // We need to make sure the terms are of the right type, otherwise they will not // be serialized correctly. List<MonolingualTextValue> aliases = map.computeIfAbsent(language, (l) -> new ArrayList<>()); aliases.add(toTerm(term)); } return map; }
/** * Returns a human-readable string representation of the given object. * * @see java.lang.Object#toString() * @param o * the object to represent as string * @return a string representation of the object */ public static String toString(MonolingualTextValue o) { return "\"" + o.getText().replace("\"", "\\\"") + "\" (" + o.getLanguageCode() + ")"; }
/** * Copy constructor. * * @param mltv * the object to copy the data from */ @Deprecated public TermImpl(MonolingualTextValue mltv) { this(mltv.getLanguageCode(), mltv.getText()); }
/** * Copy constructor. * * @param mltv * the object to copy the data from */ @Deprecated public TermImpl(MonolingualTextValue mltv) { this(mltv.getLanguageCode(), mltv.getText()); }
@Override public ItemDocument withAliases(String language, List<MonolingualTextValue> aliases) { Map<String, List<MonolingualTextValue>> newAliases = new HashMap<>(this.aliases); for(MonolingualTextValue alias : aliases) { Validate.isTrue(alias.getLanguageCode().equals(language)); } newAliases.put(language, aliases); return new ItemDocumentImpl(getItemId(), labels, descriptions, newAliases, claims, sitelinks, revisionId); }
@Override public PropertyDocument withAliases(String language, List<MonolingualTextValue> aliases) { Map<String, List<MonolingualTextValue>> newAliases = new HashMap<>(this.aliases); for(MonolingualTextValue alias : aliases) { Validate.isTrue(alias.getLanguageCode().equals(language)); } newAliases.put(language, aliases); return new PropertyDocumentImpl(getEntityId(), labels, descriptions, newAliases, claims, datatype, revisionId); }
@Override public ItemDocument withAliases(String language, List<MonolingualTextValue> aliases) { Map<String, List<MonolingualTextValue>> newAliases = new HashMap<>(this.aliases); for(MonolingualTextValue alias : aliases) { Validate.isTrue(alias.getLanguageCode().equals(language)); } newAliases.put(language, aliases); return new ItemDocumentImpl(getItemId(), labels, descriptions, newAliases, claims, sitelinks, revisionId); }
@Override public PropertyDocument withAliases(String language, List<MonolingualTextValue> aliases) { Map<String, List<MonolingualTextValue>> newAliases = new HashMap<>(this.aliases); for(MonolingualTextValue alias : aliases) { Validate.isTrue(alias.getLanguageCode().equals(language)); } newAliases.put(language, aliases); return new PropertyDocumentImpl(getEntityId(), labels, descriptions, newAliases, claims, datatype, revisionId); }
@Override public ItemDocument withLabel(MonolingualTextValue newLabel) { Map<String, MonolingualTextValue> newLabels = new HashMap<>(labels); newLabels.put(newLabel.getLanguageCode(), newLabel); return new ItemDocumentImpl(getItemId(), newLabels, descriptions, aliases, claims, sitelinks, revisionId); }
@Override public PropertyDocument withDescription(MonolingualTextValue newDescription) { Map<String, MonolingualTextValue> newDescriptions = new HashMap<>(descriptions); newDescriptions.put(newDescription.getLanguageCode(), newDescription); return new PropertyDocumentImpl(getEntityId(), labels, newDescriptions, aliases, claims, datatype, revisionId); }
@Override public ItemDocument withLabel(MonolingualTextValue newLabel) { Map<String, MonolingualTextValue> newLabels = new HashMap<>(labels); newLabels.put(newLabel.getLanguageCode(), newLabel); return new ItemDocumentImpl(getItemId(), newLabels, descriptions, aliases, claims, sitelinks, revisionId); }
@Override public PropertyDocument withDescription(MonolingualTextValue newDescription) { Map<String, MonolingualTextValue> newDescriptions = new HashMap<>(descriptions); newDescriptions.put(newDescription.getLanguageCode(), newDescription); return new PropertyDocumentImpl(getEntityId(), labels, newDescriptions, aliases, claims, datatype, revisionId); }
@Override public ItemDocument withDescription(MonolingualTextValue newDescription) { Map<String, MonolingualTextValue> newDescriptions = new HashMap<>(descriptions); newDescriptions.put(newDescription.getLanguageCode(), newDescription); return new ItemDocumentImpl(getItemId(), labels, newDescriptions, aliases, claims, sitelinks, revisionId); }
/** * We need to make sure the terms are of the right type, otherwise they will not be serialized correctly. */ private static MonolingualTextValue toTerm(MonolingualTextValue term) { return term instanceof TermImpl ? term : new TermImpl(term.getLanguageCode(), term.getText()); }
/** * We need to make sure the terms are of the right type, otherwise they will not be serialized correctly. */ private static MonolingualTextValue toTerm(MonolingualTextValue term) { return term instanceof TermImpl ? term : new TermImpl(term.getLanguageCode(), term.getText()); }
/** * Copies a {@link MonolingualTextValue}. This method is not affected by the * language filter option (see * {@link DatamodelConverter#setOptionLanguageFilter(Set)}). * * @param object * object to copy * @return copied object */ public MonolingualTextValue copy(MonolingualTextValue object) { return dataObjectFactory.getMonolingualTextValue(object.getText(), object.getLanguageCode()); }
/** * Creates a monolingual value that is suitable for JSON serialization. * @param monolingualTextValue * target monolingual value for serialization * @return Jackson implementation that is serialized appropriately */ protected TermImpl monolingualToJackson(MonolingualTextValue monolingualTextValue) { return new TermImpl(monolingualTextValue.getLanguageCode(), monolingualTextValue.getText()); } }
/** * Copies a {@link MonolingualTextValue}. This method is not affected by the * language filter option (see * {@link DatamodelConverter#setOptionLanguageFilter(Set)}). * * @param object * object to copy * @return copied object */ public MonolingualTextValue copy(MonolingualTextValue object) { return dataObjectFactory.getMonolingualTextValue(object.getText(), object.getLanguageCode()); }