diff --git a/README.md b/README.md index 2835ecc..32c021c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ See [ReleaseNotes](docs/ReleaseNotes.md) for a full history | Item | Description | | ------------------------------------------------------ | ----------------------------------------------- | | **Bugs** | | +| https://github.com/freemansoft/jacob-project/issues/35 | Add Iterable to EnumVariant | | https://github.com/freemansoft/jacob-project/issues/36 | Memory Leak | | https://github.com/freemansoft/jacob-project/issues/38 | Implement Comparable on Currency | | https://github.com/freemansoft/jacob-project/issues/40 | Incorrect delete in Dispatch JNI Invoke() | diff --git a/samples/README.md b/samples/README.md index 44e7f7d..0bef19a 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,4 +1,6 @@ -This contains sample applications that are not run as part of the unit tests +# Samples directory + +Sample applications that are not run as part of the unit tests The ADO sample is a wrapper for the ADO classes. This demonstrates how to write JACOB wrappers. @@ -6,5 +8,3 @@ to write JACOB wrappers. The applet sample shows how to use JACOB in an applet. The trick is to initialize and use the COM object in the same thread. -The test directory has numerous tests that test various features -of the JACOB functionality. diff --git a/src/main/com/jacob/com/EnumVariant.java b/src/main/com/jacob/com/EnumVariant.java index 91bcef1..019e8af 100644 --- a/src/main/com/jacob/com/EnumVariant.java +++ b/src/main/com/jacob/com/EnumVariant.java @@ -19,12 +19,17 @@ */ package com.jacob.com; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + /** * An implementation of IEnumVariant based on code submitted by Thomas Hallgren * (mailto:Thomas.Hallgren@eoncompany.com) */ public class EnumVariant extends JacobObject implements - java.util.Enumeration { + Enumeration, Iterable { /** pointer to windows memory */ private long m_pIEnumVARIANT; @@ -59,7 +64,7 @@ public EnumVariant(Dispatch disp) { /** * Implements java.util.Enumeration - * + * * @return boolean true if there are more elements in this enumeration */ public boolean hasMoreElements() { @@ -74,7 +79,7 @@ public boolean hasMoreElements() { /** * Implements java.util.Enumeration - * + * * @return next element in the enumeration */ public Variant nextElement() { @@ -90,7 +95,7 @@ public Variant nextElement() { /** * Get next element in collection or null if at end - * + * * @return Variant that is next in the collection * @deprecated use nextElement() instead */ @@ -101,9 +106,41 @@ public Variant Next() { return null; } + /** + * {@inheritDoc} + *

+ * This implementation resets the EnumVariant, + * so that iterator() can be called multiple times, + * as can {@link #stream}. + */ + @Override + public Iterator iterator() { + Reset(); + return new Iterator() { + @Override + public boolean hasNext() { + return hasMoreElements(); + } + + @Override + public Variant next() { + return nextElement(); + } + }; + } + + /** + * Get a Stream from this object. + * + * @return Stream<Variant>. + */ + public Stream stream() { + return StreamSupport.stream(this.spliterator(), false); + } + /** * This should be private and wrapped to protect JNI layer. - * + * * @param receiverArray * @return Returns the next variant object pointer as an int from windows * layer @@ -112,9 +149,9 @@ public Variant Next() { /** * This should be private and wrapped to protect JNI layer. - * + * * @param count - * number to skip + * number to skip */ public native void Skip(int count); @@ -126,13 +163,13 @@ public Variant Next() { /** * now private so only this object can access was: call this to explicitly * release the com object before gc - * + * */ private native void release(); /* * (non-Javadoc) - * + * * @see java.lang.Object#finalize() */ @Override @@ -142,7 +179,7 @@ protected void finalize() { /* * (non-Javadoc) - * + * * @see com.jacob.com.JacobObject#safeRelease() */ @Override @@ -159,4 +196,5 @@ public void safeRelease() { } } } + } \ No newline at end of file