List of usage examples for java.util LinkedList addLast
public void addLast(E e)
From source file:edu.cmu.tetrad.search.SearchGraphUtils.java
public static Graph bestGuessCycleOrientation(Graph graph, IndependenceTest test) { while (true) { List<Node> cycle = GraphUtils.directedCycle(graph); if (cycle == null) { break; }//from www .j a va 2s . c om LinkedList<Node> _cycle = new LinkedList<Node>(cycle); Node first = _cycle.getFirst(); Node last = _cycle.getLast(); _cycle.addFirst(last); _cycle.addLast(first); int _j = -1; double minP = Double.POSITIVE_INFINITY; for (int j = 1; j < _cycle.size() - 1; j++) { int i = j - 1; int k = j + 1; Node x = test.getVariable(_cycle.get(i).getName()); Node y = test.getVariable(_cycle.get(j).getName()); Node z = test.getVariable(_cycle.get(k).getName()); test.isIndependent(x, z, Collections.singletonList(y)); double p = test.getPValue(); if (p < minP) { _j = j; minP = p; } } Node x = _cycle.get(_j - 1); Node y = _cycle.get(_j); Node z = _cycle.get(_j + 1); graph.removeEdge(x, y); graph.removeEdge(z, y); graph.addDirectedEdge(x, y); graph.addDirectedEdge(z, y); } return graph; }
From source file:org.guzz.builder.GuzzConfigFileBuilder.java
public List listGlobalORMs() throws IOException, ClassNotFoundException { List ls = this.rootDoc.selectNodes("orm"); LinkedList list = new LinkedList(); if (ls.isEmpty()) return list; for (int i = 0; i < ls.size(); i++) { Element e = (Element) ls.get(i); ResultMapBasedObjectMapping map = loadORM(gf, null, e); list.addLast(map); }/*from w w w. j a v a2s. c o m*/ return list; }
From source file:com.jaspersoft.jasperserver.api.common.service.impl.JdbcDriverServiceImpl.java
private List<ClassLoader> getAvailableClassLoaders(String driverClass) { LinkedList<ClassLoader> classLoaders = new LinkedList<ClassLoader>(); ClassLoader repositoryClassLoader = getClassLoaderByClassName(driverClass); if (repositoryClassLoader != null) { classLoaders.add(repositoryClassLoader); }//from ww w .j a v a 2 s . co m //Adding system classloader to the start of to the end of list if (systemClassLoaderFirst) { classLoaders.addFirst(getSystemClassLoader()); } else { classLoaders.addLast(getSystemClassLoader()); } return classLoaders; }
From source file:org.openconcerto.sql.model.SQLTable.java
static private void fireTableModified(DispatchingState newTuple) { final LinkedList<DispatchingState> linkedList = events.get(); // add new event linkedList.addLast(newTuple); // process all pending events DispatchingState currentTuple;//from w w w.j a v a 2s. c o m while ((currentTuple = linkedList.peekFirst()) != null) { final Iterator<SQLTableModifiedListener> iter = currentTuple.get0(); final SQLTableEvent currentEvt = currentTuple.get1(); while (iter.hasNext()) { final SQLTableModifiedListener l = iter.next(); l.tableModified(currentEvt); } // not removeFirst() since the item might have been already removed linkedList.pollFirst(); } }
From source file:net.timewalker.ffmq4.storage.data.impl.journal.BlockBasedDataStoreJournal.java
private void recycleUnusedJournalFiles() throws JournalException { LinkedList<JournalFile> unusedJournalFiles = null; // Look for unused journal files synchronized (journalFiles) { while (journalFiles.size() > 0) { JournalFile journalFile = journalFiles.getFirst(); if (journalFile.isComplete() && journalFile.getLastTransactionId() < lastStoreTransactionId) { if (unusedJournalFiles == null) unusedJournalFiles = new LinkedList<>(); unusedJournalFiles.addLast(journalFile); journalFiles.removeFirst(); // Remove from list } else break; }/*w ww . ja v a 2s. c o m*/ } // Recycle unused journal files if (unusedJournalFiles != null) { while (!unusedJournalFiles.isEmpty()) { JournalFile journalFile = unusedJournalFiles.removeFirst(); if (keepJournalFiles) journalFile.close(); else { log.debug("[" + baseName + "] Recycling unused journal file : " + journalFile); File recycledFile = journalFile.closeAndRecycle(); synchronized (recycledJournalFiles) { recycledJournalFiles.addLast(recycledFile); } } } } }
From source file:org.gldapdaemon.core.ldap.LDAPListener.java
private final ByteBuffer processRequest(LdapMessage request, boolean utf8) throws Exception { if (log.isDebugEnabled()) { try {//from w w w . j a v a 2 s . c o m String command = request.getMessageTypeName(); if (command != null) { command = command.toLowerCase().replace('_', ' '); } log.debug("Processing " + command + "..."); } catch (Exception ignored) { log.warn("Processing unknown LDAP request..."); } } LinkedList list = new LinkedList(); switch (request.getMessageType()) { case LdapConstants.BIND_REQUEST: // Bind response BindResponse bind = new BindResponse(); bind.setMessageId(request.getMessageId()); LdapResult result = new LdapResult(); result.setResultCode(0); bind.setLdapResult(result); list.addLast(bind); break; case LdapConstants.UNBIND_REQUEST: // Unbind response LdapResponse unbind = new LdapResponse(); unbind.setMessageId(request.getMessageId()); result = new LdapResult(); result.setResultCode(0); unbind.setLdapResult(result); list.addLast(unbind); break; case LdapConstants.SEARCH_REQUEST: // Switch back encoding if (nativeCharsetLocked) { utf8 = false; } // Get search string SearchRequest search = request.getSearchRequest(); Filter filter = search.getTerminalFilter(); String key = null; if (filter == null) { filter = search.getFilter(); if (filter == null) { filter = search.getCurrentFilter(); } } if (filter != null) { if (filter instanceof SubstringFilter) { SubstringFilter substringFilter = (SubstringFilter) filter; ArrayList substrings = substringFilter.getAnySubstrings(); if (substrings != null && substrings.size() != 0) { key = (String) substrings.get(0); } } if (key == null) { key = filter.toString(); if (key != null) { if (key.charAt(0) == '*') { key = key.substring(1); } if (key.charAt(key.length() - 1) == '*') { key = key.substring(0, key.length() - 1); } if (key.indexOf('=') != -1) { key = key.substring(key.indexOf('=') + 1); } } } if (key != null) { if (key.length() == 0) { key = null; } else { // Decode UTF8 chars try { byte[] bytes = key.getBytes(PLATFORM_ENCODING); key = StringUtils.decodeToString(bytes, StringUtils.UTF_8); if (utf8) { bytes = key.getBytes(PLATFORM_ENCODING); key = StringUtils.decodeToString(bytes, StringUtils.UTF_8); } } catch (Exception ignored) { } if (log.isDebugEnabled()) { log.debug("LDAP search filter (" + key + ") received."); } key = key.toLowerCase(); // All contacts requested if (key.equals("@")) { key = null; } } } } // Handle native charset lock if (key != null && !utf8) { nativeCharsetLocked = true; } // Find entry ArrayList<GmailContact> contacts = loader.getContacts(); if (contacts != null) { GmailContact contact; for (int n = 0; n < contacts.size(); n++) { contact = contacts.get(n); String value = null; if (contact.name.toLowerCase().indexOf(key) >= 0 || contact.company.toLowerCase().indexOf(key) >= 0) { value = contact.name.length() > 0 ? contact.name : contact.company; } else if (key != null) { continue; } // Add search entry SearchResultEntry entry = new SearchResultEntry(); entry.setMessageId(request.getMessageId()); LdapDN name; try { name = new LdapDN("CN=" + encode(value, utf8)); } catch (Exception badDN) { log.debug(badDN); continue; } entry.setObjectName(name); BasicAttributes partialAttributeList = new BasicAttributes(true); partialAttributeList.put(new BasicAttribute("cn", encode(value, utf8))); if (contact.email.length() != 0) { // first email partialAttributeList.put(new BasicAttribute("mail", encode(contact.email, utf8))); } if (contact.notes.length() != 0) { // notes partialAttributeList.put(new BasicAttribute("comment", encode(contact.notes, utf8))); partialAttributeList.put(new BasicAttribute("description", encode(contact.notes, utf8))); } String mobile = contact.mobile; if (mobile.length() == 0) { mobile = contact.phone; } if (mobile.length() != 0) { // mobile phone partialAttributeList.put(new BasicAttribute("telephonenumber", encode(mobile, utf8))); } if (contact.phone.length() != 0) { // homePhone partialAttributeList.put(new BasicAttribute("homePhone", encode(contact.phone, utf8))); } if (contact.mail.length() != 0) { // second email partialAttributeList .put(new BasicAttribute("mozillaSecondEmail", encode(contact.mail, utf8))); partialAttributeList .put(new BasicAttribute("mailAlternateAddress", encode(contact.mail, utf8))); } if (contact.address.length() != 0) { // postal address partialAttributeList .put(new BasicAttribute("postalAddress", encode(contact.address, utf8))); partialAttributeList .put(new BasicAttribute("homePostalAddress", encode(contact.address, utf8))); partialAttributeList.put(new BasicAttribute("homeStreet", encode(contact.address, utf8))); } if (contact.pager.length() != 0) { // pager partialAttributeList.put(new BasicAttribute("pager", encode(contact.pager, utf8))); } if (contact.fax.length() != 0) { // fax partialAttributeList .put(new BasicAttribute("facsimileTelephoneNumber", encode(contact.fax, utf8))); if (contact.pager.length() == 0) { partialAttributeList.put(new BasicAttribute("pager", encode(contact.fax, utf8))); } } if (contact.title.length() != 0) { // title partialAttributeList.put(new BasicAttribute("title", encode(contact.title, utf8))); } if (contact.company.length() != 0) { // company partialAttributeList.put(new BasicAttribute("company", encode(contact.company, utf8))); partialAttributeList.put(new BasicAttribute("o", encode(contact.company, utf8))); } entry.setPartialAttributeList(partialAttributeList); list.addLast(entry); } } // Search done if (log.isDebugEnabled()) { log.debug("Found " + list.size() + " contacts."); } SearchResultDone done = new SearchResultDone(); done.setMessageId(request.getMessageId()); result = new LdapResult(); result.setResultCode(0); done.setLdapResult(result); list.addLast(done); break; case LdapConstants.ABANDON_REQUEST: // Abandon command result = new LdapResult(); result.setResultCode(0); LdapResponse response = new LdapResponse(); response.setLdapResult(result); list.addLast(response); break; default: // Unsupported command log.debug("Unsupported LDAP command!"); result = new LdapResult(); result.setErrorMessage("Unsupported LDAP command!"); response = new LdapResponse(); response.setLdapResult(result); list.addLast(response); } log.debug("LDAP request processed."); if (!list.isEmpty()) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Iterator responses = list.iterator(); while (responses.hasNext()) { LdapMessage response = (LdapMessage) responses.next(); response.setMessageId(request.getMessageId()); // Append LDAP response LdapMessage message = new LdapMessage(); message.setProtocolOP(response); message.setMessageId(request.getMessageId()); ByteBuffer bb = message.encode(null); byte[] a = bb.array(); out.write(a); } byte[] bytes = out.toByteArray(); return ByteBuffer.wrap(bytes); } return null; }
From source file:com.stimulus.archiva.domain.Volumes.java
public synchronized void setVolumePriority(int id, Priority priority) { LinkedList<Volume> list = volumes; Volume v = list.get(id);/*from w w w . java2 s . c o m*/ if (v.getStatus() != Volume.Status.UNUSED) // can only reorder unused return; if (priority == Priority.PRIORITY_HIGHER && id - 1 >= 0) { // cannot affect non unused vols Volume vs = list.get(id - 1); if (vs.getStatus() != Volume.Status.UNUSED) return; } list.remove(v); switch (priority) { case PRIORITY_HIGHER: if ((id - 1) <= 0) list.addFirst(v); else list.add(id - 1, v); break; case PRIORITY_LOWER: if ((id + 1) >= list.size()) list.addLast(v); else list.add(id + 1, v); break; } }
From source file:org.gcaldaemon.core.ldap.LDAPListener.java
private final ByteBuffer processRequest(LdapMessage request, boolean utf8) throws Exception { if (log.isDebugEnabled()) { try {/*from w w w. ja va2s.co m*/ String command = request.getMessageTypeName(); if (command != null) { command = command.toLowerCase().replace('_', ' '); } log.debug("Processing " + command + "..."); } catch (Exception ignored) { log.warn("Processing unknown LDAP request..."); } } LinkedList list = new LinkedList(); switch (request.getMessageType()) { case LdapConstants.BIND_REQUEST: // Bind response BindResponse bind = new BindResponse(); bind.setMessageId(request.getMessageId()); LdapResult result = new LdapResult(); result.setResultCode(0); bind.setLdapResult(result); list.addLast(bind); break; case LdapConstants.UNBIND_REQUEST: // Unbind response LdapResponse unbind = new LdapResponse(); unbind.setMessageId(request.getMessageId()); result = new LdapResult(); result.setResultCode(0); unbind.setLdapResult(result); list.addLast(unbind); break; case LdapConstants.SEARCH_REQUEST: // Switch back encoding if (nativeCharsetLocked) { utf8 = false; } // Get search string SearchRequest search = request.getSearchRequest(); Filter filter = search.getTerminalFilter(); String key = null; if (filter == null) { filter = search.getFilter(); if (filter == null) { filter = search.getCurrentFilter(); } } if (filter != null) { if (filter instanceof SubstringFilter) { SubstringFilter substringFilter = (SubstringFilter) filter; ArrayList substrings = substringFilter.getAnySubstrings(); if (substrings != null && substrings.size() != 0) { key = (String) substrings.get(0); } } if (key == null) { key = filter.toString(); if (key != null) { if (key.charAt(0) == '*') { key = key.substring(1); } if (key.charAt(key.length() - 1) == '*') { key = key.substring(0, key.length() - 1); } if (key.indexOf('=') != -1) { key = key.substring(key.indexOf('=') + 1); } } } if (key != null) { if (key.length() == 0) { key = null; } else { // Decode UTF8 chars try { byte[] bytes = key.getBytes(PLATFORM_ENCODING); key = StringUtils.decodeToString(bytes, StringUtils.UTF_8); if (utf8) { bytes = key.getBytes(PLATFORM_ENCODING); key = StringUtils.decodeToString(bytes, StringUtils.UTF_8); } } catch (Exception ignored) { } if (log.isDebugEnabled()) { log.debug("LDAP search filter (" + key + ") readed."); } key = key.toLowerCase(); // All contacts requested if (key.equals("@")) { key = null; } } } } // Handle native charset lock if (key != null && !utf8) { nativeCharsetLocked = true; } // Find entry GmailContact[] contacts = loader.getContacts(); if (contacts != null) { GmailContact contact; for (int n = 0; n < contacts.length; n++) { contact = contacts[n]; if (key != null && contact.name.toLowerCase().indexOf(key) == -1) { continue; } // Add search entry SearchResultEntry entry = new SearchResultEntry(); entry.setMessageId(request.getMessageId()); LdapDN name; try { name = new LdapDN("CN=" + encode(contact.name, utf8)); } catch (Exception badDN) { log.debug(badDN); continue; } entry.setObjectName(name); BasicAttributes partialAttributeList = new BasicAttributes(true); partialAttributeList.put(new BasicAttribute("cn", encode(contact.name, utf8))); if (contact.email.length() != 0) { // first email partialAttributeList.put(new BasicAttribute("mail", encode(contact.email, utf8))); } if (contact.notes.length() != 0) { // notes partialAttributeList.put(new BasicAttribute("comment", encode(contact.notes, utf8))); partialAttributeList.put(new BasicAttribute("description", encode(contact.notes, utf8))); } String mobile = contact.mobile; if (mobile.length() == 0) { mobile = contact.phone; } if (mobile.length() != 0) { // mobile phone partialAttributeList.put(new BasicAttribute("telephonenumber", encode(mobile, utf8))); } if (contact.phone.length() != 0) { // homePhone partialAttributeList.put(new BasicAttribute("homePhone", encode(contact.phone, utf8))); } if (contact.mail.length() != 0) { // second email partialAttributeList .put(new BasicAttribute("mozillaSecondEmail", encode(contact.mail, utf8))); partialAttributeList .put(new BasicAttribute("mailAlternateAddress", encode(contact.mail, utf8))); } if (contact.address.length() != 0) { // postal address partialAttributeList .put(new BasicAttribute("postalAddress", encode(contact.address, utf8))); partialAttributeList .put(new BasicAttribute("homePostalAddress", encode(contact.address, utf8))); partialAttributeList.put(new BasicAttribute("homeStreet", encode(contact.address, utf8))); } if (contact.pager.length() != 0) { // pager partialAttributeList.put(new BasicAttribute("pager", encode(contact.pager, utf8))); } if (contact.fax.length() != 0) { // fax partialAttributeList .put(new BasicAttribute("facsimileTelephoneNumber", encode(contact.fax, utf8))); if (contact.pager.length() == 0) { partialAttributeList.put(new BasicAttribute("pager", encode(contact.fax, utf8))); } } if (contact.title.length() != 0) { // title partialAttributeList.put(new BasicAttribute("title", encode(contact.title, utf8))); } if (contact.company.length() != 0) { // company partialAttributeList.put(new BasicAttribute("company", encode(contact.company, utf8))); partialAttributeList.put(new BasicAttribute("o", encode(contact.company, utf8))); } entry.setPartialAttributeList(partialAttributeList); list.addLast(entry); } } // Search done if (log.isDebugEnabled()) { log.debug("Found " + list.size() + " contacts."); } SearchResultDone done = new SearchResultDone(); done.setMessageId(request.getMessageId()); result = new LdapResult(); result.setResultCode(0); done.setLdapResult(result); list.addLast(done); break; case LdapConstants.ABANDON_REQUEST: // Abandon command result = new LdapResult(); result.setResultCode(0); LdapResponse response = new LdapResponse(); response.setLdapResult(result); list.addLast(response); break; default: // Unsupported command log.debug("Unsupported LDAP command!"); result = new LdapResult(); result.setErrorMessage("Unsupported LDAP command!"); response = new LdapResponse(); response.setLdapResult(result); list.addLast(response); } log.debug("LDAP request processed."); if (!list.isEmpty()) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Iterator responses = list.iterator(); while (responses.hasNext()) { LdapMessage response = (LdapMessage) responses.next(); response.setMessageId(request.getMessageId()); // Append LDAP response LdapMessage message = new LdapMessage(); message.setProtocolOP(response); message.setMessageId(request.getMessageId()); ByteBuffer bb = message.encode(null); byte[] a = bb.array(); out.write(a); } byte[] bytes = out.toByteArray(); return ByteBuffer.wrap(bytes); } return null; }
From source file:appeng.items.tools.powered.ToolColorApplicator.java
private ItemStack findNextColor(final ItemStack is, final ItemStack anchor, final int scrollOffset) { ItemStack newColor = null;/* w w w. j ava 2 s. c om*/ final IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory(is, null, StorageChannel.ITEMS); if (inv != null) { final IItemList<IAEItemStack> itemList = inv .getAvailableItems(AEApi.instance().storage().createItemList()); if (anchor == null) { final IAEItemStack firstItem = itemList.getFirstItem(); if (firstItem != null) { newColor = firstItem.getItemStack(); } } else { final LinkedList<IAEItemStack> list = new LinkedList<IAEItemStack>(); for (final IAEItemStack i : itemList) { list.add(i); } Collections.sort(list, new Comparator<IAEItemStack>() { @Override public int compare(final IAEItemStack a, final IAEItemStack b) { return ItemSorters.compareInt(a.getItemDamage(), b.getItemDamage()); } }); if (list.size() <= 0) { return null; } IAEItemStack where = list.getFirst(); int cycles = 1 + list.size(); while (cycles > 0 && !where.equals(anchor)) { list.addLast(list.removeFirst()); cycles--; where = list.getFirst(); } if (scrollOffset > 0) { list.addLast(list.removeFirst()); } if (scrollOffset < 0) { list.addFirst(list.removeLast()); } return list.get(0).getItemStack(); } } if (newColor != null) { this.setColor(is, newColor); } return newColor; }
From source file:edu.ucla.cs.scai.canali.core.index.utils.BiomedicalOntologyUtils.java
private void computeSameAsGroups() throws IOException { //load all entities and assign an id to them //dbpedia entites are loaded first String regex = "(\\s|\\t)*<([^<>]*)>(\\s|\\t)*<([^<>]*)>(\\s|\\t)*(<|\")(.*)(>|\")"; Pattern p = Pattern.compile(regex); for (String fileName : fileNames) { try (BufferedReader in = new BufferedReader(new FileReader(downloadedFilesPath + fileName))) { String l = in.readLine(); while (l != null) { Matcher m = p.matcher(l); if (m.find()) { String s = m.group(2); if ((s.startsWith("http://www.dbpedia.org/resource") || s.startsWith("http://dbpedia.org/resource")) && !entityIds.containsKey(s) && !classIds.containsKey(s) && !propertyIds.containsKey(s)) { entityIds.put(s, entityIds.size() + 1); }//from w ww.j ava 2 s.com String v = m.group(7); if ((v.startsWith("http://www.dbpedia.org/resource") || v.startsWith("http://dbpedia.org/resource")) && !entityIds.containsKey(v) && !classIds.containsKey(s) && !propertyIds.containsKey(s)) { entityIds.put(v, entityIds.size() + 1); } } l = in.readLine(); } } } //now non-dpedia entities are loaded: http://www4.wiwiss.fu-berlin.de, http://data.linkedct.org, http://purl.org, http://bio2rdf.org, http://www.ncbi.nlm.nih.gov for (String fileName : fileNames) { try (BufferedReader in = new BufferedReader(new FileReader(downloadedFilesPath + fileName))) { String l; while ((l = in.readLine()) != null) { Matcher m = p.matcher(l); if (m.find()) { String s = m.group(2); if (s.startsWith("http://www4.wiwiss.fu-berlin.de") && !entityIds.containsKey(s) && !classIds.containsKey(s) && !propertyIds.containsKey(s)) { entityIds.put(s, entityIds.size() + 1); } String v = m.group(7); if ((v.startsWith("http://www4.wiwiss.fu-berlin.de") //|| v.startsWith("http://data.linkedct.org") || v.startsWith("http://129.128.185.122")) && !entityIds.containsKey(v) && !classIds.containsKey(s) && !propertyIds.containsKey(s)) { entityIds.put(v, entityIds.size() + 1); } } if (entityIds.size() == 12413) { System.out.println(); } } } } //create the sameAsEdges sets sameAsEdges = new HashSet[entityIds.size() + 1]; entityById = new String[entityIds.size() + 1]; for (Map.Entry<String, Integer> e : entityIds.entrySet()) { entityById[e.getValue()] = e.getKey(); } for (String fileName : fileNames) { try (BufferedReader in = new BufferedReader(new FileReader(downloadedFilesPath + fileName))) { String l; while ((l = in.readLine()) != null) { Matcher m = p.matcher(l); if (m.find()) { String a = m.group(4); if (a.equals("http://www.w3.org/2002/07/owl#sameAs")) { String s = m.group(2); int idS = entityIds.get(s); String v = m.group(7); Integer idV = entityIds.get(v); if (idV == null) { continue; } if (sameAsEdges[idS] == null) { sameAsEdges[idS] = new HashSet<>(); } sameAsEdges[idS].add(idV); if (sameAsEdges[idV] == null) { sameAsEdges[idV] = new HashSet<>(); } sameAsEdges[idV].add(idS); } /* else if (a.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")) { String s = m.group(2); String v = m.group(7); if (v.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#Property")) { properties.add(s); } else if (v.equals("http://www.w3.org/2000/01/rdf-schema#Class")) { classes.add(s); } }*/ } l = in.readLine(); } } } sameAs = new int[entityIds.size() + 1]; int i = 1; while (i < sameAs.length) { LinkedList<Integer> q = new LinkedList<>(); q.addLast(i); while (!q.isEmpty()) { int j = q.removeFirst(); if (sameAs[j] != 0) { if (sameAs[j] != i) { System.out.println("Error"); System.exit(0); } } else { sameAs[j] = i; if (sameAsEdges[j] != null) { for (int k : sameAsEdges[j]) { q.addLast(k); } } } } i++; while (i < sameAs.length && sameAs[i] != 0) { i++; } } }