List of usage examples for java.util List listIterator
ListIterator<E> listIterator(int index);
From source file:se.uu.it.cs.recsys.ruleminer.impl.FPGrowthImpl.java
private Map<Set<Integer>, Integer> miningWithFPGrowth(FPTree fpTree, Set<Integer> suffixPattern) { Map<Set<Integer>, Integer> frequentPatternFromSinglePrefixPath = new HashMap<>(); FPTree branchingTree = fpTree;/* w ww.j av a 2 s. c o m*/ if (fpTree.hasSinglePrefixPath()) { List<Item> singlePrefixPath = fpTree.getSinglePrefixPathInTopDownOrder(); // LOGGER.debug("Single prefix path: {}", singlePrefixPath); Map<Set<Integer>, Integer> frequentPatternWithinSinglePrefixPath = getFrequentPatternFromSinglePrefixPath( singlePrefixPath); frequentPatternFromSinglePrefixPath = frequentPatternWithinSinglePrefixPath.entrySet().stream() .collect(Collectors.toMap(entry -> { Set<Integer> existingPattern = new HashSet<>(entry.getKey()); existingPattern.addAll(suffixPattern); return existingPattern; }, entry -> entry.getValue())); branchingTree = fpTree.getBranchingTree(); if (branchingTree == null) { return frequentPatternFromSinglePrefixPath; } } Map<Set<Integer>, Integer> frequentPatternFromBranchingTree = new HashMap<>(); List<HeaderTableItem> headerList = branchingTree.getHeaderTable(); ListIterator<HeaderTableItem> itr = headerList.listIterator(headerList.size()); while (itr.hasPrevious()) { HeaderTableItem visitingItem = itr.previous(); Set<Integer> newPattern = new HashSet<>(suffixPattern); newPattern.add(visitingItem.getItem().getId()); frequentPatternFromBranchingTree.put(newPattern, visitingItem.getItem().getCount()); // LOGGER.debug("Adding new pattern: {}, count: {}", newPattern, visitingItem.getItem().getCount()); Map<List<Integer>, Integer> patternBase = FPTreeUtil.getPatternBase(visitingItem); // LOGGER.debug("Pattern base for item {} is: {}", visitingItem.getItem(), patternBase); FPTree conditionalTree = FPTreeBuilder.buildConditionalFPTree(patternBase, this.minSupport); if (conditionalTree != null && !conditionalTree.getRoot().getChildren().isEmpty()) { frequentPatternFromBranchingTree.putAll(miningWithFPGrowth(conditionalTree, newPattern)); } } return consolidatePatterns(frequentPatternFromSinglePrefixPath, frequentPatternFromBranchingTree); }
From source file:edu.uci.ics.jung.algorithms.blockmodel.StructurallyEquivalent.java
/** * For each vertex pair v, v1 in G, checks whether v and v1 are fully * equivalent: meaning that they connect to the exact same vertices. (Is * this regular equivalence, or whathaveyou?) * //w w w . j ava 2 s.co m * Returns a Set of Pairs of vertices, where all the vertices in the inner * Pairs are equivalent. * * @param g */ protected Set<Pair<V>> getEquivalentPairs(Graph<V, ?> g) { Set<Pair<V>> rv = new HashSet<Pair<V>>(); Set<V> alreadyEquivalent = new HashSet<V>(); List<V> l = new ArrayList<V>(g.getVertices()); for (V v1 : l) { if (alreadyEquivalent.contains(v1)) continue; for (Iterator<V> iterator = l.listIterator(l.indexOf(v1) + 1); iterator.hasNext();) { V v2 = iterator.next(); if (alreadyEquivalent.contains(v2)) continue; if (!canPossiblyCompare(v1, v2)) continue; if (isStructurallyEquivalent(g, v1, v2)) { Pair<V> p = new Pair<V>(v1, v2); alreadyEquivalent.add(v2); rv.add(p); } } } return rv; }
From source file:org.apache.fop.layoutmgr.inline.FootnoteLayoutManager.java
/** * Find the last box in the sequence, and add a reference to the FootnoteBodyLM * @param citationList the list of elements representing the footnote citation *///www . j a v a 2s . c o m private void addAnchor(List citationList) { KnuthInlineBox lastBox = null; // the list of elements is searched backwards, until we find a box ListIterator citationIterator = citationList.listIterator(citationList.size()); while (citationIterator.hasPrevious() && lastBox == null) { Object obj = citationIterator.previous(); if (obj instanceof KnuthElement) { // obj is an element KnuthElement element = (KnuthElement) obj; if (element instanceof KnuthInlineBox) { lastBox = (KnuthInlineBox) element; } } else { // obj is a sequence of elements KnuthSequence seq = (KnuthSequence) obj; ListIterator nestedIterator = seq.listIterator(seq.size()); while (nestedIterator.hasPrevious() && lastBox == null) { KnuthElement element = (KnuthElement) nestedIterator.previous(); if (element instanceof KnuthInlineBox && !element.isAuxiliary() || element == forcedAnchor) { lastBox = (KnuthInlineBox) element; } } } } if (lastBox != null) { lastBox.setFootnoteBodyLM(bodyLM); } else { //throw new IllegalStateException("No anchor box was found for a footnote."); } }
From source file:org.craftercms.core.xml.mergers.impl.DescriptorMergerImpl.java
@Override public Document merge(List<Document> descriptorsToMerge) throws XmlMergeException { Document merged = DocumentHelper.createDocument(); if (CollectionUtils.isNotEmpty(descriptorsToMerge)) { Element mergedRoot = descriptorsToMerge.get(0).getRootElement().createCopy(); for (Iterator<Document> i = descriptorsToMerge.listIterator(1); i.hasNext();) { Element descriptorRoot = i.next().getRootElement().createCopy(); mergedRoot = initialMergeCue.merge(mergedRoot, descriptorRoot, initialMergeCueParams); }/*w w w . ja v a2s .c o m*/ merged.add(mergedRoot); } return merged; }
From source file:com.adaptris.jdbc.connection.FailoverConnection.java
private boolean createConnection(int start, int end) { List<String> list = config.getConnectionUrls(); if (start >= list.size()) { return createConnection(START_OF_LIST, end); }//from w ww . j av a 2 s . com Iterator i = list.listIterator(start == START_OF_LIST || start + 1 >= list.size() ? 0 : start + 1); while (i.hasNext()) { String url = i.next().toString(); if (list.indexOf(url) > end) { break; } if (isDebugMode()) { logR.trace("Connection attempt to " + url); } try { sqlConnection = DriverManager.getConnection(url, mergeConnectionProperties( config.getConnectionProperties(), config.getUsername(), config.getPassword())); sqlConnection.setAutoCommit(config.getAutoCommit()); currentIndex = list.indexOf(url); if (isDebugMode()) { logR.trace("Connected to [" + currentIndex + "] " + url); } return true; } catch (SQLException e) { logR.trace("Could not connect to " + url); } catch (PasswordException e) { logR.warn("Could not decode password"); break; } } return false; }
From source file:net.oneandone.stool.overview.ProcessesController.java
@RequestMapping(value = "{id}/log", method = RequestMethod.GET) @ResponseBody//from w w w . j a va 2 s .c o m public ResponseEntity log(@PathVariable(value = "id") String id, @RequestParam(defaultValue = "0") Integer index) throws IOException, InterruptedException { Node logfile; StringBuilder output; MultiValueMap<String, String> headers; output = new StringBuilder(); List<String> strings; ListIterator<String> iterator; headers = new HttpHeaders(); try { logfile = logFile(id); } catch (ResourceNotFoundException e) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } strings = logfile.readLines(); iterator = strings.listIterator(index); while (iterator.hasNext()) { output.append(iterator.next()).append("<br />"); } headers.set("X-index", "" + strings.size()); return new ResponseEntity<>(output.toString(), headers, HttpStatus.OK); }
From source file:com.redhat.lightblue.query.Projection.java
private Inclusion getFieldInclusion(Path field, ProjectionList p, Path context) { LOGGER.debug("Checking if a projection list projects {}", field); Inclusion lastResult = Inclusion.undecided; List<Projection> items = p.getItems(); ListIterator<Projection> itemsItr = items.listIterator(items.size()); while (itemsItr.hasPrevious()) { Inclusion ret = itemsItr.previous().getFieldInclusion(field, context); if (ret != Inclusion.undecided) { lastResult = ret;/*from w w w.j a v a 2s .c o m*/ break; } } LOGGER.debug("Projection list projects {}: {}", field, lastResult); return lastResult; }
From source file:com.google.gwt.emultest.java.util.ListTestBase.java
public void testListIteratorCreateInvalid() { List l = makeEmptyList(); l.add(new Integer(1)); l.listIterator(0); try {/*from ww w.j av a2 s . c o m*/ l.listIterator(1); } catch (IndexOutOfBoundsException e) { // expected } try { l.listIterator(-1); } catch (IndexOutOfBoundsException e) { // expected } }
From source file:org.apache.nifi.registry.web.security.authentication.x509.X509IdentityAuthenticationProvider.java
@Override protected AuthenticationSuccessToken buildAuthenticatedToken(AuthenticationRequestToken requestToken, AuthenticationResponse response) { AuthenticationRequest authenticationRequest = requestToken.getAuthenticationRequest(); String proxiedEntitiesChain = authenticationRequest.getDetails() != null ? (String) authenticationRequest.getDetails() : null;// w ww. j a v a 2s .co m if (StringUtils.isBlank(proxiedEntitiesChain)) { return super.buildAuthenticatedToken(requestToken, response); } // build the entire proxy chain if applicable - <end-user><proxy1><proxy2> final List<String> proxyChain = ProxiedEntitiesUtils.tokenizeProxiedEntitiesChain(proxiedEntitiesChain); proxyChain.add(response.getIdentity()); // add the chain as appropriate to each proxy NiFiUser proxy = null; for (final ListIterator<String> chainIter = proxyChain.listIterator(proxyChain.size()); chainIter .hasPrevious();) { String identity = chainIter.previous(); // determine if the user is anonymous final boolean isAnonymous = StringUtils.isBlank(identity); if (isAnonymous) { identity = StandardNiFiUser.ANONYMOUS_IDENTITY; } else { identity = mapIdentity(identity); } final Set<String> groups = getUserGroups(identity); // Only set the client address for client making the request because we don't know the clientAddress of the proxied entities String clientAddress = (proxy == null) ? requestToken.getClientAddress() : null; proxy = createUser(identity, groups, proxy, clientAddress, isAnonymous); if (chainIter.hasPrevious()) { try { PROXY_AUTHORIZABLE.authorize(authorizer, RequestAction.WRITE, proxy); } catch (final AccessDeniedException e) { throw new UntrustedProxyException(String.format("Untrusted proxy [%s].", identity)); } } } return new AuthenticationSuccessToken(new NiFiUserDetails(proxy)); }
From source file:fr.paris.lutece.plugins.workflow.modules.ticketing.service.task.TaskReplyAssignUpTicket.java
/** * Get the user assigning up the ticket corresponding to the resource of the resourceHistory id * @param nIdResourceHistory the resourceHistory id * @return the user assigning up the ticket corresponding to the resource of the resourceHistory id , {@code null} otherwise *//*from w ww . j ava2 s.c o m*/ protected AdminUser getAssigner(int nIdResourceHistory) { ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey(nIdResourceHistory); List<Integer> listIdResource = new ArrayList<Integer>(); listIdResource.add(resourceHistory.getIdResource()); List<Integer> listIdHistory = _resourceHistoryService.getListHistoryIdByListIdResourceId(listIdResource, resourceHistory.getResourceType(), resourceHistory.getWorkflow().getId()); boolean isAssignUpActionFound = false; ListIterator<Integer> iterator = listIdHistory.listIterator(listIdHistory.size()); while (!isAssignUpActionFound && iterator.hasPrevious()) { resourceHistory = _resourceHistoryService.findByPrimaryKey(iterator.previous()); if ((resourceHistory.getAction().getId() == ASSIGN_UP_ACTION_ID) || (resourceHistory.getAction().getId() == ASSIGN_TO_UNIT_ACTION_ID)) { isAssignUpActionFound = true; } } return (isAssignUpActionFound ? AdminUserHome.findUserByLogin(resourceHistory.getUserAccessCode()) : null); }