Example usage for java.util Collections EMPTY_SET

List of usage examples for java.util Collections EMPTY_SET

Introduction

In this page you can find the example usage for java.util Collections EMPTY_SET.

Prototype

Set EMPTY_SET

To view the source code for java.util Collections EMPTY_SET.

Click Source Link

Document

The empty set (immutable).

Usage

From source file:org.apache.openjpa.kernel.BrokerImpl.java

public void setSavepoint(String name) {
    beginOperation(true);/*from   www.j  a va 2 s .  co  m*/
    try {
        assertActiveTransaction();
        if (_savepoints != null && _savepoints.containsKey(name))
            throw new UserException(_loc.get("savepoint-exists", name));

        if (hasFlushed() && !_spm.supportsIncrementalFlush())
            throw new UnsupportedException(_loc.get("savepoint-flush-not-supported"));

        OpenJPASavepoint save = _spm.newSavepoint(name, this);
        if (_savepoints == null || _savepoints.isEmpty()) {
            save.save(getTransactionalStates());
            _savepoints = new LinkedMap();
        } else {
            if (_savepointCache == null)
                save.save(Collections.EMPTY_SET);
            else {
                save.save(_savepointCache);
                _savepointCache.clear();
            }
        }
        _savepoints.put(name, save);
    } catch (OpenJPAException ke) {
        throw ke;
    } catch (Exception e) {
        throw new GeneralException(e);
    } finally {
        endOperation();
    }
}

From source file:org.mindswap.pellet.KnowledgeBase.java

/**
 * Return the inverse property and all its equivalent properties.
 * /*from   ww w  .  j av a2 s.c o  m*/
 * @param prop
 * @return
 */
public Set getInverses(ATerm name) {
    Role prop = rbox.getRole(name);
    if (prop == null) {
        if (PelletOptions.SILENT_UNDEFINED_ENTITY_HANDLING)
            return Collections.EMPTY_SET;
        else
            throw new UnsupportedFeatureException(name + " is not a property!");
    }
    Role invR = prop.getInverse();
    if (invR != null && !invR.isAnon()) {
        Set inverses = getAllEquivalentProperties(invR.getName());
        return inverses;
    }

    return SetUtils.EMPTY_SET;
}

From source file:org.mindswap.pellet.KnowledgeBase.java

/**
 * Return the (explicit or implicit) domain restrictions on the property. Unlike
 * other functions the result may contain unnamed classes (represented as ATerm
 * objects). If the domain is an intersection then all the elements of the 
 * intersection will be included in the resulting set. 
 * //from   www  . j  a v a 2 s  .c  o  m
 * @param prop
 * @return
 */
public Set getDomains(ATermAppl name) {
    Set set = new HashSet();
    Role prop = rbox.getRole(name);
    if (prop == null) {
        if (PelletOptions.SILENT_UNDEFINED_ENTITY_HANDLING)
            return Collections.EMPTY_SET;
        else
            throw new UnsupportedFeatureException(name + " is not a property!");
    }

    ATermAppl domain = prop.getDomain();
    if (domain != null) {
        if (ATermUtils.isAnd(domain))
            set = ATermUtils.getPrimitives((ATermList) domain.getArgument(0));
        else if (ATermUtils.isPrimitive(domain))
            set = SetUtils.singleton(domain);
    }

    return set;
}

From source file:org.mindswap.pellet.KnowledgeBase.java

public Set getPossibleProperties(ATermAppl x) {
    ensureConsistency();/*from   ww  w  . j a  v a2  s. c om*/

    Individual ind = abox.getIndividual(x);

    if (ind == null) {
        if (PelletOptions.SILENT_UNDEFINED_ENTITY_HANDLING)
            return Collections.EMPTY_SET;
        else
            throw new UnsupportedFeatureException(x + " is not an individual!");
    }

    return abox.getPossibleProperties(x);
}

From source file:org.matonto.ontology.rest.impl.OntologyRestImplTest.java

