List of usage examples for java.util LinkedList isEmpty
boolean isEmpty();
From source file:com.evolveum.midpoint.test.ldap.OpenDJController.java
public Entry searchByEntryUuid(String entryUuid) throws DirectoryException { InternalSearchOperation op = getInternalConnection().processSearch("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, DereferencePolicy.NEVER_DEREF_ALIASES, 100, 100, false, "(entryUUID=" + entryUuid + ")", getSearchAttributes()); LinkedList<SearchResultEntry> searchEntries = op.getSearchEntries(); if (searchEntries == null || searchEntries.isEmpty()) { return null; }//from w w w . j a va 2 s. co m if (searchEntries.size() > 1) { AssertJUnit.fail("Multiple matches for Entry UUID " + entryUuid + ": " + searchEntries); } return searchEntries.get(0); }
From source file:com.ikanow.aleph2.analytics.spark.utils.SparkTechnologyUtils.java
/** Validate the job * @param new_analytic_bucket//from ww w. j ava 2 s . co m * @param jobs * @return */ public static BasicMessageBean validateJobs(final DataBucketBean new_analytic_bucket, final Collection<AnalyticThreadJobBean> jobs) { //TODO (ALEPH-63): validate batch enrichment final LinkedList<String> mutable_errs = new LinkedList<>(); jobs.stream().forEach(job -> { if (null == job.config()) { mutable_errs.push(ErrorUtils.get(SparkErrorUtils.MISSING_PARAM, new_analytic_bucket.full_name(), job.name(), "config")); } else { final SparkTopologyConfigBean config = BeanTemplateUtils .from(job.config(), SparkTopologyConfigBean.class).get(); if (SparkType.jvm == Optional.ofNullable(config.language()).orElse(SparkType.jvm)) { // JVM validation if (null == config.entry_point()) { mutable_errs.push(ErrorUtils.get(SparkErrorUtils.MISSING_PARAM, new_analytic_bucket.full_name(), job.name(), "config.entry_point")); } } else if (SparkType.python == Optional.ofNullable(config.language()).orElse(SparkType.jvm)) { // JVM validation if ((null == config.entry_point()) && (null == config.script())) { mutable_errs.push(ErrorUtils.get(SparkErrorUtils.MISSING_PARAM, new_analytic_bucket.full_name(), job.name(), "config.entry_point|config.script")); } } } }); return ErrorUtils.buildMessage(mutable_errs.isEmpty(), SparkTechnologyUtils.class, "validateJobs", mutable_errs.stream().collect(Collectors.joining(";"))); }
From source file:org.apache.openjpa.jdbc.sql.JoinSet.java
/** * Iterator over joins that prepares them for SQL translation. */// w w w. ja v a2s . c om public Iterator joinIterator() { if (_size < 2) return iterator(); if (_sorted != null) return _sorted.iterator(); List sorted = new ArrayList(_size); LinkedList queue = new LinkedList(); BitSet seen = new BitSet(_graph.size() * _graph.size() + _graph.size()); // traverse graph Node n; int idx, sidx; for (int i = 0; i < _graph.size(); i++) { // seed queue with next set of disconnected joins for (n = (Node) _graph.get(i); n != null; n = n.next) { sidx = getSeenIndex(n.join); if (!seen.get(sidx)) { seen.set(sidx); queue.add(n); } } if (queue.isEmpty()) continue; // traverse from those joins to reachables while (!queue.isEmpty()) { n = (Node) queue.removeFirst(); // don't repeat a join to a table we've already joined, but // do traverse through it in the graph (the first indexes of // the seeen bitset are reserved for joined-to tables) idx = (n.forward) ? n.join.getIndex2() : n.join.getIndex1(); if (!seen.get(idx)) { sorted.add((n.forward) ? n.join : n.join.reverse()); seen.set(idx); } for (n = (Node) _graph.get(idx); n != null; n = n.next) { sidx = getSeenIndex(n.join); if (!seen.get(sidx)) { seen.set(sidx); queue.add(n); } } } } _sorted = sorted; return _sorted.iterator(); }
From source file:org.fusesource.mop.MOP.java
private void listCommand(LinkedList<String> argList) throws Exception { String type = "installed"; if (!argList.isEmpty()) { type = argList.removeFirst();/*from ww w. j a v a 2 s.c o m*/ } this.artifactIds = parseArtifactList(argList); Set<ArtifactId> artifactIds = repository.list(type); for (ArtifactId a : artifactIds) { System.out.println(a); } }
From source file:com.xmobileapp.rockplayer.LastFmEventImporter.java
/********************************************** * /*from w w w . j av a 2 s. c o m*/ * insertListInListByDate * @param singleArtistEventList * **********************************************/ public void insertListInListByDate(LinkedList<ArtistEvent> singleArtistEventList) { /* * If this artist List is empty just return */ if (singleArtistEventList.isEmpty()) return; /* * If the big list is empty just add this one to it */ if (artistEventList.isEmpty()) { artistEventList.addAll(singleArtistEventList); return; } /* * Insert the items (normal case) */ ListIterator<ArtistEvent> artistEventListIterator = artistEventList.listIterator(0); ListIterator<ArtistEvent> singleArtistEventListIterator = singleArtistEventList.listIterator(0); ArtistEvent artistEvent; ArtistEvent singleArtistEvent; while (singleArtistEventListIterator.hasNext()) { /* * Not yet at the end of the big list */ if (artistEventListIterator.hasNext()) { singleArtistEvent = singleArtistEventListIterator.next(); artistEvent = artistEventListIterator.next(); while (singleArtistEvent.dateInMillis > artistEvent.dateInMillis) { if (artistEventListIterator.hasNext()) artistEvent = artistEventListIterator.next(); else { if (artistEventListIterator.previousIndex() >= MAX_EVENT_LIST_SIZE) { return; } else { break; // TODO: add missing items to the big list } } } artistEventListIterator.previous(); artistEventListIterator.add(singleArtistEvent); } /* * At the end of the big list (but not of the 'small' list */ else { if (artistEventListIterator.previousIndex() >= MAX_EVENT_LIST_SIZE) return; singleArtistEvent = singleArtistEventListIterator.next(); artistEventListIterator.add(singleArtistEvent); artistEventListIterator.next(); } } /* * Keep the list size in check */ while (artistEventList.size() > MAX_EVENT_LIST_SIZE) artistEventList.removeLast(); }
From source file:org.fusesource.mop.MOP.java
public void executeCommand(LinkedList<String> argList) throws Exception { resetValues();/*from ww w. ja v a 2s . c om*/ if (argList.isEmpty()) { throw new UsageException("No command specified."); } String command = argList.removeFirst(); if (command.equals("exec")) { execJava(argList); } else if (command.equals("execjar")) { execJarCommand(argList); } else if (command.equals("jar")) { jarCommand(argList); } else if (command.equals("run")) { runCommand(argList); } else if (command.equals("echo")) { echoCommand(argList); } else if (command.equals("classpath")) { classpathCommand(argList); } else if (command.equals("copy")) { copyCommand(argList); } else if (command.equals("war")) { warCommand(argList); } else if (command.equals("help")) { helpCommand(argList); } else if (command.equals("list")) { listCommand(argList); } else if (command.equals("uninstall")) { uninstallCommand(argList); } else { tryDiscoverCommand(command, argList); } }
From source file:com.mirth.connect.client.ui.components.MirthTree.java
/** * Construct a path for a specific node. * /* ww w . ja v a 2s . c o m*/ * @param parent * @param prefix * @param suffix * @return */ public static StringBuilder constructPath(TreeNode parent, String prefix, String suffix) { StringBuilder sb = new StringBuilder(); sb.insert(0, prefix); MirthTreeNode node = (MirthTreeNode) parent; SerializationType serializationType = node.getSerializationType(); // Get the parent if the leaf was actually passed in instead of the parent. if (node.isLeaf()) { node = (MirthTreeNode) node.getParent(); } /* * MIRTH-3196 - We now assign nodes types as we iterate from child to parent to add more * versatility to namespace drag and drop. The drag and drop can drag nodes, attribute or * namespace attributes so the user should be able to correctly do these now. If a node has * a namespace then will wildcard it. If an ancestor of the node has an implicit namespace * then we will also append a wildcard. The only exception to this is if the implicit * namespace is on the root node, we actually set this to the default namespace in * JavaScriptBuilder. */ LinkedList<PathNode> nodeQ = new LinkedList<PathNode>(); while (node != null && node.getParent() != null) { if (serializationType.equals(SerializationType.JSON) && node.isArrayElement()) { nodeQ.add(new PathNode(String.valueOf(node.getParent().getIndex(node) - 1), PathNode.NodeType.ARRAY_CHILD)); } else { PathNode.NodeType type = PathNode.NodeType.OTHER; if (serializationType.equals(SerializationType.XML)) { type = getXmlNodeType(node); } String nodeValue = node.getValue().replaceAll(" \\(.*\\)", ""); nodeQ.add(new PathNode(nodeValue, type)); if (serializationType.equals(SerializationType.XML)) { int parentIndexValue = getIndexOfNode(node); if (parentIndexValue != -1) { nodeQ.add(nodeQ.size() - 1, new PathNode(String.valueOf(parentIndexValue), PathNode.NodeType.ARRAY_CHILD)); } } } node = (MirthTreeNode) node.getParent(); } boolean foundImplicitNamespace = false; while (!nodeQ.isEmpty()) { PathNode nodeValue = nodeQ.removeLast(); //We start at the parent so if any implicit namespaces are reached then the rest of the nodes should wildcard the namespace boolean includeNamespace = false; PathNode.NodeType type = nodeValue.getType(); //We don't want to include a wildcard for attributes, ns definitions or array indices if (serializationType.equals(SerializationType.XML) && !Arrays .asList(PathNode.NodeType.XML_ATTRIBUTE, PathNode.NodeType.XMLNS_DEFINITION, PathNode.NodeType.XML_PREFIX_DEFINITION, PathNode.NodeType.ARRAY_CHILD) .contains(type)) { if (foundImplicitNamespace) { includeNamespace = true; } else if (type == PathNode.NodeType.XML_XMLNS_NODE) { foundImplicitNamespace = true; includeNamespace = true; } else if (type == PathNode.NodeType.XML_PREFIXED_NODE) { includeNamespace = true; } } if (includeNamespace) { int colonIndex = nodeValue.getValue().indexOf(':') + 1; sb.append(".*::['" + StringUtils.substring(nodeValue.getValue(), colonIndex) + "']"); } else if (serializationType.equals(SerializationType.XML) && type == PathNode.NodeType.XMLNS_DEFINITION) { sb.append(".namespace('')"); } else if (serializationType.equals(SerializationType.XML) && type == PathNode.NodeType.XML_PREFIX_DEFINITION) { sb.append(".namespace('" + StringUtils.substringAfter(nodeValue.getValue(), "@xmlns:") + "')"); } else if (type == PathNode.NodeType.XML_PREFIXED_ATTRIBUTE) { sb.append(".@*::['" + StringUtils.substringAfter(nodeValue.getValue(), ":") + "']"); } else if (type == PathNode.NodeType.ARRAY_CHILD) { sb.append("[" + nodeValue.getValue() + "]"); } else { sb.append("['" + nodeValue.getValue() + "']"); } } if (!serializationType.equals(SerializationType.JSON)) { sb.append(suffix); } return sb; }
From source file:org.gcaldaemon.core.notifier.GmailNotifier.java
public final void run() { log.info("Gmail notifier started successfully."); try {// w w w . j a v a 2 s . c o m sleep(7000); } catch (Exception ignored) { return; } // Processed (displayed) mails HashSet processedMails = new HashSet(); // Polling mailbox int i; for (;;) { try { // Verify local username if (users != null) { // List active users String[] activeUsers = getActiveUsers(); boolean enabled = false; if (activeUsers != null && activeUsers.length != 0) { for (i = 0; i < activeUsers.length; i++) { enabled = isUserMatch(activeUsers[i]); if (enabled) { break; } } if (!enabled) { // Sleep for a minute log.debug("Access denied for active local users."); sleep(MINUTE); // Restart loop (verify username) continue; } } } // Get Gmail address book (or null) GmailContact[] contacts = configurator.getAddressBook(); GmailContact contact; // Load feed entries SyndEntry[] entries = FeedUtilities.getFeedEntries(FEED_URL, username, password); SyndEntry entry; HashSet newMails = new HashSet(); for (i = 0; i < entries.length; i++) { entry = entries[i]; String date = getDate(entry); String from = getFrom(entry); if (contacts != null) { for (int n = 0; n < contacts.length; n++) { contact = contacts[n]; if (from.equalsIgnoreCase(contact.email)) { from = contact.name; break; } } } String title = getTitle(entry); if (mailtermSubject != null) { if (title.equals(mailtermSubject) || title.equals("Re:" + mailtermSubject)) { // Do not display mailterm commands and responses continue; } } String summary = getSummary(entry); newMails.add(date + '\t' + from + '\t' + title + '\t' + summary); } // Remove readed mails Iterator iterator = processedMails.iterator(); Object key; while (iterator.hasNext()) { key = iterator.next(); if (!newMails.contains(key)) { iterator.remove(); } } // Look up unprocessed mails LinkedList unprocessedMails = new LinkedList(); iterator = newMails.iterator(); while (iterator.hasNext()) { key = iterator.next(); if (processedMails.contains(key)) { continue; } processedMails.add(key); unprocessedMails.addLast(key); } // Display unprocessed mails if (!unprocessedMails.isEmpty()) { String[] array = new String[unprocessedMails.size()]; unprocessedMails.toArray(array); Arrays.sort(array, String.CASE_INSENSITIVE_ORDER); window.show(array); } // Sleep sleep(pollingTimeout); } catch (InterruptedException interrupt) { // Dispose window if (window != null) { try { window.setVisible(false); } catch (Exception ignored) { } } break; } catch (Exception loadError) { log.error("Unable to load Gmail feed!", loadError); try { sleep(HOUR); } catch (Exception interrupt) { return; } } } }
From source file:solidbase.core.UpgradeFile.java
/** * Retrieves all versions that are reachable from the given source version. The current version is also considered. * * @param source The source version.//from w w w.j a v a2 s . c om * @param targeting Already targeting a specific version. * @param downgradesAllowed Allow downgrades. * @param result This set gets filled with all versions that are reachable from the given source version. */ protected void collectReachableVersions(String source, String targeting, boolean downgradesAllowed, Set<String> result) { if (!this.versions.contains(source)) throw new FatalException("The current database version " + StringUtils.defaultString(source, "<no version>") + " is not available in the upgrade file. Maybe this version is deprecated or the wrong upgrade file is used."); if (targeting == null) result.add(source); // The source is reachable Collection<UpgradeSegment> segments = this.segments.get(source); // Get all segments with the given source if (segments == null) return; // Queue contains segments that await processing LinkedList<UpgradeSegment> queue = new LinkedList<UpgradeSegment>(); // Fill queue with segments if (targeting != null) { for (UpgradeSegment segment : segments) if (targeting.equals(segment.getTarget())) queue.add(segment); // Add segment to the end of the list if (queue.isEmpty()) throw new FatalException("The database is incompletely upgraded to version " + targeting + ", but that version is not reachable from version " + StringUtils.defaultString(source, "<no version>")); } else queue.addAll(segments); // Process the queue while (!queue.isEmpty()) { UpgradeSegment segment = queue.removeFirst(); // pop() is not available in java 5 if (!result.contains(segment.getTarget())) // Already there? if (downgradesAllowed || !segment.isDowngrade()) // Downgrades allowed? { result.add(segment.getTarget()); if (!segment.isOpen()) // Stop when segment is open. { segments = this.segments.get(segment.getTarget()); // Add the next to the queue if (segments != null) queue.addAll(segments); // Add segments to the end of the list } } } }
From source file:de.qspool.clementineremote.ui.fragments.PlaylistFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_playlist, container, false); mPlaylists = mPlaylistManager.getAllPlaylists(); mList = (ListView) view.findViewById(R.id.songs); mEmptyPlaylist = view.findViewById(R.id.playlist_empty); // Add Spinner to toolbar mPlaylistsSpinner = (Spinner) getActivity().findViewById(R.id.toolbar_spinner); mPlaylistsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*w w w .ja va 2 s .co m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { updateSongList(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); updatePlaylistSpinner(); // Create the adapter mAdapter = new PlaylistSongAdapter(getActivity(), R.layout.item_playlist, getSelectedPlaylistSongs()); mList.setOnItemClickListener(oiclSong); mList.setAdapter(mAdapter); mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mList.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override public boolean onActionItemClicked(ActionMode mode, android.view.MenuItem item) { SparseBooleanArray checkedPositions = mList.getCheckedItemPositions(); LinkedList<MySong> selectedSongs = new LinkedList<>(); for (int i = 0; i < checkedPositions.size(); ++i) { int position = checkedPositions.keyAt(i); if (checkedPositions.valueAt(i)) { selectedSongs.add(getSelectedPlaylistSongs().get(position)); } } if (!selectedSongs.isEmpty()) { switch (item.getItemId()) { case R.id.playlist_context_play: playSong(selectedSongs.get(0)); mode.finish(); return true; case R.id.playlist_context_download: LinkedList<String> urls = new LinkedList<>(); for (MySong s : selectedSongs) { urls.add(s.getUrl()); } if (!urls.isEmpty()) { DownloadManager.getInstance().addJob( ClementineMessageFactory.buildDownloadSongsMessage(DownloadItem.Urls, urls)); } mode.finish(); return true; case R.id.playlist_context_remove: Message msg = Message.obtain(); msg.obj = ClementineMessageFactory.buildRemoveMultipleSongsFromPlaylist(getPlaylistId(), selectedSongs); App.ClementineConnection.mHandler.sendMessage(msg); mode.finish(); return true; default: return false; } } return false; } @Override public boolean onCreateActionMode(ActionMode mode, android.view.Menu menu) { android.view.MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.playlist_context_menu, menu); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getActivity().getWindow() .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.grey_cab_status)); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, android.view.Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getActivity().getWindow() .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.actionbar_dark)); } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { } }); // Filter the results mAdapter.getFilter().filter(mFilterText); mActionBar.setTitle(""); mActionBar.setSubtitle(""); return view; }