Example usage for com.google.common.collect ImmutableCollection.Builder add

List of usage examples for com.google.common.collect ImmutableCollection.Builder add

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableCollection.Builder add.

Prototype

public final boolean add(E e) 

Source Link

Usage

From source file:org.fcrepo.kernel.rdf.impl.NamespaceRdfContext.java

/**
 * Default constructor. Loads context with RDF describing namespaces in
 * scope in the repository./* ww  w.j a  v  a 2 s  .com*/
 *
 * @param session
 * @throws RepositoryException
 */
public NamespaceRdfContext(final Session session) throws RepositoryException {
    super();
    final NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry();
    checkNotNull(namespaceRegistry, "Couldn't find namespace registry in repository!");

    final ImmutableMap.Builder<String, String> namespaces = ImmutableMap.builder();
    final ImmutableCollection.Builder<Triple> nsTriples = ImmutableSet.builder();
    for (String prefix : namespaceRegistry.getPrefixes()) {
        if (!prefix.isEmpty()) {
            final String nsURI = namespaceRegistry.getURI(prefix);
            if (prefix.equals("jcr")) {
                prefix = "fcrepo";
            }
            LOGGER.trace("Discovered namespace prefix \"{}\" with URI \"{}\"", prefix, nsURI);
            final String rdfNsUri = getRDFNamespaceForJcrNamespace(nsURI);
            // first, let's put the namespace in context
            namespaces.put(prefix, rdfNsUri);
            LOGGER.trace("Added namespace prefix \"{}\" with URI \"{}\"", prefix, rdfNsUri);
            final Node nsSubject = createURI(rdfNsUri);
            // now, some triples describing this namespace
            nsTriples.add(create(nsSubject, type.asNode(), VOAF_VOCABULARY.asNode()));
            nsTriples.add(create(nsSubject, HAS_NAMESPACE_PREFIX.asNode(), createLiteral(prefix)));
            nsTriples.add(create(nsSubject, HAS_NAMESPACE_URI.asNode(), createLiteral(rdfNsUri)));
        }
    }
    concat(nsTriples.build()).namespaces(namespaces.build());
}

From source file:com.wolvereness.overmapped.MembersSubRoutine.java

@Override
public void invoke(final OverMapped instance, final Map<String, ByteClass> classes,
        final Multimap<String, String> depends, final Multimap<String, String> rdepends,
        final BiMap<String, String> nameMaps, final BiMap<String, String> inverseNameMaps,
        final BiMap<Signature, Signature> signatureMaps, final BiMap<Signature, Signature> inverseSignatureMaps,
        final Remapper inverseMapper, final MutableSignature mutableSignature, final Set<String> searchCache,
        final Map<Signature, Integer> flags, final Map<?, ?> map)
        throws ClassCastException, NullPointerException, MojoFailureException {
    final Object memberMaps = map.get(tag);
    if (!(memberMaps instanceof Map))
        return;//from w w w  .ja  v a 2 s.c  om

    final Store store = new Store(searchCache, instance.isFindParents() ? new HashSet<String>() : null,
            instance);

    for (final Map.Entry<?, ?> memberMap : ((Map<?, ?>) memberMaps).entrySet()) {
        final Map<?, ?> maps = asType(memberMap.getValue(),
                "`%4$s' points to a %2$s `%1$s', expected a %5$s, in `%3$s'", false, memberMaps, memberMap,
                Map.class);

        if (memberMap.getKey() instanceof Collection<?> && ((Collection<?>) memberMap.getKey()).size() > 1) {
            final Iterable<String> classNames;
            {
                final ImmutableCollection.Builder<String> containingClassNames = ImmutableList.builder();
                for (final Object clazz : (Collection<?>) memberMap.getKey()) {
                    final String unresolvedClassName = asType(clazz,
                            "`%4$s' contains a %2$s `%1$s', expected a %5$s, from `%3$s'", false, memberMaps,
                            memberMap.getKey(), String.class);
                    final String className = inverseNameMaps.get(unresolvedClassName);
                    if (className == null) {
                        instance.missingAction.actMemberClass(instance.getLog(), unresolvedClassName,
                                memberMap.getKey(), inverseNameMaps);
                        continue;
                    }
                    containingClassNames.add(className);
                }
                classNames = containingClassNames.build();
            }

            for (final Map.Entry<?, ?> entry : maps.entrySet()) {
                parseMapping(store, inverseMapper, mutableSignature, maps, entry, false);
                final String newName = store.newName, oldName = store.oldName, description = store.description,
                        originalDescription = store.originalDescription;

                if (!mutableSignature.update("", "", description).isMethod())
                    throw new MojoFailureException(String
                            .format("Malformed mapping %s for %s; can only map methods.", entry, memberMap));

                for (final String className : classNames) {
                    updateMember(store, signatureMaps, inverseSignatureMaps, mutableSignature, oldName, newName,
                            description, className, nameMaps, originalDescription, nameMaps.get(className));

                    if (mutableSignature.isMethod() && !mutableSignature.isConstructor()) {
                        final Set<String> parents = store.parents;
                        if (parents != null) {
                            parents.addAll(depends.get(className));
                        }
                        for (final String inherited : rdepends.get(className)) {
                            if (!updateMember(store, signatureMaps, inverseSignatureMaps, mutableSignature,
                                    oldName, newName, description, inherited, nameMaps, originalDescription,
                                    nameMaps.get(inherited)))
                                continue;

                            if (parents != null) {
                                parents.addAll(depends.get(inherited));
                            }
                        }
                    }
                }
                performParentChecks(store, nameMaps, inverseSignatureMaps, mutableSignature, classNames,
                        newName, oldName, description, originalDescription);
                store.searchCache.clear();
            }

            continue;
        }

        if (memberMap.getKey() instanceof Collection<?> && ((Collection<?>) memberMap.getKey()).size() < 1)
            throw new MojoFailureException(
                    String.format("Malformed mapping %s -> %s", memberMap.getKey(), maps));

        final String unresolvedClassName = asType(
                memberMap.getKey() instanceof Collection<?>
                        ? ((Collection<?>) memberMap.getKey()).iterator().next()
                        : memberMap.getKey(),
                "`%4$s' points from a %2$s `%1$s', expected a %5$s, in `%3$s'", false, memberMaps, memberMap,
                String.class);
        final String className = inverseNameMaps.get(unresolvedClassName);
        if (className == null) {
            instance.missingAction.actMemberClass(instance.getLog(), unresolvedClassName, memberMap.getKey(),
                    inverseNameMaps);
            continue;
        }

        for (final Map.Entry<?, ?> entry : maps.entrySet()) {
            processSingleClassMappings(store, classes, depends, rdepends, nameMaps, signatureMaps,
                    inverseSignatureMaps, inverseMapper, mutableSignature, maps, className, unresolvedClassName,
                    entry);
        }
    }
}