List of usage examples for java.util ArrayDeque ArrayDeque
public ArrayDeque()
From source file:io.selendroid.server.model.internal.AbstractNativeElementContext.java
/** visible for testing */ protected static List<AndroidElement> searchViews(AbstractNativeElementContext context, List<View> roots, Predicate predicate, boolean findJustOne) { List<AndroidElement> elements = new ArrayList<AndroidElement>(); if (roots == null || roots.isEmpty()) { return elements; }//from w w w . j ava 2s.co m ArrayDeque<View> queue = new ArrayDeque<View>(); for (View root : roots) { queue.add(root); while (!queue.isEmpty()) { View view = queue.pop(); if (predicate.apply(view)) { elements.add(context.newAndroidElement(view)); if (findJustOne) { break; } } if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; int childrenCount = group.getChildCount(); for (int index = 0; index < childrenCount; index++) { queue.add(group.getChildAt(index)); } } } } return elements; }
From source file:com.espertech.esper.core.start.EPPreparedExecuteIUDSingleStream.java
/** * Executes the prepared query.//from www . j a va2 s . com * @return query results */ public EPPreparedQueryResult execute(ContextPartitionSelector[] contextPartitionSelectors) { try { 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) { FireAndForgetInstance processorInstance = processor.getProcessorInstanceNoContext(); if (processorInstance != null) { EventBean[] rows = executor.execute(processorInstance); if (rows != null && rows.length > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getEventTypePublic(), 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.getEventTypeResultSetProcessor(), CollectionUtil.EVENTBEANARRAY_EMPTY); } if (agentInstanceIds.size() == 1) { int agentInstanceId = agentInstanceIds.iterator().next(); FireAndForgetInstance processorInstance = processor .getProcessorInstanceContextById(agentInstanceId); EventBean[] rows = executor.execute(processorInstance); if (rows.length > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getEventTypeResultSetProcessor(), rows); } ArrayDeque<EventBean> allRows = new ArrayDeque<EventBean>(); for (int agentInstanceId : agentInstanceIds) { FireAndForgetInstance processorInstance = processor .getProcessorInstanceContextById(agentInstanceId); if (processorInstance != null) { EventBean[] rows = executor.execute(processorInstance); allRows.addAll(Arrays.asList(rows)); } } if (allRows.size() > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getEventTypeResultSetProcessor(), allRows.toArray(new EventBean[allRows.size()])); } finally { if (hasTableAccess) { services.getTableService().getTableExprEvaluatorContext().releaseAcquiredLocks(); } } }
From source file:brainflow.app.presentation.controls.FileObjectGroupSelector.java
private static String globToRegexPattern(final String glob) throws PatternSyntaxException { /* Stack to keep track of the parser mode: */ /* "--" : Base mode (first on the stack) */ /* "[]" : Square brackets mode "[...]" */ /* "{}" : Curly braces mode "{...}" */ final Deque<String> parserMode = new ArrayDeque<String>(); parserMode.push("--"); // base mode final int globLength = glob.length(); int index = 0; // index in glob /* equivalent REGEX expression to be compiled */ final StringBuilder t = new StringBuilder(); while (index < globLength) { char c = glob.charAt(index++); if (c == '\\') { /*********************** * (1) ESCAPE SEQUENCE */*from w w w .j a v a2s. c om*/ ***********************/ if (index == globLength) { /* no characters left, so treat '\' as literal char */ t.append(Pattern.quote("\\")); } else { /* read next character */ c = glob.charAt(index); final String s = c + ""; if (("--".equals(parserMode.peek()) && "\\[]{}?*".contains(s)) || ("[]".equals(parserMode.peek()) && "\\[]{}?*!-".contains(s)) || ("{}".equals(parserMode.peek()) && "\\[]{}?*,".contains(s))) { /* escape the construct char */ index++; t.append(Pattern.quote(s)); } else { /* treat '\' as literal char */ t.append(Pattern.quote("\\")); } } } else if (c == '*') { /************************ * (2) GLOB PATTERN '*' * ************************/ /* create non-capturing group to match zero or more characters */ t.append(".*"); } else if (c == '?') { /************************ * (3) GLOB PATTERN '?' * ************************/ /* create non-capturing group to match exactly one character */ t.append('.'); } else if (c == '[') { /**************************** * (4) GLOB PATTERN "[...]" * ****************************/ /* opening square bracket '[' */ /* create non-capturing group to match exactly one character */ /* inside the sequence */ t.append('['); parserMode.push("[]"); /* check for negation character '!' immediately after */ /* the opening bracket '[' */ if ((index < globLength) && (glob.charAt(index) == '!')) { index++; t.append('^'); } } else if ((c == ']') && "[]".equals(parserMode.peek())) { /* closing square bracket ']' */ t.append(']'); parserMode.pop(); } else if ((c == '-') && "[]".equals(parserMode.peek())) { /* character range '-' in "[...]" */ t.append('-'); } else if (c == '{') { /**************************** * (5) GLOB PATTERN "{...}" * ****************************/ /* opening curly brace '{' */ /* create non-capturing group to match one of the */ /* strings inside the sequence */ t.append("(?:(?:"); parserMode.push("{}"); } else if ((c == '}') && "{}".equals(parserMode.peek())) { /* closing curly brace '}' */ t.append("))"); parserMode.pop(); } else if ((c == ',') && "{}".equals(parserMode.peek())) { /* comma between strings in "{...}" */ t.append(")|(?:"); } else { /************************* * (6) LITERAL CHARACTER * *************************/ /* convert literal character to a regex string */ t.append(Pattern.quote(c + "")); } } /* done parsing all chars of the source pattern string */ /* check for mismatched [...] or {...} */ if ("[]".equals(parserMode.peek())) throw new PatternSyntaxException("Cannot find matching closing square bracket ] in GLOB expression", glob, -1); if ("{}".equals(parserMode.peek())) throw new PatternSyntaxException("Cannot find matching closing curly brace } in GLOB expression", glob, -1); return t.toString(); }
From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java
/** * Creates an instance of a TabPersistentStore. * @param modelSelector The {@link TabModelSelector} to restore to and save from. * @param tabCreatorManager The {@link TabCreatorManager} to use. * @param observer Notified when the TabPersistentStore has completed tasks. * @param mergeTabs Whether tabs from a second TabModelSelector should be merged into * into this instance. *///w w w .ja v a 2 s. c o m public TabPersistentStore(TabPersistencePolicy policy, TabModelSelector modelSelector, TabCreatorManager tabCreatorManager, TabPersistentStoreObserver observer, final boolean mergeTabs) { mPersistencePolicy = policy; mTabModelSelector = modelSelector; mTabCreatorManager = tabCreatorManager; mTabsToSave = new ArrayDeque<>(); mTabsToRestore = new ArrayDeque<>(); mTabIdsToRestore = new HashSet<>(); mObserver = observer; mPreferences = ContextUtils.getAppSharedPreferences(); assert isStateFile(policy.getStateFileName()) : "State file name is not valid"; boolean needsInitialization = mPersistencePolicy.performInitialization(AsyncTask.SERIAL_EXECUTOR); if (mPersistencePolicy.isMergeInProgress()) return; Executor executor = needsInitialization ? AsyncTask.SERIAL_EXECUTOR : AsyncTask.THREAD_POOL_EXECUTOR; mPrefetchTabListTask = startFetchTabListTask(executor, mPersistencePolicy.getStateFileName()); startPrefetchActiveTabTask(executor); if (mergeTabs) { assert mPersistencePolicy.getStateToBeMergedFileName() != null; mPrefetchTabListToMergeTask = startFetchTabListTask(executor, mPersistencePolicy.getStateToBeMergedFileName()); } }
From source file:org.xwiki.xdomviz.Main.java
/** * <p>//from ww w.jav a 2 s.co m * This method produces the GraphViz source code corresponding to the node tree. * </p> * * @param root The node tree root. * @return A string containing the GraphViz source code to display the node tree. */ private static String generateGraphViz(Node root) { // The rendering buffer. StringBuffer sb = new StringBuffer(); // This map contains the GraphViz Ids (integers) associated to the nodes in the tree. Map<Node, Integer> nodeToIdMap = new HashMap<Node, Integer>(); sb.append("digraph XDOM {\n"); // Breadth first visit of the XDOM to assign simple ids to nodes. Queue<Node> nodesQueue = new ArrayDeque<Node>(); nodesQueue.add(root); // Counter used to keep track of the assigned ids. It's incremented at each time a new node is found for the // first time. int i = 0; while (!nodesQueue.isEmpty()) { Node node = nodesQueue.poll(); if (nodeToIdMap.get(node) == null) { nodeToIdMap.put(node, i); i++; } for (Node child : node.getChildren()) { if (nodeToIdMap.get(child) == null) { nodeToIdMap.put(child, i); i++; } nodesQueue.add(child); // Render the edge. sb.append(String.format("%d -> %d;\n", nodeToIdMap.get(node), nodeToIdMap.get(child))); } } // Render the label assignment. for (Node node : nodeToIdMap.keySet()) { sb.append(String.format("%d [label = \"%s\"];\n", nodeToIdMap.get(node), node)); } sb.append("}\n"); return sb.toString(); }
From source file:org.chromium.chrome.browser.media.router.cast.CastMessageHandler.java
@VisibleForTesting void handleStopMessage(String clientId, int sequenceNumber) { Queue<Integer> sequenceNumbersForClient = mStopRequests.get(clientId); if (sequenceNumbersForClient == null) { sequenceNumbersForClient = new ArrayDeque<Integer>(); mStopRequests.put(clientId, sequenceNumbersForClient); }// www .j a v a 2s . c om sequenceNumbersForClient.add(sequenceNumber); mSession.stopApplication(); }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Collection<EventBean> normalizeCollection(SortedMap<Object, Set<EventBean>> submap) { if (submap.size() == 0) { return null; }//from w w w.j av a 2 s . co m if (submap.size() == 1) { return submap.get(submap.firstKey()); } Deque<EventBean> result = new ArrayDeque<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submap.entrySet()) { result.addAll(entry.getValue()); } return result; }
From source file:com.yangtsaosoftware.pebblemessenger.services.PebbleCenter.java
@Override public void onCreate() { super.onCreate(); Handler pebbleCenterHandler = new PebbleCenterHandler(); mPebbleCenterHandler = new Messenger(pebbleCenterHandler); Constants.log(TAG_NAME, "Create PebbleCenter Messenger."); loadPref();/*from ww w . j av a2s . co m*/ _contex = this; // busyBegin=new Time(); // waitQueue=new ArrayDeque<PebbleMessage>(); sendQueue = new ArrayDeque<PebbleDictionary>(); bindService(new Intent(this, MessageProcessingService.class), connToMessageProcessing, Context.BIND_AUTO_CREATE); Thread prepareThread = new PrepareThread(); prepareThread.start(); Thread sendMsgThread = new SendMsgThread(); sendMsgThread.start(); isPebbleEnable = PebbleKit.isWatchConnected(_contex); PebbleKit.registerReceivedDataHandler(_contex, new PebbleKit.PebbleDataReceiver(Constants.PEBBLE_UUID) { @Override public void receiveData(Context context, int transactionId, PebbleDictionary data) { PebbleKit.sendAckToPebble(_contex, transactionId); // appStatue++; Constants.log(TAG_NAME, "Received data form pebble"); switch (data.getUnsignedIntegerAsLong(ID_COMMAND).intValue()) { case REQUEST_TRANSID_CALL_TABLE: { Constants.log(TAG_NAME, "Request call table."); clean_SendQue(); Message msg = Message.obtain(); msg.what = MessageProcessingService.MSG_GET_CALL_TABLE; try { rMessageProcessingHandler.send(msg); } catch (RemoteException e) { e.printStackTrace(); } } break; case REQUEST_TRANSID_MESSAGE_TABLE: { Constants.log(TAG_NAME, "Request message table."); clean_SendQue(); Message msg = Message.obtain(); msg.what = MessageProcessingService.MSG_GET_MESSAGE_TABLE; try { rMessageProcessingHandler.send(msg); } catch (RemoteException e) { e.printStackTrace(); } } break; case REQUEST_TRANSID_CALL: { clean_SendQue(); Message msg = Message.obtain(); msg.what = MessageProcessingService.MSG_GET_CALL; Bundle b = new Bundle(); b.putString(MessageDbHandler.COL_CALL_ID, data.getString(ID_EXTRA_DATA)); Constants.log(TAG_NAME, "Request call id:" + data.getString(ID_EXTRA_DATA)); msg.setData(b); try { rMessageProcessingHandler.send(msg); } catch (RemoteException e) { e.printStackTrace(); } } break; case REQUEST_TRANSID_MESSAGE: clean_SendQue(); Message msg = Message.obtain(); msg.what = MessageProcessingService.MSG_GET_MESSAGE; Bundle b = new Bundle(); b.putString(MessageDbHandler.COL_MESSAGE_ID, data.getString(ID_EXTRA_DATA)); Constants.log(TAG_NAME, "Request message id:" + data.getString(ID_EXTRA_DATA)); msg.setData(b); try { rMessageProcessingHandler.send(msg); } catch (RemoteException e) { e.printStackTrace(); } break; case REQUEST_TRANSID_PICKUP_PHONE: TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Constants.log("Receivephone", "Receive phone:" + data.getString(ID_EXTRA_DATA2)); if (telMag.getCallState() == TelephonyManager.CALL_STATE_RINGING) { switch (data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).intValue()) { case REQUEST_EXTRA_SPEAKER_ON: answerCall(true); break; case REQUEST_EXTRA_SPEAKER_OFF: answerCall(false); break; } } else { switch (data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).intValue()) { case REQUEST_EXTRA_SPEAKER_ON: dialNumber(data.getString(ID_EXTRA_DATA2), true); break; case REQUEST_EXTRA_SPEAKER_OFF: dialNumber(data.getString(ID_EXTRA_DATA2), false); break; } } // pebbleBusy = false; break; case REQUEST_TRANSID_HANGOFF_PHONE: endCall(); // pebbleBusy=false; break; case REQUEST_TRANSID_HANGOFF_SMS1: Constants.log(TAG_NAME, "Request hangoff and send sms1"); endCall(); doSendSMSTo(data.getString(ID_EXTRA_DATA), sms1); // pebbleBusy=false; break; case REQUEST_TRANSID_HANGOFF_SMS2: Constants.log(TAG_NAME, "Request hangoff and send sms2"); endCall(); doSendSMSTo(data.getString(ID_EXTRA_DATA), sms2); // pebbleBusy=false; break; case REQUEST_TRANSID_CLOSE_APP: Constants.log(TAG_NAME, "Request close app command."); sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP); // need_delay=true; break; case REQUEST_TRANSID_NEXTPAGE: Constants.log(TAG_NAME, "Request send next page."); sendMsgThreadHandler.sendEmptyMessage(SEND_NEXT_PAGE); break; case REQUEST_TRANSID_READ_NOTIFY: { Constants.log(TAG_NAME, "Request read msg"); Message read_msg = Message.obtain(); read_msg.what = MessageProcessingService.MSG_READ; Bundle bd = new Bundle(); bd.putString(MessageDbHandler.COL_MESSAGE_ID, data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).toString()); read_msg.setData(bd); try { rMessageProcessingHandler.send(read_msg); } catch (RemoteException e) { e.printStackTrace(); } } break; case REQUEST_TRANSID_IM_FREE: Constants.log(TAG_NAME, "Request pebble app is free to receive data."); // need_delay = data.getUnsignedInteger(ID_EXTRA_DATA).intValue() == REQUEST_EXTRA_DELAY_ON ; // clean_SendQue(); break; case REQUEST_TRANSID_VERSION: { send_test_get_return = true; String result = data.getString(ID_EXTRA_DATA); Constants.log("PmpVersion", result); StringTokenizer tokens = new StringTokenizer(result, "."); Intent inner_intent = new Intent(SetupFragment.class.getName()); inner_intent.putExtra(Constants.BROADCAST_VERSION, new byte[] { Byte.parseByte(tokens.nextToken()), Byte.parseByte(tokens.nextToken()), Byte.parseByte(tokens.nextToken()) }); LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent); sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP); break; } } } }); PebbleKit.registerReceivedAckHandler(_contex, new PebbleKit.PebbleAckReceiver(Constants.PEBBLE_UUID) { @Override public void receiveAck(Context context, int transactionId) { Constants.log(TAG_NAME, "Get a receiveAck:" + String.valueOf(transactionId)); switch (transactionId) { case TRANS_ID_COMMON: Constants.log(TAG_NAME, "Send continue..."); // pebbleBusy=true; sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE); break; case TRANS_ID_END: send_full_page = true; break; case TRANS_ID_EMPTY: // pebbleBusy=true; sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE); break; case TRANS_ID_TEST: { break; } } } }); PebbleKit.registerReceivedNackHandler(_contex, new PebbleKit.PebbleNackReceiver(Constants.PEBBLE_UUID) { @Override public void receiveNack(Context context, int transactionId) { Constants.log(TAG_NAME, "Get a receivedNack:" + String.valueOf(transactionId)); if (PebbleKit.isWatchConnected(_contex)) { switch (transactionId) { case TRANS_ID_COMMON: sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE); break; case TRANS_ID_END: send_full_page = true; break; case TRANS_ID_EMPTY: // appStatue=0; sendMsgThreadHandler.sendEmptyMessage(SEND_OPEN_APP); break; case TRANS_ID_TEST: { Intent inner_intent = new Intent(SetupFragment.class.getName()); inner_intent.putExtra(Constants.BROADCAST_VERSION, new byte[] { 0, 0, 0 }); LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent); } } } else { sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP); } } }); PebbleKit.registerPebbleConnectedReceiver(_contex, new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { isPebbleEnable = true; } }); PebbleKit.registerPebbleDisconnectedReceiver(_contex, new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { isPebbleEnable = false; sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP); } }); BroadcastReceiver br = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int command = intent.getIntExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_PREFER_CHANGED); switch (command) { case Constants.BROADCAST_PREFER_CHANGED: loadPref(); break; case Constants.BROADCAST_CALL_IDLE: if (callEnable) { sendMsgThreadHandler.sendEmptyMessage(SEND_CALL_END); } break; case Constants.BROADCAST_CALL_HOOK: if (callEnable) { sendMsgThreadHandler.sendEmptyMessage(SEND_CALL_HOOK); } break; case Constants.BROADCAST_PEBBLE_TEST: if (isPebbleEnable) { prepareThreadHandler.sendEmptyMessage(PREPARE_TEST); } break; } } }; IntentFilter intentFilter = new IntentFilter(PebbleCenter.class.getName()); LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(br, intentFilter); }
From source file:com.grepcurl.random.ObjectGenerator.java
protected Object _process(Type type, SetterOverrides setterOverrides) { return _process(type, setterOverrides, new ArrayDeque<>()); }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Collection<EventBean> normalizeCollection(SortedMap<Object, Set<EventBean>> submapOne, SortedMap<Object, Set<EventBean>> submapTwo) { if (submapOne.size() == 0) { return normalizeCollection(submapTwo); }/* w w w .j a va 2 s . c o m*/ if (submapTwo.size() == 0) { return normalizeCollection(submapOne); } ArrayDeque<EventBean> result = new ArrayDeque<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submapOne.entrySet()) { result.addAll(entry.getValue()); } for (Map.Entry<Object, Set<EventBean>> entry : submapTwo.entrySet()) { result.addAll(entry.getValue()); } return result; }