From 19ee77cb5c0bd8183599f3f4bd166dddd6901c59 Mon Sep 17 00:00:00 2001 From: Zikani Nyirenda Mwase Date: Wed, 7 Jul 2021 15:44:08 +0200 Subject: [PATCH] Add some more addAttribute methods to make developer experience better --- .../scify/jedai/datamodel/EntityProfile.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/main/java/org/scify/jedai/datamodel/EntityProfile.java b/src/main/java/org/scify/jedai/datamodel/EntityProfile.java index 39858914..22e7cca8 100644 --- a/src/main/java/org/scify/jedai/datamodel/EntityProfile.java +++ b/src/main/java/org/scify/jedai/datamodel/EntityProfile.java @@ -17,6 +17,9 @@ package org.scify.jedai.datamodel; import java.io.Serializable; +import java.sql.Date; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.HashSet; import java.util.Set; @@ -43,6 +46,83 @@ public void addAttribute(String propertyName, String propertyValue) { attributes.add(new Attribute(propertyName, propertyValue)); } + /** + * Add an integer attribute to the profile + * + * @param propertyName name of the attribute + * @param propertyValue value of the attribute + * @see String#valueOf(int) + */ + public void addAttribute(String propertyName, int propertyValue) { + attributes.add(new Attribute(propertyName, String.valueOf(propertyValue))); + } + + /** + * Add an attribute to the profile + * + * @param propertyName name of the attribute + * @param propertyValue value of the attribute + * @see String#valueOf(long) + */ + public void addAttribute(String propertyName, long propertyValue) { + attributes.add(new Attribute(propertyName, String.valueOf(propertyValue))); + } + + /** + * Add an attribute to the profile + * + * @param propertyName name of the attribute + * @param propertyValue value of the attribute + * @see String#valueOf(float) + */ + public void addAttribute(String propertyName, float propertyValue) { + attributes.add(new Attribute(propertyName, String.valueOf(propertyValue))); + } + + /** + * Add an attribute to the profile + * + * @param propertyName name of the attribute + * @param propertyValue value of the attribute + * @see String#valueOf(double) + */ + public void addAttribute(String propertyName, double propertyValue) { + attributes.add(new Attribute(propertyName, String.valueOf(propertyValue))); + } + + /** + * Add an attribute to the profile + * + * @param propertyName name of the attribute + * @param propertyValue value of the attribute + * @see String#valueOf(Object) + */ + public void addAttribute(String propertyName, Date propertyValue) { + attributes.add(new Attribute(propertyName, String.valueOf(propertyValue))); + } + + /** + * Add an attribute to the profile + * + * @param propertyName name of the attribute + * @param propertyValue local date value of the attribute + * @see LocalDate#format(DateTimeFormatter) + */ + public void addAttribute(String propertyName, LocalDate propertyValue) { + attributes.add(new Attribute(propertyName, propertyValue.format(DateTimeFormatter.ISO_DATE))); + } + + /** + * Add an attribute to the profile + * + * @param propertyName name of the attribute + * @param propertyValue local date value of the attribute + * @see LocalDate#format(DateTimeFormatter) + */ + public void addAttribute(String propertyName, LocalDate propertyValue, DateTimeFormatter formatter) { + attributes.add(new Attribute(propertyName, propertyValue.format(formatter))); + } + public String getEntityUrl() { return entityUrl; }