-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Observability extension - devservices, devresources, LGTM #38448
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.quarkus.runtime.util; | ||
|
||
import java.util.Enumeration; | ||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
import java.util.Objects; | ||
import java.util.Spliterator; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Transform to "old school" Enumeration from Iterator/Spliterator/Stream | ||
*/ | ||
public class EnumerationUtil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably leftover from previous PR, it will be used in the 2nd (or 3rd) PR -- when I move all of the code from initial (the huge closed one) PR. |
||
public static <T> Enumeration<T> from(Iterator<T> iterator) { | ||
Objects.requireNonNull(iterator); | ||
|
||
return new Enumeration<T>() { | ||
@Override | ||
public boolean hasMoreElements() { | ||
return iterator.hasNext(); | ||
} | ||
|
||
@Override | ||
public T nextElement() { | ||
return iterator.next(); | ||
} | ||
}; | ||
} | ||
|
||
public static <T> Enumeration<T> from(Spliterator<T> spliterator) { | ||
Objects.requireNonNull(spliterator); | ||
|
||
class Adapter implements Enumeration<T>, Consumer<T> { | ||
boolean valueReady; | ||
T nextElement; | ||
|
||
public void accept(T t) { | ||
this.valueReady = true; | ||
this.nextElement = t; | ||
} | ||
|
||
public boolean hasMoreElements() { | ||
if (!this.valueReady) { | ||
spliterator.tryAdvance(this); | ||
} | ||
|
||
return this.valueReady; | ||
} | ||
|
||
public T nextElement() { | ||
if (!this.valueReady && !this.hasMoreElements()) { | ||
throw new NoSuchElementException(); | ||
} else { | ||
this.valueReady = false; | ||
T t = this.nextElement; | ||
this.nextElement = null; | ||
return t; | ||
} | ||
} | ||
} | ||
|
||
return new Adapter(); | ||
} | ||
|
||
public static <T> Enumeration<T> from(Stream<T> stream) { | ||
return from(stream.spliterator()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these are supposed to always be scope can we set the scope here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that works, that would be perfect.
Let me change it ...