@Test
public void testGetDatatypesInOntologyWhenNoDatatypes() {
    when(ontology.getAllDatatypes()).thenReturn(Collections.EMPTY_SET);

    Response response = target().path("ontologies/" + encode(ontologyIRI.stringValue()) + "/datatypes")
            .queryParam("branchId", branchId.stringValue()).queryParam("commitId", commitId.stringValue())
            .request().get();//from   w w w .  jav  a  2s  .co  m

    assertEquals(response.getStatus(), 200);
    verify(ontologyManager).retrieveOntology(any(Resource.class), any(Resource.class), any(Resource.class));
    assertGetOntology(true);
    assertDatatypes(getResponse(response), Collections.EMPTY_SET);
}

From source file:org.wso2.carbon.apimgt.impl.APIConsumerImpl.java

@Override
public Set<Tag> getAllTags(String requestedTenantDomain) throws APIManagementException {

    this.isTenantModeStoreView = (requestedTenantDomain != null);

    if (requestedTenantDomain != null) {
        this.requestedTenant = requestedTenantDomain;
    }/*from   w w w  .jav a  2  s  .  co m*/

    /* We keep track of the lastUpdatedTime of the TagCache to determine its freshness.
     */
    long lastUpdatedTimeAtStart = lastUpdatedTime;
    long currentTimeAtStart = System.currentTimeMillis();
    if (isTagCacheEnabled && ((currentTimeAtStart - lastUpdatedTimeAtStart) < tagCacheValidityTime)) {
        if (tagSet != null) {
            return tagSet;
        }
    }

    TreeSet<Tag> tempTagSet = new TreeSet<Tag>(new Comparator<Tag>() {
        @Override
        public int compare(Tag o1, Tag o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    Registry userRegistry = null;
    boolean isTenantFlowStarted = false;
    String tagsQueryPath = null;
    try {
        tagsQueryPath = RegistryConstants.QUERIES_COLLECTION_PATH + "/tag-summary";
        Map<String, String> params = new HashMap<String, String>();
        params.put(RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.TAG_SUMMARY_RESULT_TYPE);
        //as a tenant, I'm browsing my own Store or I'm browsing a Store of another tenant..
        if ((this.isTenantModeStoreView && this.tenantDomain == null)
                || (this.isTenantModeStoreView && isTenantDomainNotMatching(requestedTenantDomain))) {//Tenant based store anonymous mode
            int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager()
                    .getTenantId(this.requestedTenant);
            userRegistry = ServiceReferenceHolder.getInstance().getRegistryService()
                    .getGovernanceUserRegistry(CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME, tenantId);
        } else {
            userRegistry = registry;
        }

        Map<String, Tag> tagsData = new HashMap<String, Tag>();
        try {
            PrivilegedCarbonContext.getThreadLocalCarbonContext()
                    .setUsername(((UserRegistry) userRegistry).getUserName());
            if (requestedTenant != null
                    && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(requestedTenant)) {
                isTenantFlowStarted = true;
                PrivilegedCarbonContext.startTenantFlow();
                PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(requestedTenant, true);
                PrivilegedCarbonContext.getThreadLocalCarbonContext()
                        .setUsername(((UserRegistry) userRegistry).getUserName());
            }

            Map<String, List<String>> criteriaPublished = new HashMap<String, List<String>>();
            criteriaPublished.put(APIConstants.LCSTATE_SEARCH_KEY, new ArrayList<String>() {
                {
                    add(APIConstants.PUBLISHED);
                }
            });
            //rxt api media type
            List<TermData> termsPublished = GovernanceUtils.getTermDataList(criteriaPublished,
                    APIConstants.API_OVERVIEW_TAG, APIConstants.API_RXT_MEDIA_TYPE, true);

            if (termsPublished != null) {
                for (TermData data : termsPublished) {
                    tempTagSet.add(new Tag(data.getTerm(), (int) data.getFrequency()));
                }
            }

            Map<String, List<String>> criteriaPrototyped = new HashMap<String, List<String>>();
            criteriaPrototyped.put(APIConstants.LCSTATE_SEARCH_KEY, new ArrayList<String>() {
                {
                    add(APIConstants.PROTOTYPED);
                }
            });
            //rxt api media type
            List<TermData> termsPrototyped = GovernanceUtils.getTermDataList(criteriaPrototyped,
                    APIConstants.API_OVERVIEW_TAG, APIConstants.API_RXT_MEDIA_TYPE, true);

            if (termsPrototyped != null) {
                for (TermData data : termsPrototyped) {
                    tempTagSet.add(new Tag(data.getTerm(), (int) data.getFrequency()));
                }
            }

        } finally {
            if (isTenantFlowStarted) {
                PrivilegedCarbonContext.endTenantFlow();
            }
        }

        synchronized (tagCacheMutex) {
            lastUpdatedTime = System.currentTimeMillis();
            this.tagSet = tempTagSet;
        }

    } catch (RegistryException e) {
        try {
            //Before a tenant login to the store or publisher at least one time,
            //a registry exception is thrown when the tenant store is accessed in anonymous mode.
            //This fix checks whether query resource available in the registry. If not
            // give a warn.
            if (userRegistry != null && !userRegistry.resourceExists(tagsQueryPath)) {
                log.warn("Failed to retrieve tags query resource at " + tagsQueryPath);
                return tagSet == null ? Collections.EMPTY_SET : tagSet;
            }
        } catch (RegistryException e1) {
            // Even if we should ignore this exception, we are logging this as a warn log.
            // The reason is that, this error happens when we try to add some additional logs in an error
            // scenario and it does not affect the execution path.
            log.warn("Unable to execute the resource exist method for tags query resource path : "
                    + tagsQueryPath, e1);
        }
        handleException("Failed to get all the tags", e);
    } catch (UserStoreException e) {
        handleException("Failed to get all the tags", e);
    }

    return tagSet;
}

From source file:org.fenixedu.academic.domain.StudentCurricularPlan.java

@Atomic
public RuleResult removeCurriculumModulesFromNoCourseGroupCurriculumGroup(
        final List<CurriculumModule> curriculumModules, final ExecutionSemester executionSemester,
        final NoCourseGroupCurriculumGroupType groupType) {
    final EnrolmentContext context = new EnrolmentContext(this, executionSemester, Collections.EMPTY_SET,
            curriculumModules, groupType.getCurricularRuleLevel());
    return org.fenixedu.academic.domain.studentCurriculum.StudentCurricularPlanEnrolment.createManager(context)
            .manage();//  www. j  a v  a2s . c o  m
}

From source file:com.tesora.dve.sql.parser.TranslatorUtils.java

public Set<TableModifier> buildCharsetCollationModifiers(final CharsetCollationModifierBuilder builder) {
    if (builder.hasValues()) {
        return builder.buildModifiers(getNativeCharSetCatalog(), getNativeCollationCatalog());
    }//from   w ww  . j ava2s  . com
    return Collections.EMPTY_SET;
}

From source file:org.matonto.ontology.rest.impl.OntologyRestImplTest.java

@Test
public void testGetObjectPropertiesInOntologyWhenNoObjectProperties() {
    when(ontology.getAllObjectProperties()).thenReturn(Collections.EMPTY_SET);

    Response response = target().path("ontologies/" + encode(ontologyIRI.stringValue()) + "/object-properties")
            .queryParam("branchId", branchId.stringValue()).queryParam("commitId", commitId.stringValue())
            .request().get();//from www.j  a v  a  2  s  .  c o m

    assertEquals(response.getStatus(), 200);
    verify(ontologyManager).retrieveOntology(any(Resource.class), any(Resource.class), any(Resource.class));
    assertGetOntology(true);
    assertObjectProperties(getResponse(response), Collections.EMPTY_SET);
}

From source file:org.apache.openjpa.kernel.BrokerImpl.java

/**
 * End the current transaction, making appropriate state transitions.
 *///from   www .  j  a v a  2  s. co  m
protected void endTransaction(int status) {
    // if a data store transaction was in progress, do the
    // appropriate transaction change
    boolean rollback = status != Status.STATUS_COMMITTED;
    List<Exception> exceps = null;

    try {
        exceps = add(exceps, endStoreManagerTransaction(rollback));
    } catch (RuntimeException re) {
        rollback = true;
        exceps = add(exceps, re);
    }

    // go back to default none lock level
    _fc.setReadLockLevel(LOCK_NONE);
    _fc.setWriteLockLevel(LOCK_NONE);
    _fc.setLockTimeout(-1);

    Collection transStates;
    if (hasTransactionalObjects())
        transStates = _transCache;
    else
        transStates = Collections.EMPTY_SET;

    // fire after rollback/commit event
    Collection mobjs = null;
    if (_transEventManager.hasEndListeners()) {
        mobjs = new ManagedObjectCollection(transStates);
        int eventType = (rollback) ? TransactionEvent.AFTER_ROLLBACK : TransactionEvent.AFTER_COMMIT;
        fireTransactionEvent(
                new TransactionEvent(this, eventType, mobjs, _persistedClss, _updatedClss, _deletedClss));
    }

    // null transactional caches now so that all the removeFromTransaction
    // calls as we transition each object don't have to do any work; don't
    // clear trans cache object because we still need the transStates
    // reference to it below
    _transCache = null;
    if (_persistedClss != null)
        _persistedClss = null;
    if (_updatedClss != null)
        _updatedClss = null;
    if (_deletedClss != null)
        _deletedClss = null;

    // new cache would get cleared anyway during transitions, but doing so
    // immediately saves us some lookups
    _cache.clearNew();

    // tell all derefed instances they're no longer derefed; we can't
    // rely on rollback and commit calls below cause some instances might
    // not be transactional
    if (_derefCache != null && !_derefCache.isEmpty()) {
        for (Iterator<StateManagerImpl> itr = _derefCache.iterator(); itr.hasNext();)
            itr.next().setDereferencedDependent(false, false);
        _derefCache = null;
    }

    // perform commit or rollback state transitions on each instance
    StateManagerImpl sm;
    for (Iterator itr = transStates.iterator(); itr.hasNext();) {
        sm = (StateManagerImpl) itr.next();
        try {
            if (rollback) {
                // tell objects that may have been derefed then flushed
                // (and therefore deleted) to un-deref
                sm.setDereferencedDependent(false, false);
                sm.rollback();
            } else {
                if (sm.getPCState() == PCState.PNEWDELETED || sm.getPCState() == PCState.PDELETED) {
                    fireLifecycleEvent(sm.getPersistenceCapable(), null, sm.getMetaData(),
                            LifecycleEvent.AFTER_DELETE_PERFORMED);
                }
                sm.commit();
            }
        } catch (RuntimeException re) {
            exceps = add(exceps, re);
        }
    }

    // notify the lock manager to clean up and release remaining locks
    _lm.endTransaction();

    // clear old savepoints in reverse
    OpenJPASavepoint save;
    while (_savepoints != null && _savepoints.size() > 0) {
        save = (OpenJPASavepoint) _savepoints.remove(_savepoints.size() - 1);
        save.release(false);
    }
    _savepoints = null;
    _savepointCache = null;

    // fire after state change event
    if (_transEventManager.hasEndListeners())
        fireTransactionEvent(
                new TransactionEvent(this, TransactionEvent.AFTER_STATE_TRANSITIONS, mobjs, null, null, null));

    // now clear trans cache; keep cleared version rather than
    // null to avoid having to re-create the set later; more efficient
    if (transStates != Collections.EMPTY_SET) {
        _transCache = (TransactionalCache) transStates;
        _transCache.clear();
    }

    throwNestedExceptions(exceps, true);
}