Example usage for java.util LinkedHashSet add

List of usage examples for java.util LinkedHashSet add

Introduction

In this page you can find the example usage for java.util LinkedHashSet add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:org.pdfsam.console.business.pdf.handlers.SplitCmdExecutor.java

/**
 * Execute the split of a pdf document when split type is S_BLEVEL
 * //w w  w  . j a  v  a2  s  . c  o  m
 * @param inputCommand
 * @throws Exception
 */
private void executeBookmarksSplit(SplitParsedCommand inputCommand) throws Exception {
    pdfReader = PdfUtility.readerFor(inputCommand.getInputFile());
    int bLevel = inputCommand.getBookmarksLevel().intValue();
    Hashtable bookmarksTable = new Hashtable();
    if (bLevel > 0) {
        pdfReader.removeUnusedObjects();
        pdfReader.consolidateNamedDestinations();
        List bookmarks = SimpleBookmark.getBookmark(pdfReader);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        SimpleBookmark.exportToXML(bookmarks, out, "UTF-8", false);
        ByteArrayInputStream input = new ByteArrayInputStream(out.toByteArray());
        int maxDepth = PdfUtility.getMaxBookmarksDepth(input);
        input.reset();
        if (bLevel <= maxDepth) {
            SAXReader reader = new SAXReader();
            org.dom4j.Document document = reader.read(input);
            // head node
            String headBookmarkXQuery = "/Bookmark/Title[@Action=\"GoTo\"]";
            Node headNode = document.selectSingleNode(headBookmarkXQuery);
            if (headNode != null && headNode.getText() != null && headNode.getText().trim().length() > 0) {
                bookmarksTable.put(new Integer(1), headNode.getText().trim());
            }
            // bLevel nodes
            StringBuffer buffer = new StringBuffer("/Bookmark");
            for (int i = 0; i < bLevel; i++) {
                buffer.append("/Title[@Action=\"GoTo\"]");
            }
            String xQuery = buffer.toString();
            List nodes = document.selectNodes(xQuery);
            input.close();
            input = null;
            if (nodes != null && nodes.size() > 0) {
                LinkedHashSet pageSet = new LinkedHashSet(nodes.size());
                for (Iterator nodeIter = nodes.iterator(); nodeIter.hasNext();) {
                    Node currentNode = (Node) nodeIter.next();
                    Node pageAttribute = currentNode.selectSingleNode("@Page");
                    if (pageAttribute != null && pageAttribute.getText().length() > 0) {
                        String attribute = pageAttribute.getText();
                        int blankIndex = attribute.indexOf(' ');
                        if (blankIndex > 0) {
                            Integer currentNumber = new Integer(attribute.substring(0, blankIndex));
                            String bookmarkText = currentNode.getText().trim();
                            // fix #2789963
                            if (currentNumber.intValue() > 0) {
                                // bookmarks regexp matching if any
                                if (StringUtils.isBlank(inputCommand.getBookmarkRegexp())
                                        || bookmarkText.matches(inputCommand.getBookmarkRegexp())) {
                                    // to split just before the given page
                                    if ((currentNumber.intValue()) > 1) {
                                        pageSet.add(new Integer(currentNumber.intValue() - 1));
                                    }
                                    if (StringUtils.isNotBlank(bookmarkText)) {
                                        bookmarksTable.put(currentNumber, bookmarkText.trim());
                                    }
                                }
                            }
                        }
                    }
                }
                if (pageSet.size() > 0) {
                    if (StringUtils.isBlank(inputCommand.getBookmarkRegexp())) {
                        LOG.debug("Found " + pageSet.size() + " destination pages at level " + bLevel);
                    } else {
                        LOG.debug("Found " + pageSet.size() + " destination pages at level " + bLevel
                                + " matching '" + inputCommand.getBookmarkRegexp() + "'");
                    }
                    inputCommand.setSplitPageNumbers((Integer[]) pageSet.toArray(new Integer[pageSet.size()]));
                } else {
                    throw new SplitException(SplitException.ERR_BLEVEL_NO_DEST, new String[] { "" + bLevel });
                }
            } else {
                throw new SplitException(SplitException.ERR_BLEVEL, new String[] { "" + bLevel });
            }
        } else {
            input.close();
            pdfReader.close();
            throw new SplitException(SplitException.ERR_BLEVEL_OUTOFBOUNDS,
                    new String[] { "" + bLevel, "" + maxDepth });

        }
    } else {
        pdfReader.close();
        throw new SplitException(SplitException.ERR_NOT_VALID_BLEVEL, new String[] { "" + bLevel });
    }
    pdfReader.close();
    executeSplit(inputCommand, bookmarksTable);
}

