List of usage examples for java.util ArrayDeque size
public int size()
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(1);//w w w. ja v a 2 s . c om deque.add(2); deque.add(10); System.out.println(deque); // finding size of this deque int retval = deque.size(); System.out.println("Deque consists of " + retval + " elements"); deque.clear(); retval = deque.size(); System.out.println("Now, deque consists of " + retval + " elements"); }
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(3);/* w w w .j av a2 s . c om*/ deque.add(1); deque.add(25); deque.add(4); System.out.println(deque); // this will print the size of this deque int retval = deque.size(); System.out.println("Size of deque = " + retval); }
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(3);/* w ww . jav a2s . c om*/ deque.add(1); deque.add(25); deque.add(18); System.out.println(deque); // printing the array length of elements added above Integer[] ob = deque.toArray(new Integer[deque.size()]); System.out.println("\n Array Size : " + ob.length); }
From source file:com.espertech.esper.core.context.util.StatementAgentInstanceUtil.java
private static void evaluateEventForStatementInternal(EPServicesContext servicesContext, EventBean theEvent, List<AgentInstance> agentInstances) { // context was created - reevaluate for the given event ArrayDeque<FilterHandle> callbacks = new ArrayDeque<FilterHandle>(2); servicesContext.getFilterService().evaluate(theEvent, callbacks); // evaluates for ALL statements if (callbacks.isEmpty()) { return;// w w w . ja v a 2s. c o m } // there is a single callback and a single context, if they match we are done if (agentInstances.size() == 1 && callbacks.size() == 1) { AgentInstance agentInstance = agentInstances.get(0); if (agentInstance.getAgentInstanceContext().getStatementId() .equals(callbacks.getFirst().getStatementId())) { process(agentInstance, servicesContext, callbacks, theEvent); } return; } // use the right sorted/unsorted Map keyed by AgentInstance to sort boolean isPrioritized = servicesContext.getConfigSnapshot().getEngineDefaults().getExecution() .isPrioritized(); Map<AgentInstance, Object> stmtCallbacks; if (!isPrioritized) { stmtCallbacks = new HashMap<AgentInstance, Object>(); } else { stmtCallbacks = new TreeMap<AgentInstance, Object>(AgentInstanceComparator.INSTANCE); } // process all callbacks for (FilterHandle filterHandle : callbacks) { // determine if this filter entry applies to any of the affected agent instances String statementId = filterHandle.getStatementId(); AgentInstance agentInstanceFound = null; for (AgentInstance agentInstance : agentInstances) { if (agentInstance.getAgentInstanceContext().getStatementId().equals(statementId)) { agentInstanceFound = agentInstance; break; } } if (agentInstanceFound == null) { // when the callback is for some other stmt continue; } EPStatementHandleCallback handleCallback = (EPStatementHandleCallback) filterHandle; EPStatementAgentInstanceHandle handle = handleCallback.getAgentInstanceHandle(); // Self-joins require that the internal dispatch happens after all streams are evaluated. // Priority or preemptive settings also require special ordering. if (handle.isCanSelfJoin() || isPrioritized) { Object stmtCallback = stmtCallbacks.get(agentInstanceFound); if (stmtCallback == null) { stmtCallbacks.put(agentInstanceFound, handleCallback); } else if (stmtCallback instanceof ArrayDeque) { ArrayDeque<EPStatementHandleCallback> q = (ArrayDeque<EPStatementHandleCallback>) stmtCallback; q.add(handleCallback); } else { ArrayDeque<EPStatementHandleCallback> q = new ArrayDeque<EPStatementHandleCallback>(4); q.add((EPStatementHandleCallback) stmtCallback); q.add(handleCallback); stmtCallbacks.put(agentInstanceFound, q); } continue; } // no need to be sorted, process process(agentInstanceFound, servicesContext, Collections.<FilterHandle>singletonList(handleCallback), theEvent); } if (stmtCallbacks.isEmpty()) { return; } // Process self-join or sorted prioritized callbacks for (Map.Entry<AgentInstance, Object> entry : stmtCallbacks.entrySet()) { AgentInstance agentInstance = entry.getKey(); Object callbackList = entry.getValue(); if (callbackList instanceof ArrayDeque) { process(agentInstance, servicesContext, (Collection<FilterHandle>) callbackList, theEvent); } else { process(agentInstance, servicesContext, Collections.<FilterHandle>singletonList((FilterHandle) callbackList), theEvent); } if (agentInstance.getAgentInstanceContext().getEpStatementAgentInstanceHandle().isPreemptive()) { return; } } }
From source file:com.espertech.esper.collection.TestTimeWindow.java
public void testAdd() { assertTrue(window.getOldestTimestamp() == null); assertTrue(window.isEmpty());/* w w w.jav a 2s.c o m*/ window.add(19, beans[0]); assertTrue(window.getOldestTimestamp() == 19L); assertFalse(window.isEmpty()); window.add(19, beans[1]); assertTrue(window.getOldestTimestamp() == 19L); window.add(20, beans[2]); assertTrue(window.getOldestTimestamp() == 19L); window.add(20, beans[3]); window.add(21, beans[4]); window.add(22, beans[5]); assertTrue(window.getOldestTimestamp() == 19L); ArrayDeque<EventBean> beanList = window.expireEvents(19); assertTrue(beanList == null); beanList = window.expireEvents(20); assertTrue(beanList.size() == 2); assertTrue(beanList.poll() == beans[0]); assertTrue(beanList.poll() == beans[1]); beanList = window.expireEvents(21); assertTrue(beanList.size() == 2); assertTrue(beanList.poll() == beans[2]); assertTrue(beanList.poll() == beans[3]); assertFalse(window.isEmpty()); assertTrue(window.getOldestTimestamp() == 21); beanList = window.expireEvents(22); assertTrue(beanList.size() == 1); assertTrue(beanList.poll() == beans[4]); assertFalse(window.isEmpty()); assertTrue(window.getOldestTimestamp() == 22); beanList = window.expireEvents(23); assertTrue(beanList.size() == 1); assertTrue(beanList.poll() == beans[5]); assertTrue(window.isEmpty()); assertTrue(window.getOldestTimestamp() == null); beanList = window.expireEvents(23); assertTrue(beanList == null); assertTrue(window.isEmpty()); assertTrue(window.getOldestTimestamp() == null); }
From source file:com.espertech.esper.collection.TestTimeWindow.java
public void testAddRemove() { assertTrue(windowRemovable.getOldestTimestamp() == null); assertTrue(windowRemovable.isEmpty()); windowRemovable.add(19, beans[0]);//from ww w . j a v a 2 s . c om assertTrue(windowRemovable.getOldestTimestamp() == 19L); assertFalse(windowRemovable.isEmpty()); windowRemovable.add(19, beans[1]); assertTrue(windowRemovable.getOldestTimestamp() == 19L); windowRemovable.add(20, beans[2]); assertTrue(windowRemovable.getOldestTimestamp() == 19L); windowRemovable.add(20, beans[3]); windowRemovable.add(21, beans[4]); windowRemovable.add(22, beans[5]); assertTrue(windowRemovable.getOldestTimestamp() == 19L); windowRemovable.remove(beans[4]); windowRemovable.remove(beans[0]); windowRemovable.remove(beans[3]); ArrayDeque<EventBean> beanList = windowRemovable.expireEvents(19); assertTrue(beanList == null); beanList = windowRemovable.expireEvents(20); assertTrue(beanList.size() == 1); assertTrue(beanList.getFirst() == beans[1]); beanList = windowRemovable.expireEvents(21); assertTrue(beanList.size() == 1); assertTrue(beanList.getFirst() == beans[2]); assertFalse(windowRemovable.isEmpty()); assertTrue(windowRemovable.getOldestTimestamp() == 22); beanList = windowRemovable.expireEvents(22); assertTrue(beanList.size() == 0); beanList = windowRemovable.expireEvents(23); assertTrue(beanList.size() == 1); assertTrue(beanList.getFirst() == beans[5]); assertTrue(windowRemovable.isEmpty()); assertTrue(windowRemovable.getOldestTimestamp() == null); beanList = windowRemovable.expireEvents(23); assertTrue(beanList == null); assertTrue(windowRemovable.isEmpty()); assertTrue(windowRemovable.getOldestTimestamp() == null); assertEquals(0, windowRemovable.getReverseIndex().size()); }
From source file:com.rammelkast.anticheatreloaded.config.yaml.CommentedConfiguration.java
@Override public String saveToString() { yamlOptions.setIndent(options().indent()); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); // String header = buildHeader(); - CommentedConfiguration String dump = yaml.dump(getValues(false)); if (dump.equals(BLANK_CONFIG)) { dump = ""; }// w w w . ja v a2 s . com // Begin CommentedConfiguration StringBuilder builder = new StringBuilder(); String[] lines = dump.split("\n"); ArrayDeque<String> queue = new ArrayDeque<String>(); for (String string : lines) { queue.add(string); } int i = 0; while (queue.size() > 0) { if (comments.containsKey(i)) { builder.append(comments.get(i)); // Handle subsequent comments int b = i; while (true) { b++; if (comments.containsKey(b)) { builder.append('\n'); builder.append(comments.get(b)); } else { break; } } builder.append('\n'); i = b; } builder.append(queue.getFirst()); builder.append('\n'); queue.pop(); i++; } // End CommentedConfiguration return builder.toString(); }
From source file:com.espertech.esper.epl.property.PropertyEvaluatorNested.java
public EventBean[] getProperty(EventBean theEvent, ExprEvaluatorContext exprEvaluatorContext) { ArrayDeque<EventBean> resultEvents = new ArrayDeque<EventBean>(); eventsPerStream[0] = theEvent;// w ww .j a v a2s . c o m populateEvents(theEvent, 0, resultEvents, exprEvaluatorContext); if (resultEvents.isEmpty()) { return null; } return resultEvents.toArray(new EventBean[resultEvents.size()]); }
From source file:com.espertech.esper.view.window.TimeWindowView.java
/** * This method removes (expires) objects from the window and schedules a new callback for the * time when the next oldest message would expire from the window. *///from w ww . j a va 2 s .c o m protected final void expire() { long expireBeforeTimestamp = agentInstanceContext.getStatementContext().getSchedulingService().getTime() - millisecondsBeforeExpiry + 1; // Remove from the timeWindow any events that have an older or timestamp then the given timestamp // The window extends from X to (X - millisecondsBeforeExpiry + 1) ArrayDeque<EventBean> expired = timeWindow.expireEvents(expireBeforeTimestamp); // If there are child views, fireStatementStopped update method if (this.hasViews()) { if ((expired != null) && (!expired.isEmpty())) { EventBean[] oldEvents = expired.toArray(new EventBean[expired.size()]); if (viewUpdatedCollection != null) { viewUpdatedCollection.update(null, oldEvents); } updateChildren(null, oldEvents); } } scheduleExpiryCallback(); }
From source file:com.espertech.esper.core.start.EPPreparedExecuteSingleStream.java
/** * Executes the prepared query.//from www . ja va 2s.co m * @return query results */ public EPPreparedQueryResult execute(ContextPartitionSelector[] contextPartitionSelectors) { if (contextPartitionSelectors != null && contextPartitionSelectors.length != 1) { throw new IllegalArgumentException("Number of context partition selectors must be one"); } ContextPartitionSelector optionalSingleSelector = contextPartitionSelectors != null && contextPartitionSelectors.length > 0 ? contextPartitionSelectors[0] : null; // validate context if (processor.getContextName() != null && statementSpec.getOptionalContextName() != null && !processor.getContextName().equals(statementSpec.getOptionalContextName())) { throw new EPException("Context for named window is '" + processor.getContextName() + "' and query specifies context '" + statementSpec.getOptionalContextName() + "'"); } // handle non-specified context if (statementSpec.getOptionalContextName() == null) { NamedWindowProcessorInstance processorInstance = processor.getProcessorInstanceNoContext(); if (processorInstance != null) { EventBean[] rows = executor.execute(processorInstance); if (rows.length > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getNamedWindowType(), rows); } } // context partition runtime query Collection<Integer> agentInstanceIds = EPPreparedExecuteMethodHelper.getAgentInstanceIds(processor, optionalSingleSelector, services.getContextManagementService(), processor.getContextName()); // collect events and agent instances if (agentInstanceIds.isEmpty()) { return new EPPreparedQueryResult(processor.getNamedWindowType(), CollectionUtil.EVENT_PER_STREAM_EMPTY); } if (agentInstanceIds.size() == 1) { int agentInstanceId = agentInstanceIds.iterator().next(); NamedWindowProcessorInstance processorInstance = processor.getProcessorInstance(agentInstanceId); EventBean[] rows = executor.execute(processorInstance); if (rows.length > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getNamedWindowType(), rows); } ArrayDeque<EventBean> allRows = new ArrayDeque<EventBean>(); for (int agentInstanceId : agentInstanceIds) { NamedWindowProcessorInstance processorInstance = processor.getProcessorInstance(agentInstanceId); if (processorInstance != null) { EventBean[] rows = executor.execute(processorInstance); allRows.addAll(Arrays.asList(rows)); } } if (allRows.size() > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getNamedWindowType(), allRows.toArray(new EventBean[allRows.size()])); }