From: Roland Haeder Date: Fri, 7 Aug 2015 11:41:56 +0000 (+0200) Subject: Better return an iterator of Map.Entry. This is really generic, it... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=08cf79beba2d1707717cd01d4cd396244841d019;p=jcore.git Better return an iterator of Map.Entry. This is really generic, it may be fine for first "demo" Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index 33923f8..7d96be8 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -26,10 +26,10 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.Iterator; -import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; import java.util.StringTokenizer; @@ -760,7 +760,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { * @param className Class name to iterate over * @return An iterator over all object's fields */ - protected Iterator fieldIterator (final FrameworkInterface instance, final String className) { + protected Iterator> fieldIterator (final FrameworkInterface instance, final String className) { // Trace message this.getLogger().trace(MessageFormat.format("instance={0},className={1} - CALLED!", instance, className)); @@ -770,8 +770,8 @@ public class BaseFrameworkSystem implements FrameworkInterface { // Debug message this.getLogger().debug(MessageFormat.format("Found {0} fields.", fields.length)); - // A list is fine - List list = new ArrayList<>(fields.length); + // A simple map with K=fieldName and V=Value is fine + Map map = new HashMap<>(fields.length); // Walk through all for (final Field field : fields) { @@ -791,16 +791,13 @@ public class BaseFrameworkSystem implements FrameworkInterface { this.getLogger().debug(MessageFormat.format("value={0}", value)); // Add it to list - boolean added = list.add(value); - - // Debug log - this.getLogger().debug("added=" + added); + map.put(field, value); } // Debug message - this.getLogger().debug(MessageFormat.format("Returning iterator for {0} entries ...", list.size())); + this.getLogger().debug(MessageFormat.format("Returning iterator for {0} entries ...", map.size())); // Return list iterator - return list.iterator(); + return map.entrySet().iterator(); } } diff --git a/src/org/mxchange/jcore/contact/BaseContact.java b/src/org/mxchange/jcore/contact/BaseContact.java index 2465158..b817a59 100644 --- a/src/org/mxchange/jcore/contact/BaseContact.java +++ b/src/org/mxchange/jcore/contact/BaseContact.java @@ -16,8 +16,10 @@ */ package org.mxchange.jcore.contact; +import java.lang.reflect.Field; import java.text.MessageFormat; import java.util.Iterator; +import java.util.Map; import java.util.Objects; import org.mxchange.jcore.BaseFrameworkSystem; import org.mxchange.jcore.client.Client; @@ -596,7 +598,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { * @return An iterator */ @Override - public Iterator iterator () { + public Iterator> iterator () { return this.fieldIterator(this, "BaseContact"); } diff --git a/src/org/mxchange/jcore/contact/Contact.java b/src/org/mxchange/jcore/contact/Contact.java index e4a90b5..f0f3a68 100644 --- a/src/org/mxchange/jcore/contact/Contact.java +++ b/src/org/mxchange/jcore/contact/Contact.java @@ -16,6 +16,9 @@ */ package org.mxchange.jcore.contact; +import java.lang.reflect.Field; +import java.util.Iterator; +import java.util.Map; import org.mxchange.jcore.FrameworkInterface; import org.mxchange.jcore.client.Client; @@ -24,7 +27,12 @@ import org.mxchange.jcore.client.Client; * * @author Roland Haeder */ -public interface Contact extends FrameworkInterface, Iterable { +public interface Contact extends FrameworkInterface { + /** + * Returns an iterator of all values from this object + * @return An iterator + */ + public Iterator> iterator (); /** * Some "getter" for translated gender of the contact