下面列出了java.util.ArrayDeque#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 将更新数据与窗口中的对方流数据,根据KEY(条件)进行匹配
* 根据是否允许Join 空流,由具体的Composer进行操作
*/
protected void compose(IEvent[] events, int streamIndex, Set<MultiKey> result)
{
if (events == null || events.length == 0)
{
return;
}
ArrayDeque<IEvent[]> joinTemp = new ArrayDeque<IEvent[]>();
for (IEvent theEvent : events)
{
perEventCompose(theEvent, streamIndex, joinTemp);
// 如果joinTemp结果无事件,则没有任何结果
for (IEvent[] row : joinTemp)
{
result.add(new MultiKey(row));
}
joinTemp.clear();
}
}
/**
* 针对每个更新数据,与对方流有效数据进行全匹配
* 如果对方 流中没有有效数据,至少输出一条结果数据
*/
private void compose(IEvent[] events, int streamIndex, Set<MultiKey> result)
{
if (events == null || events.length == 0)
{
return;
}
ArrayDeque<IEvent[]> joinTemp = new ArrayDeque<IEvent[]>();
for (IEvent theEvent : events)
{
perEventCompose(theEvent, streamIndex, joinTemp);
for (IEvent[] row : joinTemp)
{
result.add(new MultiKey(row));
}
joinTemp.clear();
}
}
/**
* clear removes all elements
*/
public void testClear() {
ArrayDeque q = populatedDeque(SIZE);
q.clear();
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertTrue(q.add(new Integer(1)));
assertFalse(q.isEmpty());
q.clear();
assertTrue(q.isEmpty());
}
/**
* clear removes all elements
*/
public void testClear() {
ArrayDeque q = populatedDeque(SIZE);
q.clear();
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertTrue(q.add(new Integer(1)));
assertFalse(q.isEmpty());
q.clear();
assertTrue(q.isEmpty());
}
private void dumpBusEvents(Execution execution) throws InterruptedException {
final ArrayDeque<ScoreEvent> eventsQueue = execution.getSystemContext().getEvents();
if ((eventsQueue != null) && !eventsQueue.isEmpty()) {
for (ScoreEvent eventWrapper : eventsQueue) {
eventBus.dispatch(eventWrapper);
}
eventsQueue.clear();
}
}
@Test
public void testFlushStopping() throws XMPPException, TigaseStringprepException {
String recipient = "[email protected]";
JID recp1 = JID.jidInstanceNS(recipient + "/res1");
JID connId1 = JID.jidInstanceNS("[email protected]/recipient1-res1");
XMPPResourceConnection session1 = getSession(connId1, recp1);
enableCSI(session1);
ArrayDeque<Packet> results = new ArrayDeque<>();
Packet p = Packet.packetInstance("presence", "[email protected]/res1", recp1.toString(), StanzaType.available);
p.setPacketTo(connId1);
csi.filter(p, session1, null, results);
results.clear();
Packet m = Packet.packetInstance("message", "[email protected]/res1", recp1.toString(), StanzaType.chat);
m.getElement().addChild(new Element("received", new String[]{ "xmlns" }, new String[] { "urn:xmpp:receipts" }));
m.setPacketTo(connId1);
results.offer(m);
csi.filter(m, session1, null, results);
results.clear();
results.offer(m);
results.clear();
csi.stopped(session1, results, new HashMap<>());
Packet[] processed = results.toArray(new Packet[results.size()]);
Assert.assertEquals(0, processed.length);
}
private <T> boolean search(MimedType<T> target, ArrayDeque<PathInfo> bestMatch, ArrayDeque<PathInfo> currentPath, MimedType currentSearch, HashSet<MimedType> searched) {
if (target.isTypeOf(currentSearch)) {
bestMatch.clear();
bestMatch.addAll(currentPath);
return true;
}
// the current path must have potential to be better than the best match
if (!bestMatch.isEmpty() && PathInfo.distance(currentPath) >= PathInfo.distance(bestMatch))
return false;
// prevent reentrancy
if (searched.contains(currentSearch))
return false;
boolean found = false;
searched.add(currentSearch);
ConverterTransformers<Object, Object> converterTransformers = outputs.getAll(currentSearch);
for (MimedType candidate: converterTransformers.keySet()) {
// this simulates the mime results of a transform
MimedType newSearch = new MimedType(candidate.type, mimeReplace(currentSearch.mime, candidate.mime));
PathInfo path = new PathInfo();
path.transformer = converterTransformers.get(candidate);
path.mime = newSearch.mime;
path.candidate = candidate;
currentPath.addLast(path);
try {
found |= search(target, bestMatch, currentPath, newSearch, searched);
}
finally {
currentPath.removeLast();
}
}
if (found) {
// if this resulted in a success,
// clear this from the currentSearch list, because we know this leads
// to a potential solution. maybe we can arrive here faster.
searched.remove(currentSearch);
}
return found;
}
/**
* Inspect the instructions to find details over a specific stack position.
*
* @param instructions
* the parsed instructions
* @param count
* the count of values on the stack back. 1 means the last value. 2 means the penultimate value.
* @param javaCodePos
* the current code position, important to follow jumps in the code
* @return details of the stack position
*/
static StackValue findInstructionThatPushValue( List<WasmInstruction> instructions, int count, int javaCodePos ) {
// because there can be jumps (GOTO) we can analyze the stack only forward. If we iterate backward we will not see that we are in a jump.
ArrayDeque<StackValue> stack = new ArrayDeque<>();
int size = instructions.size();
for( int i = 0; i < size; i++ ) {
WasmInstruction instr = instructions.get( i );
int popCount = instr.getPopCount();
for( int p = 0; p < popCount; p++ ) {
stack.pop();
}
AnyType pushValue = instr.getPushValueType();
if( pushValue != null ) {
StackValue el = new StackValue();
el.idx = i;
el.instr = instr;
stack.push( el );
}
if( instr.getType() == Type.Jump ) {
if( popCount == 0 ) { // GOTO, for example on the end of the THEN branch
JumpInstruction jump = (JumpInstruction)instr;
int jumpPos = jump.getJumpPosition();
if( jumpPos > javaCodePos ) {
// we need a stack position inside a branch, we can remove all outside
stack.clear();
} else if( jumpPos > instr.getCodePosition() ) {
while( ++i < size && jumpPos > instructions.get( i ).getCodePosition() ) {
//nothing
}
i--; // we are on the right position but the loop increment
}
}
}
}
try {
StackValue stackValue;
do {
stackValue = stack.pop();
} while( --count > 0 );
return stackValue;
} catch( NoSuchElementException ex ) {
throw new WasmException( "Push instruction not found", -1 ); // should never occur
}
}