From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java

/**
 * @see org.openmrs.module.sync.api.db.SyncDAO#getSyncStatistics(java.util.Date, java.util.Date)
 *///from  w  w  w . ja v a2s. c  om
@SuppressWarnings("unchecked")
public Map<RemoteServer, LinkedHashSet<SyncStatistic>> getSyncStatistics(Date fromDate, Date toDate)
        throws DAOException {

    //first get the list of remote servers and make map out of it
    List<RemoteServer> servers = this.getRemoteServers();

    Map<RemoteServer, LinkedHashSet<SyncStatistic>> map = new HashMap<RemoteServer, LinkedHashSet<SyncStatistic>>();

    String hqlChild = "select rs.nickname, ssr.state, count(*) "
            + "from RemoteServer rs join rs.serverRecords as ssr "
            + "where rs.serverId = :server_id and ssr.state  <> '"
            + SyncRecordState.NOT_SUPPOSED_TO_SYNC.toString() + "' " + "group by rs.nickname, ssr.state "
            + "order by nickname, state";

    String hqlParent = "select count(*) from SyncRecord where originalUuid = uuid and state <> '"
            + SyncRecordState.COMMITTED.toString() + "' and state <> '"
            + SyncRecordState.NOT_SUPPOSED_TO_SYNC.toString() + "'";

    //for each server configured, get its stats
    for (RemoteServer r : servers) {
        if (r.getServerType() == RemoteServerType.CHILD) {
            Query q = sessionFactory.getCurrentSession().createQuery(hqlChild);
            q.setParameter("server_id", r.getServerId());
            List<Object[]> rows = q.list();
            LinkedHashSet<SyncStatistic> props = new LinkedHashSet<SyncStatistic>();
            for (Object[] row : rows) {
                SyncStatistic stat = new SyncStatistic(SyncStatistic.Type.SYNC_RECORD_COUNT_BY_STATE,
                        row[1].toString(), row[2]); //state/count
                props.add(stat);
            }
            map.put(r, props);
        } else {
            //for parent servers, get the number of records in sync record
            Query q = sessionFactory.getCurrentSession().createQuery(hqlParent);
            Long count = (Long) q.uniqueResult();
            LinkedHashSet<SyncStatistic> props = new LinkedHashSet<SyncStatistic>();
            if (count != null) {
                props.add(new SyncStatistic(SyncStatistic.Type.SYNC_RECORD_COUNT_BY_STATE, "AWAITING", count)); //count
            }
            map.put(r, props);
        }
    }

    return map;
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerV3Impl.java

public BulkResponse findAssociations(Collection findQualifiers, String sourceObjectId, String targetObjectId,
        Collection associationTypes) throws JAXRException {
    //TODO: Currently we just return all the Association objects owned by the caller
    IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
    try {/*from  w w  w. ja va 2  s .  c o m*/
        ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection();
        AuthToken auth = this.getAuthToken(con, registry);
        PublisherAssertions result = null;
        try {
            result = registry.getPublisherAssertions(auth.getAuthInfo());
        } catch (RegistryV3Exception rve) {
            String username = getUsernameFromCredentials(con.getCredentials());
            if (AuthTokenV3Singleton.getToken(username) != null) {
                AuthTokenV3Singleton.deleteAuthToken(username);
            }
            auth = getAuthToken(con, registry);
            result = registry.getPublisherAssertions(auth.getAuthInfo());
        }

        List<PublisherAssertion> publisherAssertionList = result.getPublisherAssertion();
        LinkedHashSet<Association> col = new LinkedHashSet<Association>();
        for (PublisherAssertion pas : publisherAssertionList) {
            String sourceKey = pas.getFromKey();
            String targetKey = pas.getToKey();
            Collection<Key> orgcol = new ArrayList<Key>();
            orgcol.add(new KeyImpl(sourceKey));
            orgcol.add(new KeyImpl(targetKey));
            BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
            Association asso = ScoutUddiV3JaxrHelper.getAssociation(bl.getCollection(),
                    registryService.getBusinessLifeCycleManager());
            KeyedReference keyr = pas.getKeyedReference();
            Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
            c.setName(new InternationalStringImpl(keyr.getKeyName()));
            c.setKey(new KeyImpl(keyr.getTModelKey()));
            c.setValue(keyr.getKeyValue());
            asso.setAssociationType(c);
            col.add(asso);
        }
        return new BulkResponseImpl(col);
    } catch (RegistryV3Exception e) {
        throw new JAXRException(e);
    }
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerV3Impl.java

public BulkResponse getRegistryObjects(String id) throws JAXRException {
    if (LifeCycleManager.ORGANIZATION.equalsIgnoreCase(id)) {
        IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
        ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection();
        AuthToken auth = this.getAuthToken(con, registry);
        LinkedHashSet<Organization> orgs = null;
        try {//  ww  w  .  java2 s .  c  om
            RegisteredInfo ri = null;
            try {
                ri = registry.getRegisteredInfo(auth.getAuthInfo());
            } catch (RegistryV3Exception rve) {
                String username = getUsernameFromCredentials(con.getCredentials());
                if (AuthTokenV3Singleton.getToken(username) != null) {
                    AuthTokenV3Singleton.deleteAuthToken(username);
                }
                auth = getAuthToken(con, registry);
                ri = registry.getRegisteredInfo(auth.getAuthInfo());
            }

            if (ri != null && ri.getBusinessInfos() != null) {
                List<BusinessInfo> bizInfoList = ri.getBusinessInfos().getBusinessInfo();
                orgs = new LinkedHashSet<Organization>();
                for (BusinessInfo businessInfo : bizInfoList) {
                    BusinessDetail detail = registry.getBusinessDetail(businessInfo.getBusinessKey());
                    orgs.add(((BusinessLifeCycleManagerV3Impl) registryService.getLifeCycleManagerImpl())
                            .createOrganization(detail));
                }
            }

        } catch (RegistryV3Exception re) {
            throw new JAXRException(re);
        }
        return new BulkResponseImpl(orgs);
    } else if (LifeCycleManager.SERVICE.equalsIgnoreCase(id)) {
        List<String> a = new ArrayList<String>();
        a.add("%");

        BulkResponse br = this.findServices(null, null, a, null, null);

        return br;
    } else {
        throw new JAXRException("Unsupported type for getRegistryObjects() :" + id);
    }

}

From source file:org.apache.tajo.plan.LogicalPlanner.java

private static LinkedHashSet<Target> createFieldTargetsFromRelation(QueryBlock block, RelationNode relationNode,
        Set<String> newlyEvaluatedRefNames) {
    LinkedHashSet<Target> targets = Sets.newLinkedHashSet();
    for (Column column : relationNode.getLogicalSchema().getAllColumns()) {

        // TODO - Currently, EvalNode has DataType as a return type. So, RECORD cannot be used for any target.
        // The following line is a kind of hack, preventing RECORD to be used for target in the logical planning phase.
        // This problem should be resolved after TAJO-1402.
        if (column.getTypeDesc().getDataType().getType() == TajoDataTypes.Type.RECORD) {
            continue;
        }/*from  ww  w. j a v  a2 s .c om*/

        String aliasName = block.namedExprsMgr.checkAndGetIfAliasedColumn(column.getQualifiedName());
        if (aliasName != null) {
            targets.add(new Target(new FieldEval(column), aliasName));
            newlyEvaluatedRefNames.remove(aliasName);
        } else {
            targets.add(new Target(new FieldEval(column)));
        }
    }
    return targets;
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerImpl.java

public BulkResponse getRegistryObjects(String id) throws JAXRException {
    if (LifeCycleManager.ORGANIZATION.equalsIgnoreCase(id)) {
        IRegistry registry = (IRegistry) registryService.getRegistry();
        ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection();
        AuthToken auth = this.getAuthToken(con, registry);
        LinkedHashSet<Organization> orgs = null;
        try {//w  w w  .  j a v  a  2s.  c  o  m
            RegisteredInfo ri = null;
            try {
                ri = registry.getRegisteredInfo(auth.getAuthInfo());
            } catch (RegistryException rve) {
                String username = getUsernameFromCredentials(con.getCredentials());
                if (AuthTokenSingleton.getToken(username) != null) {
                    AuthTokenSingleton.deleteAuthToken(username);
                }
                auth = getAuthToken(con, registry);
                ri = registry.getRegisteredInfo(auth.getAuthInfo());
            }

            if (ri != null && ri.getBusinessInfos() != null) {
                List<BusinessInfo> bizInfoList = ri.getBusinessInfos().getBusinessInfo();
                orgs = new LinkedHashSet<Organization>();
                for (BusinessInfo businessInfo : bizInfoList) {
                    BusinessDetail detail = registry.getBusinessDetail(businessInfo.getBusinessKey());
                    orgs.add(((BusinessLifeCycleManagerImpl) registryService.getLifeCycleManagerImpl())
                            .createOrganization(detail));
                }
            }

        } catch (RegistryException re) {
            throw new JAXRException(re);
        }
        return new BulkResponseImpl(orgs);
    } else if (LifeCycleManager.SERVICE.equalsIgnoreCase(id)) {
        List<String> a = new ArrayList<String>();
        a.add("%");

        BulkResponse br = this.findServices(null, null, a, null, null);

        return br;
    } else {
        throw new JAXRException("Unsupported type for getRegistryObjects() :" + id);
    }

}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerV3Impl.java

public BulkResponse findConcepts(Collection findQualifiers, Collection namePatterns, Collection classifications,
        Collection externalIdentifiers, Collection externalLinks) throws JAXRException {
    LinkedHashSet<Concept> col = new LinkedHashSet<Concept>();

    //Lets ask the uddi registry if it has the TModels
    IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
    FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
    Iterator iter = null;//from  w ww .j  a v a 2 s . co m
    if (namePatterns != null)
        iter = namePatterns.iterator();
    while (iter.hasNext()) {
        String namestr = (String) iter.next();
        try {
            TModelList list = registry.findTModel(namestr,
                    ScoutJaxrUddiV3Helper.getCategoryBagFromClassifications(classifications),
                    ScoutJaxrUddiV3Helper.getIdentifierBagFromExternalIdentifiers(externalIdentifiers),
                    juddiFindQualifiers, 10);

            if (list != null && list.getTModelInfos() != null) {
                List<TModelInfo> tmodelInfoList = list.getTModelInfos().getTModelInfo();
                if (tmodelInfoList != null) {
                    for (TModelInfo info : tmodelInfoList) {
                        col.add(ScoutUddiV3JaxrHelper.getConcept(info,
                                this.registryService.getBusinessLifeCycleManager()));
                    }
                }
            }
        } catch (RegistryV3Exception e) {
            throw new JAXRException(e.getLocalizedMessage());
        }
    }

    return new BulkResponseImpl(col);
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerImpl.java

public BulkResponse findConcepts(Collection findQualifiers, Collection namePatterns, Collection classifications,
        Collection externalIdentifiers, Collection externalLinks) throws JAXRException {
    LinkedHashSet<Concept> col = new LinkedHashSet<Concept>();

    //Lets ask the uddi registry if it has the TModels
    IRegistry registry = (IRegistry) registryService.getRegistry();
    FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
    Iterator iter = null;// ww w.j  av a 2 s .c om
    if (namePatterns != null)
        iter = namePatterns.iterator();
    while (iter.hasNext()) {
        String namestr = (String) iter.next();
        try {
            TModelList list = registry.findTModel(namestr,
                    ScoutJaxrUddiHelper.getCategoryBagFromClassifications(classifications),
                    ScoutJaxrUddiHelper.getIdentifierBagFromExternalIdentifiers(externalIdentifiers),
                    juddiFindQualifiers, 10);

            if (list != null && list.getTModelInfos() != null) {
                List<TModelInfo> tmodelInfoList = list.getTModelInfos().getTModelInfo();
                if (tmodelInfoList != null) {
                    for (TModelInfo info : tmodelInfoList) {
                        col.add(ScoutUddiJaxrHelper.getConcept(info,
                                this.registryService.getBusinessLifeCycleManager()));
                    }
                }
            }
        } catch (RegistryException e) {
            throw new JAXRException(e.getLocalizedMessage());
        }
    }

    return new BulkResponseImpl(col);
}

From source file:org.intermine.bio.dataconversion.SequenceProcessor.java

/**
 * Search ClassDescriptor cd class for refs/collections with the right name for the objectType
 * eg. find CDSs collection for objectType = CDS and find gene reference for objectType = Gene.
 *//* w ww  .j a va 2 s.c o  m*/
private List<FieldDescriptor> getReferenceForRelationship(String objectType, ClassDescriptor cd) {
    List<FieldDescriptor> fds = new ArrayList<FieldDescriptor>();
    LinkedHashSet<String> allClasses = new LinkedHashSet<String>();
    allClasses.add(objectType);
    try {
        Set<String> parentClasses = ClassDescriptor.findSuperClassNames(getModel(), objectType);
        allClasses.addAll(parentClasses);
    } catch (MetaDataException e) {
        throw new RuntimeException("class not found in the model", e);
    }

    for (String clsName : allClasses) {
        List<String> possibleRefNames = new ArrayList<String>();
        String unqualifiedClsName = TypeUtil.unqualifiedName(clsName);
        possibleRefNames.add(unqualifiedClsName);
        possibleRefNames.add(unqualifiedClsName + 's');
        possibleRefNames.add(StringUtil.decapitalise(unqualifiedClsName));
        possibleRefNames.add(StringUtil.decapitalise(unqualifiedClsName) + 's');
        for (String possibleRefName : possibleRefNames) {
            FieldDescriptor fd = cd.getFieldDescriptorByName(possibleRefName);
            if (fd != null) {
                fds.add(fd);
            }
        }
    }
    return fds;
}