Skip to content

Commit

Permalink
#35 add Iterable to EnumVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
freemansoft committed Mar 19, 2024
1 parent c7b0ecc commit 75124c9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() |
Expand Down
6 changes: 3 additions & 3 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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.

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.
58 changes: 48 additions & 10 deletions src/main/com/jacob/com/EnumVariant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected])
*/
public class EnumVariant extends JacobObject implements
java.util.Enumeration<Variant> {
Enumeration<Variant>, Iterable<Variant> {
/** pointer to windows memory */
private long m_pIEnumVARIANT;

Expand Down Expand Up @@ -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() {
Expand All @@ -74,7 +79,7 @@ public boolean hasMoreElements() {

/**
* Implements java.util.Enumeration
*
*
* @return next element in the enumeration
*/
public Variant nextElement() {
Expand All @@ -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
*/
Expand All @@ -101,9 +106,41 @@ public Variant Next() {
return null;
}

/**
* {@inheritDoc}
* <p>
* This implementation resets the EnumVariant,
* so that <code>iterator()</code> can be called multiple times,
* as can {@link #stream}.
*/
@Override
public Iterator<Variant> iterator() {
Reset();
return new Iterator<Variant>() {
@Override
public boolean hasNext() {
return hasMoreElements();
}

@Override
public Variant next() {
return nextElement();
}
};
}

/**
* Get a Stream from this object.
*
* @return Stream&lt;Variant&gt;.
*/
public Stream<Variant> 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
Expand All @@ -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);

Expand All @@ -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
Expand All @@ -142,7 +179,7 @@ protected void finalize() {

/*
* (non-Javadoc)
*
*
* @see com.jacob.com.JacobObject#safeRelease()
*/
@Override
Expand All @@ -159,4 +196,5 @@ public void safeRelease() {
}
}
}

}

0 comments on commit 75124c9

Please sign in to comment.