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.candlepin.sync.ExporterTest.java

@SuppressWarnings("unchecked")
@Test//from   w ww .j  a v a 2s  .c om
public void exportProducts() throws Exception {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    Consumer consumer = mock(Consumer.class);
    Entitlement ent = mock(Entitlement.class);
    Pool pool = mock(Pool.class);
    Rules mrules = mock(Rules.class);
    Principal principal = mock(Principal.class);
    IdentityCertificate idcert = new IdentityCertificate();

    Set<Entitlement> entitlements = new HashSet<Entitlement>();
    entitlements.add(ent);

    Owner owner = TestUtil.createOwner("Example-Corporation");

    Product prod = TestUtil.createProduct("12345", "RHEL Product");
    prod.setMultiplier(1L);
    prod.setCreated(new Date());
    prod.setUpdated(new Date());
    prod.setAttributes(Collections.EMPTY_SET);

    Product prod1 = TestUtil.createProduct("MKT-prod", "RHEL Product");
    prod1.setMultiplier(1L);
    prod1.setCreated(new Date());
    prod1.setUpdated(new Date());
    prod1.setAttributes(Collections.EMPTY_SET);

    Product subProduct = TestUtil.createProduct("MKT-sub-prod", "Sub Product");
    subProduct.setMultiplier(1L);
    subProduct.setCreated(new Date());
    subProduct.setUpdated(new Date());
    subProduct.setAttributes(Collections.EMPTY_SET);

    Product subProvidedProduct = TestUtil.createProduct("332211", "Sub Product");
    subProvidedProduct.setMultiplier(1L);
    subProvidedProduct.setCreated(new Date());
    subProvidedProduct.setUpdated(new Date());
    subProvidedProduct.setAttributes(Collections.EMPTY_SET);

    ProductCertificate pcert = new ProductCertificate();
    pcert.setKey("euh0876puhapodifbvj094");
    pcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    pcert.setCreated(new Date());
    pcert.setUpdated(new Date());

    Set<Product> ppset = new HashSet<Product>();
    ppset.add(prod);

    Set<Product> sppSet = new HashSet<Product>();
    sppSet.add(subProvidedProduct);

    when(pool.getProvidedProducts()).thenReturn(ppset);
    when(pool.getProduct()).thenReturn(prod1);

    when(pool.getDerivedProvidedProducts()).thenReturn(sppSet);
    when(pool.getDerivedProduct()).thenReturn(subProduct);

    when(ent.getPool()).thenReturn(pool);
    when(mrules.getRules()).thenReturn("foobar");
    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(rc.getRules()).thenReturn(mrules);
    when(consumer.getEntitlements()).thenReturn(entitlements);
    when(psa.getProductCertificate(any(Owner.class), any(String.class))).thenReturn(pcert);
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");
    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);

    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());

    // FINALLY test this badboy
    Exporter e = new Exporter(ctc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules,
            pprov, dvc, dve, cdnc, cdne);

    File export = e.getFullExport(consumer);

    // VERIFY
    assertNotNull(export);
    verifyContent(export, "export/products/12345.pem", new VerifyProductCert("12345.pem"));
    assertFalse(verifyHasEntry(export, "export/products/MKT-prod.pem"));

    verifyContent(export, "export/products/332211.pem", new VerifyProductCert("332211.pem"));
    assertFalse(verifyHasEntry(export, "export/products/MKT-sub-prod.pem"));

    FileUtils.deleteDirectory(export.getParentFile());
    assertTrue(new File("/tmp/consumer_export.zip").delete());
    assertTrue(new File("/tmp/12345.pem").delete());
    assertTrue(new File("/tmp/332211.pem").delete());
}

From source file:edu.utah.further.core.math.schedule.JobSchedulerGraphImpl.java

/**
 * Get dependencies relevant to a job runner event. runner start-up event, the
 * "dependents" are defined as all vertices.
 * //w w  w  .  j av  a2 s  . c om
 * @param job
 *            completed job's vertex, if applicable
 * @return dependent collection
 */
private Collection<V> getDependents(final V job) {
    if (graph.containsVertex(job)) {
        return Graphs.successorListOf(graph, job);
    }
    return Collections.EMPTY_SET;
}

From source file:org.vosao.search.impl.SearchIndexImpl.java

