List of usage examples for java.util HashSet iterator
public Iterator<E> iterator()
From source file:com.javadog.cgeowear.WearService.java
@Override public void onConnected(Bundle bundle) { Log.d(DEBUG_TAG, "Connected to Play Services"); //Subscribe to location updates LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, locationListener); //Get ID of connected Wear device and send it the initial cache info (in another thread) new Thread(new Runnable() { @Override/*from w ww . ja v a 2 s . c om*/ public void run() { HashSet<String> connectedWearDevices = new HashSet<String>(); NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(apiClient).await(); for (Node node : nodes.getNodes()) { connectedWearDevices.add(node.getId()); } Message m = new Message(); try { wearInterface = new WearInterface(apiClient, connectedWearDevices.iterator().next()); wearInterface.initTracking(cacheName, geocode, 0f, 0f, useWatchCompass, geocacheLocation); m.obj = MESSAGE_NAVIGATING_NOW; } catch (ConnectException e) { Log.e(DEBUG_TAG, "Couldn't send initial tracking data."); m.obj = MESSAGE_ERROR_COMMUNICATING; } catch (NoSuchElementException e) { Log.e(DEBUG_TAG, "No Wear devices connected. Killing service..."); m.obj = MESSAGE_NO_WEAR_DEVICE; } finally { initThreadHandler.sendMessage(m); } } }).start(); }
From source file:eionet.util.Util.java
/** * Finds all urls in a given string and replaces them with HTML anchors with target being a new window. * * @param in/*from ww w. j av a 2 s . c om*/ * - the text to scan in plain text. * @param newWindow * - whether to launch links in a new window. * @param cutLink * - can shorten the link text in the output HTML. * @return The modified text as HTML */ public static String processForLink(String in, boolean newWindow, int cutLink) { if (in == null || in.trim().length() == 0) { return in; } HashSet urlSchemes = new HashSet(); urlSchemes.add("http://"); urlSchemes.add("https://"); urlSchemes.add("ftp://"); urlSchemes.add("mailto://"); urlSchemes.add("ldap://"); urlSchemes.add("file://"); int beginIndex = -1; Iterator iter = urlSchemes.iterator(); while (iter.hasNext() && beginIndex < 0) { beginIndex = in.indexOf((String) iter.next()); } if (beginIndex < 0) { return in; } int endIndex = -1; String s = null; for (endIndex = in.length(); endIndex > beginIndex; endIndex--) { s = in.substring(beginIndex, endIndex); if (isURI(s)) { break; } } if (s == null) { return in; } HashSet endChars = new HashSet(); endChars.add(new Character('!')); endChars.add(new Character('\'')); endChars.add(new Character('(')); endChars.add(new Character(')')); endChars.add(new Character('.')); endChars.add(new Character(':')); endChars.add(new Character(';')); for (endIndex = endIndex - 1; endIndex > beginIndex; endIndex--) { char c = in.charAt(endIndex); if (!endChars.contains(new Character(c))) { break; } } StringBuffer buf = new StringBuffer(in.substring(0, beginIndex)); String link = in.substring(beginIndex, endIndex + 1); StringBuffer _buf = new StringBuffer("<a "); _buf.append("href=\""); _buf.append(link); _buf.append("\">"); if (cutLink < link.length()) { _buf.append(link.substring(0, cutLink)).append("..."); } else { _buf.append(link); } _buf.append("</a>"); buf.append(_buf.toString()); buf.append(in.substring(endIndex + 1)); return buf.toString(); }
From source file:com.mousefeed.eclipse.NagPopUp.java
/** * Handle link activation./* ww w . j a v a 2s . com*/ */ @SuppressWarnings({ "rawtypes", "unchecked" }) final void doLinkActivated() { Object data = null; final IWorkbench workbench = Activator.getDefault().getWorkbench(); final ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class); final Command command = commandService.getCommand(actionId); if (command != null) { final HashSet allParameterizedCommands = new HashSet(); try { allParameterizedCommands.addAll(ParameterizedCommand.generateCombinations(command)); } catch (final NotDefinedException e) { // It is safe to just ignore undefined commands. } if (!allParameterizedCommands.isEmpty()) { data = allParameterizedCommands.iterator().next(); // only commands can be bound to keyboard shortcuts openWorkspacePreferences(data); } } }
From source file:alma.acs.tmcdb.compare.TestHighLevelNodes.java
public void testMACI_Components() throws Exception { String[] xmlAllNodes = retrieveComponentsList(xmlAccess); String[] rdbAllNodes = retrieveComponentsList(rdbAccess); assertEquals(xmlAllNodes.length, rdbAllNodes.length); HashSet<String> xmlNodes = new HashSet<String>(Arrays.asList(xmlAllNodes)); HashSet<String> rdbNodes = new HashSet<String>(Arrays.asList(rdbAllNodes)); logger.info("XML: " + xmlNodes.toString() + ";\n TMCDB: " + rdbNodes.toString()); assertTrue(xmlNodes.equals(rdbNodes)); assertTrue(CollectionUtils.isEqualCollection(xmlNodes, rdbNodes)); for (Iterator<String> iterator = xmlNodes.iterator(); iterator.hasNext();) { String xmlstring = "MACI/Components/" + (String) iterator.next(); DAO xmlDao = xmlDAL.get_DAO_Servant(xmlstring); DAO rdbDao = rdbDAL.get_DAO_Servant(xmlstring); assertEquals(xmlDao.get_string("Code"), rdbDao.get_string("Code")); assertEquals(xmlDao.get_string("Type"), rdbDao.get_string("Type")); assertEquals(xmlDao.get_string("Container"), rdbDao.get_string("Container")); assertEquals(xmlDao.get_string("Default"), rdbDao.get_string("Default")); assertEquals(xmlDao.get_string("ImplLang"), rdbDao.get_string("ImplLang")); }//from w ww . ja va 2 s . c om }
From source file:org.apache.hama.ml.recommendation.cf.OnlineTrainBSP.java
private void askForFeatures(BSPPeer<Text, VectorWritable, Text, VectorWritable, MapWritable> peer, HashSet<Text> requiredUserFeatures, HashSet<Text> requiredItemFeatures) throws IOException, SyncException, InterruptedException { int peerCount = peer.getNumPeers(); int peerId = peer.getPeerIndex(); if (requiredUserFeatures != null) { Iterator<Text> iter = requiredUserFeatures.iterator(); Text key = null;/* w ww . j a v a 2 s . c o m*/ while (iter.hasNext()) { MapWritable msg = new MapWritable(); key = iter.next(); msg.put(OnlineCF.Settings.MSG_INP_USER_FEATURES, key); msg.put(OnlineCF.Settings.MSG_SENDER_ID, new IntWritable(peerId)); peer.send(peer.getPeerName(key.hashCode() % peerCount), msg); } } if (requiredItemFeatures != null) { Iterator<Text> iter = requiredItemFeatures.iterator(); Text key = null; while (iter.hasNext()) { MapWritable msg = new MapWritable(); key = iter.next(); msg.put(OnlineCF.Settings.MSG_INP_ITEM_FEATURES, key); msg.put(OnlineCF.Settings.MSG_SENDER_ID, new IntWritable(peerId)); peer.send(peer.getPeerName(key.hashCode() % peerCount), msg); } } }
From source file:org.springframework.yarn.batch.am.AbstractBatchAppmaster.java
/** * Adds the step splits.//from w ww . j a va 2 s .co m * * @param masterStepExecution the partitioned steps parent step execution * @param remoteStepName the remote step name * @param stepExecutions the step executions splits * @param resourceRequests the request data for step executions */ public void addStepSplits(StepExecution masterStepExecution, String remoteStepName, Set<StepExecution> stepExecutions, Map<StepExecution, ContainerRequestHint> resourceRequests) { // from request data we get hints where container should be run. // find a well distributed union of hosts. ContainerAllocateData containerAllocateData = new ContainerAllocateData(); int countNeeded = 0; HashSet<String> hostUnion = new HashSet<String>(); for (Entry<StepExecution, ContainerRequestHint> entry : resourceRequests.entrySet()) { StepExecution se = entry.getKey(); ContainerRequestHint crd = entry.getValue(); requestData.put(se, crd); remoteStepNames.put(se, remoteStepName); countNeeded++; for (String host : crd.getHosts()) { hostUnion.add(host); } } while (countNeeded > 0) { Iterator<String> iterator = hostUnion.iterator(); while (countNeeded > 0 && iterator.hasNext()) { String host = iterator.next(); containerAllocateData.addHosts(host, 1); countNeeded--; } } if (log.isDebugEnabled()) { log.debug("Adding " + stepExecutions.size() + " split steps into masterStepExecution=" + masterStepExecution); } // Create new set due to SHDP-188 HashSet<StepExecution> set = new HashSet<StepExecution>(stepExecutions.size()); set.addAll(stepExecutions); masterExecutions.put(masterStepExecution, set); int remaining = stepExecutions.size() - resourceRequests.size(); for (StepExecution execution : set) { if (!requestData.containsKey(execution)) { requestData.put(execution, null); } if (!remoteStepNames.containsKey(execution)) { remoteStepNames.put(execution, remoteStepName); } } getAllocator().allocateContainers(remaining); getAllocator().allocateContainers(containerAllocateData); }
From source file:alma.acs.tmcdb.compare.TestHighLevelNodes.java
public void testMACI_Managers() throws Exception { HashSet<String> xmlNodes = new HashSet<String>( Arrays.asList(xmlDAL.list_nodes("MACI/Managers").split(" "))); HashSet<String> rdbNodes = new HashSet<String>( Arrays.asList(rdbDAL.list_nodes("MACI/Managers").split(" "))); logger.info("XML: " + xmlNodes.toString() + "; TMCDB: " + rdbNodes.toString()); assertEquals(xmlNodes, rdbNodes);/*from w w w.ja v a2 s . co m*/ for (Iterator<String> iterator = xmlNodes.iterator(); iterator.hasNext();) { String xmlstring = "MACI/Managers/" + (String) iterator.next(); DAO xmlDao = xmlDAL.get_DAO_Servant(xmlstring); DAO rdbDao = rdbDAL.get_DAO_Servant(xmlstring); examineLoggingConfig(xmlDao, rdbDao); assertEquals(xmlDao.get_string("Startup"), rdbDao.get_string("Startup")); assertEquals(xmlDao.get_string("ServiceComponents"), rdbDao.get_string("ServiceComponents")); String sx = null; boolean xbool = true; try { sx = xmlDao.get_string("ServiceDaemons"); } catch (CDBFieldDoesNotExistEx e) { xbool = false; } String sr = null; try { sr = rdbDao.get_string("ServiceDaemons"); } catch (CDBFieldDoesNotExistEx e) { if (xbool) fail("Service Daemons: XML CDB has value: " + sx + " but TMCDB can't find the field."); continue; // Neither CDB can find it; move to next property } if (!xbool) fail("Service Daemons: TMCDB has value: " + sr + " but XML CDB can't find the field."); assertEquals(sx, sr); // TODO: Redo this once Matej's implementation is complete } }
From source file:org.apache.hadoop.yarn.server.nodemanager.util.CgroupsLCEResourcesHandlerGPU.java
private LinkedList<String> createCgroupDeviceEntry(HashSet<GPU> gpus, int numGPUsToAllocate) { LinkedList<String> cgroupDenyEntries = new LinkedList<>(); Iterator<GPU> itr = gpus.iterator(); while (itr.hasNext()) { GPU gpuDevice = itr.next();//from w w w .jav a 2 s . c o m cgroupDenyEntries.add("c " + gpuDevice.getGpuDevice() + " rwm\n"); if (gpuDevice.getRenderNode() != null) { cgroupDenyEntries.add("c " + gpuDevice.getRenderNode() + " rwm\n"); } } if (numGPUsToAllocate == 0) { for (Device driver : getGPUAllocator().getMandatoryDrivers()) { cgroupDenyEntries.add("c " + driver.toString() + " rwm\n"); } } return cgroupDenyEntries; }
From source file:org.hyperic.hq.events.ext.RegisteredTriggers.java
public Collection<RegisterableTriggerInterface> getInterestedTriggers(AbstractEvent event, Integer instanceId) { HashSet<RegisterableTriggerInterface> trigs = new HashSet<RegisterableTriggerInterface>(); // All alerts are disabled, so no triggers should be processing events if (!alertRegulator.alertsAllowed()) { return trigs; }//from ww w. j ava 2 s .c om TriggerEventKey key = new TriggerEventKey(event.getClass(), instanceId.intValue()); Map<Integer, RegisterableTriggerInterface> triggersById = triggers.get(key); if (triggersById != null) { trigs.addAll(triggersById.values()); } // Remove disabled triggers from new set so don't have to synchronize // retrieval around concurrent triggers map for (Iterator<RegisterableTriggerInterface> iterator = trigs.iterator(); iterator.hasNext();) { RegisterableTriggerInterface trigger = iterator.next(); if (!trigger.isEnabled()) { if (trigger instanceof ValueChangeTrigger) { if (event instanceof MeasurementEvent) { ((ValueChangeTrigger) trigger).setLast(((MeasurementEvent) event)); } } iterator.remove(); } } return trigs; }
From source file:GraphicsExample.java
void createTabList(Composite parent) { tabList = new Tree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); HashSet set = new HashSet(); for (int i = 0; i < tabs.length; i++) { GraphicsTab tab = tabs[i];// w w w . java 2 s . co m set.add(tab.getCategory()); } for (Iterator iter = set.iterator(); iter.hasNext();) { String text = (String) iter.next(); TreeItem item = new TreeItem(tabList, SWT.NONE); item.setText(text); } TreeItem[] items = tabList.getItems(); for (int i = 0; i < items.length; i++) { TreeItem item = items[i]; for (int j = 0; j < tabs.length; j++) { GraphicsTab tab = tabs[j]; if (item.getText().equals(tab.getCategory())) { TreeItem item1 = new TreeItem(item, SWT.NONE); item1.setText(tab.getText()); item1.setData(tab); } } } tabList.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { TreeItem item = (TreeItem) event.item; if (item != null) { setTab((GraphicsTab) item.getData()); } } }); }