jacob-project
jacob-project copied to clipboard
Proposed IterableEnumVariant class.
I propose this addition to the com.jacob.com
package. It is an Iterable
and Stream
-able subclass of EnumVariant
.
IteratableEnumVariant class.
package com.jacob.com;
import java.util.Iterator;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* Iterable and streaming EnumVariant.
*
* @author Esmond Pitt
* @since 1.21
*/
public class IterableEnumVariant extends EnumVariant implements Iterable<Variant>
{
/**
* Construct an instance.
*
* @param variant Variant from which to obtain the enumeration.
*/
public IterableEnumVariant(Variant variant)
{
super(variant.m_pVariant);
}
/**
* {@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()
{
super.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<Variant>.
*/
public Stream<Variant> stream()
{
return StreamSupport.stream(this.spliterator(), false);
}
}
(or better still fold this into EnumVariant.
Sample code?
Sure. Executing a query:
Stream
.of(wmiServer)
.map(w -> w.invoke("ExecQuery", new Variant(query)))
.map(Variant::toDispatch)
.map(IterableActiveXComponent::new)
.flatMap(IterableActiveXComponent::stream)
// .peek(System.out::println)
.forEach
(
a ->
{
// System.out.println("query result="+a.getProperty("Name"));
}
)
;
- The example uses IterableActiveXComponent which does not exist in the current code base
- Could you provide the sample query
Added to EnumVariant https://github.com/freemansoft/jacob-project/commit/75124c90d754f5884f909030094215a0584cf256
Still need sample code or the IterableActiveXComponent