本文整理匯總了Java中java.util.function.BooleanSupplier.getAsBoolean方法的典型用法代碼示例。如果您正苦於以下問題:Java BooleanSupplier.getAsBoolean方法的具體用法?Java BooleanSupplier.getAsBoolean怎麽用?Java BooleanSupplier.getAsBoolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.function.BooleanSupplier
的用法示例。
在下文中一共展示了BooleanSupplier.getAsBoolean方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: awaitBusy
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
public static boolean awaitBusy(BooleanSupplier breakSupplier, long maxWaitTime, TimeUnit unit) throws InterruptedException {
long maxTimeInMillis = TimeUnit.MILLISECONDS.convert(maxWaitTime, unit);
long timeInMillis = 1;
long sum = 0;
while (sum + timeInMillis < maxTimeInMillis) {
if (breakSupplier.getAsBoolean()) {
return true;
}
Thread.sleep(timeInMillis);
sum += timeInMillis;
timeInMillis = Math.min(AWAIT_BUSY_THRESHOLD, timeInMillis * 2);
}
timeInMillis = maxTimeInMillis - sum;
Thread.sleep(Math.max(timeInMillis, 0));
return breakSupplier.getAsBoolean();
}
示例2: runTimerOnEDT
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
/**
* Allow to run method at specified interval on EDT
* <p>
* Inside boolean supplier, return false to stop timer
*
* @param interval
* @param run
*/
public static void runTimerOnEDT(int interval, BooleanSupplier run) {
ActionListener action = (e) -> {
if (SwingUtilities.isEventDispatchThread() == false) {
throw new IllegalStateException("Do not run this method on Event Dispatch Thread");
}
// perform action and get return value
boolean continueTimer = run.getAsBoolean();
// if return false, stop timer
if (continueTimer == false) {
((Timer) e.getSource()).stop();
}
};
// launch timer
Timer timer = new Timer(interval, action);
timer.start();
}
示例3: isNederlandsAdres
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
private boolean isNederlandsAdres(final MetaRecord adresRecord) {
final BooleanSupplier landGebiedCodeisNL = () ->
adresRecord.getAttribuut(Element.PERSOON_ADRES_LANDGEBIEDCODE) != null
&& adresRecord.getAttribuut(Element.PERSOON_ADRES_LANDGEBIEDCODE).<String>getWaarde().equals(LandOfGebied.CODE_NEDERLAND);
final BooleanSupplier buitenlandsAdresRegelsZijnLeeg = () ->
Lists.newArrayList(
Element.PERSOON_ADRES_BUITENLANDSADRESREGEL1,
Element.PERSOON_ADRES_BUITENLANDSADRESREGEL2,
Element.PERSOON_ADRES_BUITENLANDSADRESREGEL3,
Element.PERSOON_ADRES_BUITENLANDSADRESREGEL4,
Element.PERSOON_ADRES_BUITENLANDSADRESREGEL5,
Element.PERSOON_ADRES_BUITENLANDSADRESREGEL6).stream().allMatch(elem ->
adresRecord.getAttribuut(elem) == null || adresRecord.getAttribuut(elem).getWaarde() == null);
return landGebiedCodeisNL.getAsBoolean() && buitenlandsAdresRegelsZijnLeeg.getAsBoolean();
}
示例4: doVisitAttribuut
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
private void doVisitAttribuut(final MetaAttribuut attribuut, final Onderzoekbundel onderzoekbundel) {
final BooleanSupplier ontbrekendGegeven = () -> onderzoekbundel.isOntbrekend()
&& attribuut.getAttribuutElement().equals(onderzoekbundel.getElement());
final BooleanSupplier voorkomenGegeven = () -> onderzoekbundel.getElementVoorkomensleutel() != null
&& attribuut.getParentRecord().getVoorkomensleutel() == onderzoekbundel.getElementVoorkomensleutel();
final BooleanSupplier objectGegeven = () -> onderzoekbundel.getElementObjectsleutel() != null
&& attribuut.getParentRecord().getParentGroep().getParentObject()
.getObjectsleutel() == onderzoekbundel.getElementObjectsleutel();
if (ontbrekendGegeven.getAsBoolean() || voorkomenGegeven.getAsBoolean() || objectGegeven.getAsBoolean()) {
//voor bepaalde attributen in onderzoek moet het object in onderzoek geplaatst worden
if (onderzoekbundel.getElementObjectsleutel() != null) {
gegevensInOnderzoekTemp.put(onderzoekbundel, attribuut.getParentRecord().getParentGroep().getParentObject());
} else {
gegevensInOnderzoekTemp.put(onderzoekbundel, attribuut);
}
}
}
示例5: waitForCondition
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
/**
* Wait until timeout for condition to be true for specified time
*
* @param condition, a condition to wait for
* @param timeout a time in milliseconds to wait for condition to be true,
* specifying -1 will wait forever
* @param sleepTime a time to sleep value in milliseconds
* @return condition value, to determine if wait was successfull
*/
public static final boolean waitForCondition(BooleanSupplier condition,
long timeout, long sleepTime) {
long startTime = System.currentTimeMillis();
while (!(condition.getAsBoolean() || (timeout != -1L
&& ((System.currentTimeMillis() - startTime) > timeout)))) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new Error(e);
}
}
return condition.getAsBoolean();
}
示例6: conditionTrueForNIterations
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
public static BooleanSupplier conditionTrueForNIterations(BooleanSupplier condition, int iters) {
final AtomicInteger ai = new AtomicInteger(0);
return () -> {
if (condition.getAsBoolean()) {
int i = ai.incrementAndGet();
return i >= iters;
} else {
ai.set(0);
return false;
}
};
}
示例7: gcAwait
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
static void gcAwait(BooleanSupplier s) {
for (int i = 0; i < 10; i++) {
if (s.getAsBoolean())
return;
forceFullGc();
}
throw new AssertionError("failed to satisfy condition");
}
示例8: create
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
/**
* <p>Creates a binding using the passed supplier and list of dependencies.</p>
*
* <p>Note that this method requires manual implementation of the respective binding logic. For
* most cases, however, the static methods provided by this interface do suffice however and
* require far less manually programmed logic.</p>
*/
@Nonnull
static BooleanBinding create(@Nonnull BooleanSupplier supplier,
ReadOnlyObservable<?>... observables) {
return new AbstractBooleanBinding(new HashSet<>(Arrays.asList(observables))) {
@Override
protected Boolean compute() {
return supplier.getAsBoolean();
}
};
}
示例9: waitForCondition
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
/**
* Wait until timeout for condition to be true for specified time
*
* @param condition, a condition to wait for
* @param timeout a time in milliseconds to wait for condition to be true,
* specifying -1 will wait forever
* @param sleepTime a time to sleep value in milliseconds
* @return condition value, to determine if wait was successful
*/
public static final boolean waitForCondition(BooleanSupplier condition,
long timeout, long sleepTime) {
long startTime = System.currentTimeMillis();
while (!(condition.getAsBoolean() || (timeout != -1L
&& ((System.currentTimeMillis() - startTime) > timeout)))) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new Error(e);
}
}
return condition.getAsBoolean();
}
示例10: consume
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
/**
* Use the supplied function to asynchronously consume messages from the cluster.
*
* @param groupId the name of the group; may not be null
* @param clientId the name of the client; may not be null
* @param autoOffsetReset how to pick a starting offset when there is no initial offset in ZooKeeper or if an offset is
* out of range; may be null for the default to be used
* @param keyDeserializer the deserializer for the keys; may not be null
* @param valueDeserializer the deserializer for the values; may not be null
* @param continuation the function that determines if the consumer should continue; may not be null
* @param offsetCommitCallback the callback that should be used after committing offsets; may be null if offsets are
* not to be committed
* @param completion the function to call when the consumer terminates; may be null
* @param topics the set of topics to consume; may not be null or empty
* @param consumerFunction the function to consume the messages; may not be null
*/
public <K, V> void consume(String groupId, String clientId, OffsetResetStrategy autoOffsetReset,
Deserializer<K> keyDeserializer, Deserializer<V> valueDeserializer,
BooleanSupplier continuation, OffsetCommitCallback offsetCommitCallback, Runnable completion,
Collection<String> topics,
java.util.function.Consumer<ConsumerRecord<K, V>> consumerFunction) {
Properties props = getConsumerProperties(groupId, clientId, autoOffsetReset);
Thread t = new Thread(() -> {
LOGGER.info("Starting consumer {} to read messages", clientId);
try (KafkaConsumer<K, V> consumer = new KafkaConsumer<>(props, keyDeserializer, valueDeserializer)) {
consumer.subscribe(new ArrayList<>(topics));
while (continuation.getAsBoolean()) {
consumer.poll(10).forEach(record -> {
LOGGER.info("Consumer {}: consuming message {}", clientId, record);
consumerFunction.accept(record);
if (offsetCommitCallback != null) {
consumer.commitAsync(offsetCommitCallback);
}
});
}
} finally {
if (completion != null) completion.run();
LOGGER.debug("Stopping consumer {}", clientId);
}
});
t.setName(clientId + "-thread");
t.start();
}
示例11: valideerZoekOptie
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
private void valideerZoekOptie(final ZoekPersoonVerzoek.ZoekCriteria zoekCriterium, final Set<Melding> meldingen) {
final AttribuutElement attribuut = ElementHelper.getAttribuutElement(zoekCriterium.getElementNaam());
//controleer vanaf en klein
final BooleanSupplier valideerKleinZoeken = () -> !Zoekoptie.KLEIN.equals(zoekCriterium.getZoekOptie()) || attribuut.isString();
final BooleanSupplier
valideerVanafZoeken =
() -> !(Zoekoptie.VANAF_KLEIN.equals(zoekCriterium.getZoekOptie()) || Zoekoptie.VANAF_EXACT.equals(zoekCriterium.getZoekOptie())) || attribuut
.isString() || attribuut.isDatum();
if (!(valideerKleinZoeken.getAsBoolean() && valideerVanafZoeken.getAsBoolean())) {
LOGGER.debug(String.format(FOUT_MELDING, Regel.R2281.toString(), zoekCriterium.getElementNaam()));
meldingen.add(new Melding(Regel.R2281));
}
}
示例12: checkComparedTypes
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
/**
* Controleert of de types van twee expressies vergelijkbaar zijn, rekening houdend met mogelijke NULL-waarden.
*
* @param expressie1 Eerste expressie.
* @param expressie2 Tweede expressie.
* @param errorHandler De error handler
* @return Code van de gevonden typefout, anders ParserFoutCode.GEEN_FOUT.
*/
static ParserFoutCode checkComparedTypes(final Expressie expressie1, final Expressie expressie2,
final Function<ParserFoutCode, ExpressieParseException> errorHandler) {
final ExpressieType type1 = getExpressieType(expressie1);
final ExpressieType type2 = getExpressieType(expressie2);
final BooleanSupplier isGelijk = () -> type1.equals(type2);
final BooleanSupplier isCompatibel = () -> type1.isCompatibel(type2);
final BooleanSupplier isOnbekendOfNull = () -> type1.isOnbekendOfNull() || type2.isOnbekendOfNull();
final BooleanSupplier isLijst = () -> type1 == ExpressieType.LIJST || type2 == ExpressieType.LIJST;
if (!(isGelijk.getAsBoolean() || isCompatibel.getAsBoolean() || isOnbekendOfNull.getAsBoolean() || isLijst.getAsBoolean())) {
throw errorHandler.apply(getMissingTypeError(type1));
}
return ParserFoutCode.GEEN_FOUT;
}
示例13: continueIfNotExpired
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
protected BooleanSupplier continueIfNotExpired(BooleanSupplier continuation,
long timeout, TimeUnit unit) {
return new BooleanSupplier() {
long stopTime = 0L;
public boolean getAsBoolean() {
if (this.stopTime == 0L) {
this.stopTime = System.currentTimeMillis() + unit.toMillis(timeout);
}
return continuation.getAsBoolean() && System.currentTimeMillis() <= this.stopTime;
}
};
}
示例14: spinWaitUntil
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
static void spinWaitUntil(BooleanSupplier predicate, long timeoutMillis) {
long startTime = -1L;
while (!predicate.getAsBoolean()) {
if (startTime == -1L)
startTime = System.nanoTime();
else if (millisElapsedSince(startTime) > timeoutMillis)
throw new AssertionError(
String.format("timed out after %s ms", timeoutMillis));
Thread.yield();
}
}
示例15: waitFor
import java.util.function.BooleanSupplier; //導入方法依賴的package包/類
public static boolean waitFor(BooleanSupplier condition, BooleanSupplier failCondition, long interval, long timeout) throws InterruptedException, TimeoutException {
timeout = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < timeout) {
if (failCondition != null && failCondition.getAsBoolean()) {
return false;
}
if (condition.getAsBoolean()) {
return true;
}
Thread.sleep(interval);
}
throw new TimeoutException();
}