private Set<Long> getPageKeys(String word) {
    if (getIndex().containsKey(word)) {
        return getIndex().get(word);
    }/*  www  . jav a 2s.  com*/
    return Collections.EMPTY_SET;
}

From source file:org.onecmdb.core.internal.model.ModelService.java

public Set<ICi> getAllTemplates(IPath<String> path) {
    ICi base = null;// w  ww. j av  a 2  s. com
    if (path != null) {
        base = findCi(path);
        if (base == null) {
            return (Collections.EMPTY_SET);
        }
    }

    /*
    HashMap<String, Object> crit = new HashMap<String, Object>();
    crit.put("isBlueprint", Boolean.TRUE);
    List<ICi> list = (List<ICi>) daoReader.query(ConfigurationItem.class, crit);
    //List<ICi> list = daoReader.sqlQuery("select {ci.*} from CI {ci} where isBlueprint = 'true'");
     */
    /*
    String hqlQuery = "from ICi ci where ci.class = ConfigurationItem ans ci.isBlueprint='true'";
    List<ICi> list = daoReader.hqlQuery(hqlQuery);
    */
    //List<ICi> list = daoReader.sqlQuery("select {ci.*} from CI {ci} where ci.isBlueprint = 'true'");

    HashMap<String, Object> crit = new HashMap<String, Object>();
    crit.put("isBlueprint", Boolean.TRUE);
    List<ICi> list = (List<ICi>) daoReader.query(ConfigurationItem.class, crit);

    HashSet<ICi> set = new HashSet<ICi>();
    if (base == null) {
        set.addAll(list);
    } else {
        for (ICi ci : list) {
            if (isOffspringOf(base, ci) && !ci.equals(base)) {
                set.add(ci);
            }
        }
    }
    return (set);
}

From source file:org.jactr.modules.pm.aural.audicon.map.OnsetFeatureMap.java

protected Collection<IIdentifier> equal(Double when) {
    Set<IIdentifier> identifiers = _onsetMap.get(when);
    if (identifiers == null)
        identifiers = Collections.EMPTY_SET;
    return identifiers;
}

From source file:org.apache.cocoon.servletservice.ServletServiceContext.java

public Set getResourcePaths(String path) {
    if (path == null) {
        return Collections.EMPTY_SET;
    }//from   ww  w. j  a  v a2 s. c  om

    String pathPrefix;
    if (this.contextPath.startsWith("file:")) {
        pathPrefix = this.contextPath.substring("file:".length());
    } else {
        pathPrefix = this.contextPath;
    }

    path = pathPrefix + path;

    File file = new File(path);

    if (!file.exists()) {
        return Collections.EMPTY_SET;
    }

    HashSet set = new HashSet();
    set.addAll(getDirectoryList(file, pathPrefix));

    return set;
}

From source file:edu.northwestern.bioinformatics.studycalendar.dataproviders.coppa.CoppaStudySiteProvider.java

@SuppressWarnings("unchecked")
private Set<String> collectStudyProtocolIdentifiers(gov.nih.nci.coppa.services.pa.StudySite[] raw) {
    if (raw == null || raw.length <= 0) {
        return Collections.EMPTY_SET;
    }/* ww  w. ja  v a  2  s.  com*/

    return new HashSet(collect(Arrays.asList(raw), new Transformer() {
        public Object transform(Object o) {
            gov.nih.nci.coppa.services.pa.StudySite s = (gov.nih.nci.coppa.services.pa.StudySite) o;
            if (s != null && s.getStudyProtocolIdentifier() != null) {
                return s.getStudyProtocolIdentifier().getExtension();
            }
            return null;
        }
    }));
}

From source file:org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupMembershipManager.java

public Set<ScimGroup> getDefaultUserGroups(IdentityZone zone) {
    Set<ScimGroup> groups = defaultUserGroups.get(zone);
    if (groups == null) {
        return Collections.EMPTY_SET;
    }//from   ww w .j  a v a2 s.c o  m
    return groups;
}

From source file:com.adaptris.core.marshaller.xstream.AliasedElementReflectionConverter.java

