本文整理匯總了Java中java.util.Queue.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java Queue.clear方法的具體用法?Java Queue.clear怎麽用?Java Queue.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Queue
的用法示例。
在下文中一共展示了Queue.clear方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: render
import java.util.Queue; //導入方法依賴的package包/類
public void render(){
if(models.size()!=toRender.length){
toRender=new Queue[models.size()];
Arrays.fill(toRender, new ArrayDeque<>());
}
rend.start();
particles.forEach(p->toRender[p.getModelIndex()].add(p));
GLUtil.BLEND.set(true);
GLUtil.BLEND_FUNC.set(BlendFunc.ADD);
glDepthMask(false);
for(Queue<Particle<?>> batch:toRender){
Shaders.ENTITY.renderBatch(batch);
batch.clear();
}
rend.end();
GLUtil.BLEND_FUNC.set(BlendFunc.NORMAL);
glDepthMask(true);
}
示例2: processClassC
import java.util.Queue; //導入方法依賴的package包/類
private void processClassC(ClassInstance cls) {
Queue<ClassInstance> toCheck = new ArrayDeque<>();
Set<ClassInstance> checked = Util.newIdentityHashSet();
for (MethodInstance method : cls.methods) {
processMethod(method, toCheck, checked);
toCheck.clear();
checked.clear();
}
for (FieldInstance field : cls.fields) {
processField(field, toCheck, checked);
toCheck.clear();
checked.clear();
}
}
示例3: processClassD
import java.util.Queue; //導入方法依賴的package包/類
/**
* 3rd processing pass, in depth analysis.
*/
private void processClassD(ClassInstance cls, CommonClasses common) {
Queue<MethodInstance> toCheckM = new ArrayDeque<>();
Set<MethodInstance> checkedM = Util.newIdentityHashSet();
for (MethodInstance method : cls.getMethods()) {
processMemberD(method, toCheckM, checkedM);
toCheckM.clear();
checkedM.clear();
//Analysis.analyzeMethod(method, common);
}
Queue<FieldInstance> toCheckF = new ArrayDeque<>();
Set<FieldInstance> checkedF = Util.newIdentityHashSet();
for (FieldInstance field : cls.getFields()) {
processMemberD(field, toCheckF, checkedF);
toCheckF.clear();
checkedF.clear();
if (field.writeRefs.size() == 1) {
Analysis.checkInitializer(field, this);
}
}
}
示例4: removeMessageFrom
import java.util.Queue; //導入方法依賴的package包/類
private void removeMessageFrom(Queue<SqsMessage> messages, String receiptHandle) {
List<SqsMessage> remainingMessages = new ArrayList<>();
messages.stream()
.filter(message -> !StringUtils.equals(receiptHandle, message.getReceiptHandle()))
.forEach(remainingMessages::add);
messages.clear();
messages.addAll(remainingMessages);
}
示例5: removeBatchEntriesFromQueue
import java.util.Queue; //導入方法依賴的package包/類
private void removeBatchEntriesFromQueue(List<BatchEntry> batchEntries,
Queue<SqsMessage> messages) {
List<SqsMessage> remainingMessages = new ArrayList<>();
messages.stream().filter(message -> isMessageNotOnDeletionList(message, batchEntries))
.forEach(remainingMessages::add);
messages.clear();
messages.addAll(remainingMessages);
}
示例6: release
import java.util.Queue; //導入方法依賴的package包/類
public synchronized void release() {
Queue<Object> q = this.queue;
ObjectPool<Queue<Object>> p = this.pool;
if (!(p == null || q == null)) {
q.clear();
this.queue = null;
p.returnObject(q);
}
}
示例7: poisonQueue
import java.util.Queue; //導入方法依賴的package包/類
private static void poisonQueue(final Queue<? extends ConnectionEntry> queue, final RequestException cause) {
for (ConnectionEntry e : queue) {
final Request<?, ?> request = e.getRequest();
LOG.trace("Poisoning request {}", request, cause);
e.complete(request.toRequestFailure(cause));
}
queue.clear();
}
示例8: estimateSpread
import java.util.Queue; //導入方法依賴的package包/類
/**
* Given a seed set, compute spread under IC model
* @param seeds Current seed set
* @param candidate Seed candidate id
*/
public double estimateSpread(Graph graph, Config config,
Set<Integer> seeds, Integer candidate) {
boolean[] active = new boolean[graph.n];
Queue<Integer> bfsQueue = new LinkedList<>();
double ret = 0;
for (int i = 0; i < config.mcRuns; ++i) {
Arrays.fill(active, false);
bfsQueue.clear();
int countActive = 0;
// activate the candidate
if (candidate != null) {
active[candidate] = true;
bfsQueue.add(candidate);
countActive++;
}
// activate all seeds
for (int s : seeds) {
countActive++;
active[s] = true;
bfsQueue.add(s);
}
countActive += bfs(graph, bfsQueue, active);
ret += countActive;
}
return InfMaxUtils.round(ret / (double) config.mcRuns, config.rounding);
}
示例9: spreadStats
import java.util.Queue; //導入方法依賴的package包/類
/**
* Compute spread, mean, and std dev of each PW
*/
public double[] spreadStats(Graph graph, Config config, Set<Integer> seeds) {
double spread = 0;
double[] countActive = new double[config.mcRuns];
Arrays.fill(countActive, 0.0);
boolean[] active = new boolean[graph.n];
Queue<Integer> bfsQueue = new LinkedList<>();
for (int i = 0; i < config.mcRuns; ++i) {
Arrays.fill(active, false);
bfsQueue.clear();
// activate all seeds
for (int s : seeds) {
countActive[i]++;
active[s] = true;
bfsQueue.add(s);
}
countActive[i] += bfs(graph, bfsQueue, active);
spread += countActive[i];
}
double[] stats = new double[3]; // expected spread, mean, std dev
stats[0] = spread / (double) config.mcRuns;
stats[1] = computeMean(countActive);
stats[2] = computeStdDev(countActive);
return stats;
}
示例10: addDependingFieldsToQueue
import java.util.Queue; //導入方法依賴的package包/類
@Test
public void addDependingFieldsToQueue() {
List<TriplePattern> bgp = new ArrayList<TriplePattern>();
bgp.add(tp1);
bgp.add(tp2);
bgp.add(tp3);
bgp.add(tp4);
bgp.add(tp5);
bgp.add(tp6);
bgp.add(tp7);
bgp.add(tp8);
// Subject test
CompositeKey actual = new CompositeKey(tp1.getStringRepresentation(),
Position.SUBJECT);
Queue<CompositeKey> queue = new LinkedList<>();
BGPVerifyUtil.addDependingFieldsToQueue(actual, queue, bgp);
Queue<CompositeKey> expected = new LinkedList<>();
expected.add(new CompositeKey(tp6.getStringRepresentation(),
Position.SUBJECT));
expected.add(new CompositeKey(tp2.getStringRepresentation(),
Position.SUBJECT));
assertQueue(expected, queue);
// Predicate test
actual = new CompositeKey(tp6.getStringRepresentation(),
Position.PREDICATE);
queue.clear();
BGPVerifyUtil.addDependingFieldsToQueue(actual, queue, bgp);
expected.clear();
expected.add(new CompositeKey(tp2.getStringRepresentation(),
Position.SUBJECT));
expected.add(new CompositeKey(tp1.getStringRepresentation(),
Position.OBJECT));
assertQueue(expected, queue);
// Self loop test
actual = new CompositeKey(tp8.getStringRepresentation(),
Position.SUBJECT);
queue.clear();
BGPVerifyUtil.addDependingFieldsToQueue(actual, queue, bgp);
expected.clear();
expected.add(new CompositeKey(tp1.getStringRepresentation(),
Position.SUBJECT));
expected.add(new CompositeKey(tp3.getStringRepresentation(),
Position.SUBJECT));
expected.add(new CompositeKey(tp4.getStringRepresentation(),
Position.SUBJECT));
assertQueue(expected, queue);
// Predicate non variable
actual = new CompositeKey(tp3.getStringRepresentation(),
Position.PREDICATE);
queue.clear();
BGPVerifyUtil.addDependingFieldsToQueue(actual, queue, bgp);
expected.clear();
expected.add(new CompositeKey(tp1.getStringRepresentation(),
Position.SUBJECT));
expected.add(new CompositeKey(tp4.getStringRepresentation(),
Position.SUBJECT));
expected.add(new CompositeKey(tp8.getStringRepresentation(),
Position.SUBJECT));
expected.add(new CompositeKey(tp8.getStringRepresentation(),
Position.OBJECT));
expected.add(new CompositeKey(tp2.getStringRepresentation(),
Position.OBJECT));
assertQueue(expected, queue);
}
示例11: testOrdering
import java.util.Queue; //導入方法依賴的package包/類
@Test
public void testOrdering() throws Exception {
Queue<Object> actual;
Queue<Object> expected;
// emit some out of order events for a given key.
// numerous events are emitted for timestamp 2 to validate support for having
// more than one event at a given timestamp.
testHarness.processElement(record(K1, 1L));
testHarness.processElement(record(K1, 3L));
testHarness.processElement(record(K1, 2L));
testHarness.processElement(record(K1, 2L));
testHarness.processElement(record(K1, 4L));
// advance to timestamp 3, expecting a subset of elements to be emitted.
testHarness.processWatermark(3L);
actual = testHarness.getOutput();
expected = new ConcurrentLinkedQueue<>();
expected.add(record(K1, 1L));
expected.add(record(K1, 2L));
expected.add(record(K1, 2L));
expected.add(record(K1, 3L));
expected.add(watermark(3L));
TestHarnessUtil.assertOutputEquals("Unexpected output", expected, actual);
actual.clear();
// advance to timestamp 4, expecting the final element to be emitted.
testHarness.processWatermark(4L);
actual = testHarness.getOutput();
expected = new ConcurrentLinkedQueue<>();
expected.add(record(K1, 4L));
expected.add(watermark(4L));
TestHarnessUtil.assertOutputEquals("Unexpected output", expected, actual);
actual.clear();
// advance to timestamp 5, expecting no elements to be emitted.
testHarness.processWatermark(5L);
actual = testHarness.getOutput();
expected = new ConcurrentLinkedQueue<>();
expected.add(watermark(5L));
TestHarnessUtil.assertOutputEquals("Unexpected output", expected, actual);
actual.clear();
}
示例12: run
import java.util.Queue; //導入方法依賴的package包/類
static AnyProcess run(File workDir, String command, Queue<String> consoleLines, Consumer<String> onNewLine, Runnable onStop) {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
buffer.write(b);
if (((byte) b) == ((byte) 10)) { // \n
String newLine = new String(buffer.toByteArray(), StandardCharsets.UTF_8);
while (!consoleLines.offer(newLine)) {
consoleLines.poll();
}
buffer.reset();
onNewLine.accept(newLine);
}
}
};
consoleLines.clear();
consoleLines.offer("Running:\n");
consoleLines.offer(command + "\n");
consoleLines.offer("...\n");
AnyProcess process = AnyProcess.newBuilder()
.command(ProcUtils.isWindows() ? new String[]{"cmd.exe", "/c", command} : new String[]{"/bin/bash", "-c", command})
.workingDir(workDir)
.redirectStderr()
.pipeStdout(out)
.build();
Thread waiter = new Thread(() -> {
try {
process.waitFor();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
onStop.run();
}, "Process (" + command + ")");
waiter.setDaemon(true);
waiter.start();
return process;
}
示例13: intersect
import java.util.Queue; //導入方法依賴的package包/類
/**
* Performs intersection on the input collection of policies and returns the resulting (intersected) policy. If input policy
* collection contains only a single policy instance, no intersection is performed and the instance is directly returned
* as a method call result.
*
* @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
* @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
*
* @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
*/
public Policy intersect(final Policy... policies) {
if (policies == null || policies.length == 0) {
throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
} else if (policies.length == 1) {
return policies[0];
}
// check for "null" and "empty" policy: if such policy is found return "null" policy,
// or if all policies are "empty", return "empty" policy
boolean found = false;
boolean allPoliciesEmpty = true;
NamespaceVersion latestVersion = null;
for (Policy tested : policies) {
if (tested.isEmpty()) {
found = true;
} else {
if (tested.isNull()) {
found = true;
}
allPoliciesEmpty = false;
}
if (latestVersion == null) {
latestVersion = tested.getNamespaceVersion();
} else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
latestVersion = tested.getNamespaceVersion();
}
if (found && !allPoliciesEmpty) {
return Policy.createNullPolicy(latestVersion, null, null);
}
}
latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
if (allPoliciesEmpty) {
return Policy.createEmptyPolicy(latestVersion, null, null);
}
// simple tests didn't lead to final answer => let's performe some intersecting ;)
final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
for (int i = 1; i < policies.length; i++) {
final Collection<AssertionSet> currentAlternatives = policies[i].getContent();
testedAlternatives.clear();
testedAlternatives.addAll(finalAlternatives);
finalAlternatives.clear();
AssertionSet testedAlternative;
while ((testedAlternative = testedAlternatives.poll()) != null) {
for (AssertionSet currentAlternative : currentAlternatives) {
if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
alternativesToMerge.add(testedAlternative);
alternativesToMerge.add(currentAlternative);
finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
alternativesToMerge.clear();
}
}
}
}
return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
示例14: estimateSpreadPlus
import java.util.Queue; //導入方法依賴的package包/類
/**
* @param seeds Current seed set
* @param candidate Seed candidate
* @param curBest current best node
* @return An double array {u.mg1, u.mg2}
*/
public double[] estimateSpreadPlus(Graph graph, Config config,
Set<Integer> seeds, int candidate, int curBest) {
boolean[] active = new boolean[graph.n];
Queue<Integer> bfsQueue = new LinkedList<>();
// ret[0] = sigma(S+u), ret[1] = sigma(S+u+curBest), both initialized to 0
double[] ret = new double[2];
for (int i = 0; i < config.mcRuns; ++i) {
// reset relevant data structures
Arrays.fill(active, false);
bfsQueue.clear();
int countActive = 0;
// activate the candidate
active[candidate] = true;
bfsQueue.add(candidate);
countActive++;
// activate all seeds
for (int s : seeds) {
countActive++;
active[s] = true;
bfsQueue.add(s);
}
// compute MG(u | S)
countActive += bfs(graph, bfsQueue, active);
ret[0] += countActive;
ret[1] += countActive;
// compute mg2 = MG(u | S + prevBest)
if (curBest >= 0 && !active[curBest]) {
active[curBest] = true;
countActive = 1;
bfsQueue.add(curBest);
countActive += bfs(graph, bfsQueue, active);
ret[1] += countActive;
}
}
ret[0] = InfMaxUtils.round(ret[0] / (double) config.mcRuns, config.rounding);
ret[1] = InfMaxUtils.round(ret[1] / (double) config.mcRuns, config.rounding);
return ret;
}
示例15: transformedQueue
import java.util.Queue; //導入方法依賴的package包/類
/**
* Factory method to create a transforming queue that will transform
* existing contents of the specified queue.
* <p>
* If there are any elements already in the queue being decorated, they
* will be transformed by this method.
* Contrast this with {@link #transformingQueue(Queue, Transformer)}.
*
* @param <E> the type of the elements in the queue
* @param queue the queue to decorate, must not be null
* @param transformer the transformer to use for conversion, must not be null
* @return a new transformed Queue
* @throws NullPointerException if queue or transformer is null
* @since 4.0
*/
public static <E> TransformedQueue<E> transformedQueue(final Queue<E> queue,
final Transformer<? super E, ? extends E> transformer) {
// throws IAE if queue or transformer is null
final TransformedQueue<E> decorated = new TransformedQueue<E>(queue, transformer);
if (queue.size() > 0) {
@SuppressWarnings("unchecked") // queue is type <E>
final E[] values = (E[]) queue.toArray(); // NOPMD - false positive for generics
queue.clear();
for (final E value : values) {
decorated.decorated().add(transformer.transform(value));
}
}
return decorated;
}