Java Code Examples for java.util.ArrayDeque#clear()

The following examples show how to use java.util.ArrayDeque#clear() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: PoseidonX   File: BiIndexedJoinComposer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 将更新数据与窗口中的对方流数据,根据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();
    }
}
 
Example 2
Source Project: PoseidonX   File: CrossBiJoinComposer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 针对每个更新数据,与对方流有效数据进行全匹配
 * 如果对方 流中没有有效数据,至少输出一条结果数据
 */
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();
    }
    
}
 
Example 3
/**
 * 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());
}
 
Example 4
Source Project: j2objc   File: ArrayDequeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 5
Source Project: score   File: ExecutionServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 6
@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);
}
 
Example 7
Source Project: MediaSDK   File: Converter.java    License: Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 8
Source Project: JWebAssembly   File: StackInspector.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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
    }
}