protected void doMarshal(final Object source, final HierarchicalStreamWriter writer,
        final MarshallingContext context) {
    final List<FieldInfo> fields = new ArrayList<>();
    final Map<String, java.lang.reflect.Field> defaultFieldDefinition = new HashMap<>();

    // Attributes might be preferred to child elements ...
    reflectionProvider.visitSerializableFields(source, new ReflectionProvider.Visitor() {
        final Set<String> writtenAttributes = new HashSet<>();

        public void visit(String fieldName, Class type, Class definedIn, Object value) {
            if (!mapper.shouldSerializeMember(definedIn, fieldName)) {
                return;
            }//from   w w w .j  a v  a 2 s.c o m
            if (!defaultFieldDefinition.containsKey(fieldName)) {
                Class lookupType = source.getClass();
                // See XSTR-457 and OmitFieldsTest
                if (definedIn != source.getClass() && !mapper.shouldSerializeMember(lookupType, fieldName)) {
                    lookupType = definedIn;
                }
                defaultFieldDefinition.put(fieldName, reflectionProvider.getField(lookupType, fieldName));
            }

            SingleValueConverter converter = mapper.getConverterFromItemType(fieldName, type, definedIn);
            if (converter != null) {
                final String attribute = mapper
                        .aliasForAttribute(mapper.serializedMember(definedIn, fieldName));
                if (value != null) {
                    if (writtenAttributes.contains(fieldName)) { // TODO: use attribute
                        throw new ConversionException("Cannot write field with name '" + fieldName
                                + "' twice as attribute for object of type " + source.getClass().getName());
                    }
                    final String str = converter.toString(value);
                    if (str != null) {
                        writer.addAttribute(attribute, str);
                    }
                }
                writtenAttributes.add(fieldName); // TODO: use attribute
            } else {
                fields.add(new FieldInfo(fieldName, type, definedIn, value));
            }
        }
    });

    new Object() {
        {
            for (Iterator<FieldInfo> fieldIter = fields.iterator(); fieldIter.hasNext();) {
                FieldInfo info = (FieldInfo) fieldIter.next();
                // Check if the field is not null, we don't output null fields
                if (info.value != null) {
                    Mapper.ImplicitCollectionMapping mapping = mapper
                            .getImplicitCollectionDefForFieldName(source.getClass(), info.fieldName);
                    if (mapping != null) {
                        if (context instanceof ReferencingMarshallingContext) {
                            if (info.value != Collections.EMPTY_LIST && info.value != Collections.EMPTY_SET
                                    && info.value != Collections.EMPTY_MAP) {
                                ReferencingMarshallingContext refContext = (ReferencingMarshallingContext) context;
                                refContext.registerImplicit(info.value);
                            }
                        }
                        final boolean isCollection = info.value instanceof Collection;
                        final boolean isMap = info.value instanceof Map;
                        final boolean isEntry = isMap && mapping.getKeyFieldName() == null;
                        final boolean isArray = info.value.getClass().isArray();

                        for (Iterator iter = isArray ? new ArrayIterator(info.value)
                                : isCollection ? ((Collection) info.value).iterator()
                                        : isEntry ? ((Map) info.value).entrySet().iterator()
                                                : ((Map) info.value).values().iterator(); iter.hasNext();) {
                            Object obj = iter.next();
                            final String itemName;
                            final Class itemType;
                            if (obj == null) {
                                itemType = Object.class;
                                itemName = mapper.serializedClass(null);
                            } else if (isEntry) {
                                final String entryName = mapping.getItemFieldName() != null
                                        ? mapping.getItemFieldName()
                                        : mapper.serializedClass(Map.Entry.class);
                                Map.Entry entry = (Map.Entry) obj;
                                ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName,
                                        entry.getClass());
                                writeItem(entry.getKey(), context, writer);
                                writeItem(entry.getValue(), context, writer);
                                writer.endNode();
                                continue;
                            } else if (mapping.getItemFieldName() != null) {
                                itemType = mapping.getItemType();
                                itemName = mapping.getItemFieldName();
                            } else {
                                itemType = obj.getClass();
                                itemName = mapper.serializedClass(itemType);
                            }
                            writeField(info.fieldName, itemName, itemType, info.definedIn, obj);
                        }
                    }
                    // Field is not an implicit collection
                    else {
                        writeField(info.fieldName, null, info.type, info.definedIn, info.value);
                    }
                }
            }
        }

        //      void writeFieldStandard(String fieldName, String aliasName, Class fieldType, Class definedIn, Object newObj) {
        //        Class actualType = newObj != null ? newObj.getClass() : fieldType;
        //        ExtendedHierarchicalStreamWriterHelper.startNode(
        //            writer,
        //            aliasName != null ? aliasName : mapper.serializedMember(
        //                source.getClass(), fieldName), actualType);
        //
        //        // We don't process null fields (field values)
        //        if (newObj != null) {
        //          Class defaultType = mapper.defaultImplementationOf(fieldType);
        //          if (!actualType.equals(defaultType)) {
        //            String serializedClassName = mapper.serializedClass(actualType);
        //            if (!serializedClassName
        //                .equals(mapper.serializedClass(defaultType))) {
        //              String attributeName = mapper.aliasForSystemAttribute("class");
        //              if (attributeName != null) {
        //                writer.addAttribute(attributeName, serializedClassName);
        //              }
        //            }
        //          }
        //
        //          final Field defaultField = (Field) defaultFieldDefinition
        //              .get(fieldName);
        //          if (defaultField.getDeclaringClass() != definedIn) {
        //            String attributeName = mapper.aliasForSystemAttribute("defined-in");
        //            if (attributeName != null) {
        //              writer.addAttribute(attributeName,
        //                  mapper.serializedClass(definedIn));
        //            }
        //          }
        //
        //          Field field = reflectionProvider.getField(definedIn, fieldName);
        //          marshallField(context, newObj, field);
        //        }
        //        writer.endNode();
        //      }

        // Modified version of method from that super class
        void writeField(String fieldName, String aliasName, Class fieldType, Class definedIn, Object newObj) {
            Class<?> actualType = newObj != null ? newObj.getClass() : fieldType;
            String elementName = aliasName != null ? aliasName
                    : mapper.serializedMember(source.getClass(), fieldName);

            String classAttributeName = null;
            String definedAttributeName = null;
            // We don't process null fields (field values)
            if (newObj != null) {
                Class defaultType = mapper.defaultImplementationOf(fieldType);
                if (!actualType.equals(defaultType)) {
                    String serializedClassName = mapper.serializedClass(actualType);
                    if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
                        classAttributeName = mapper.aliasForSystemAttribute("class");
                    }
                }

                final Field defaultField = (Field) defaultFieldDefinition.get(fieldName);
                if (defaultField.getDeclaringClass() != definedIn) {
                    definedAttributeName = mapper.aliasForSystemAttribute("defined-in");
                }
            }

            writeOutElementBasedOnClassType(elementName, definedIn, actualType, classAttributeName,
                    definedAttributeName);
            if (newObj != null) {
                Field field = reflectionProvider.getField(definedIn, fieldName);
                marshallField(context, newObj, field);
            }
            writer.endNode();
        }

        // Now where the super class would have written out the field name
        // followed by a class attribute that contained the subclass name,
        // we will write out the subclass alias name as the element with no
        // class attribute at all.
        private void writeOutElementBasedOnClassType(String elementName, Class definedIn, Class<?> actualType,
                String classAttributeName, String definedAttributeName) {
            boolean isClassAttributeSet = !StringUtils.isBlank(classAttributeName);
            if (isClassAttributeSet) {
                String serializedClassName = mapper.serializedClass(actualType);
                ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedClassName, actualType);
            } else {
                String serializedClassName = mapper.serializedClass(actualType);

                ExtendedHierarchicalStreamWriterHelper.startNode(writer, elementName, actualType);
                if (classAttributeName != null) {
                    writer.addAttribute(classAttributeName, serializedClassName);
                }
                if (definedAttributeName != null) {
                    writer.addAttribute(definedAttributeName, mapper.serializedClass(definedIn));
                }
            }
        }

        void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
            if (item == null) {
                String name = mapper.serializedClass(null);
                ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, Mapper.Null.class);
                writer.endNode();
            } else {
                String name = mapper.serializedClass(item.getClass());
                ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, item.getClass());
                context.convertAnother(item);
                writer.endNode();
            }
        }
    };
}

From source file:org.apache.camel.impl.DefaultPackageScanClassResolver.java

@SuppressWarnings("unchecked")
public Set<Class<?>> findByFilter(PackageScanFilter filter, String... packageNames) {
    if (packageNames == null) {
        return Collections.EMPTY_SET;
    }/*  www  .  j a va 2 s.  c  om*/

    Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
    for (String pkg : packageNames) {
        find(filter, pkg, classes);
    }

    if (log.isDebugEnabled()) {
        log.debug("Found: " + classes);
    }

    return classes;
}