Example usage for com.google.common.collect Sets newIdentityHashSet

List of usage examples for com.google.common.collect Sets newIdentityHashSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newIdentityHashSet.

Prototype

public static <E> Set<E> newIdentityHashSet() 

Source Link

Document

Creates an empty Set that uses identity to determine equality.

Usage

From source file:co.cask.tigon.lang.ClassLoaders.java

/**
 * Returns the ClassLoader of the given type. If the given type is a {@link java.lang.reflect.ParameterizedType},
 * it returns a {@link CombineClassLoader} of all types. The context ClassLoader or System ClassLoader would be used
 * as the parent of the CombineClassLoader.
 *
 * @return A new CombineClassLoader. If no ClassLoader is found from the type,
 *         it returns the current thread context ClassLoader if it's not null, otherwise, return system ClassLoader.
 *//*from ww w .  j a  va2 s .c  o m*/
public static ClassLoader getClassLoader(TypeToken<?> type) {
    Set<ClassLoader> classLoaders = Sets.newIdentityHashSet();

    // Breath first traversal into the Type.
    Queue<TypeToken<?>> queue = Lists.newLinkedList();
    queue.add(type);
    while (!queue.isEmpty()) {
        type = queue.remove();
        ClassLoader classLoader = type.getRawType().getClassLoader();
        if (classLoader != null) {
            classLoaders.add(classLoader);
        }

        if (type.getType() instanceof ParameterizedType) {
            for (Type typeArg : ((ParameterizedType) type.getType()).getActualTypeArguments()) {
                queue.add(TypeToken.of(typeArg));
            }
        }
    }

    // Determine the parent classloader
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    ClassLoader parent = (contextClassLoader == null) ? ClassLoader.getSystemClassLoader() : contextClassLoader;

    if (classLoaders.isEmpty()) {
        return parent;
    }
    return new CombineClassLoader(parent, classLoaders);
}

From source file:com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport.java

protected static Set<Entity> createEntitySet() {
    return Sets.newIdentityHashSet();
}

From source file:org.sosy_lab.cpachecker.cpa.value.symbolic.refiner.ARGTreePrecisionUpdater.java

private VariableTrackingPrecision mergeValuePrecisionsForSubgraph(final ARGState pRefinementRoot,
        final ARGReachedSet pReached) {
    // get all unique precisions from the subtree
    Set<VariableTrackingPrecision> uniquePrecisions = Sets.newIdentityHashSet();

    for (ARGState descendant : getNonCoveredStatesInSubgraph(pRefinementRoot)) {
        uniquePrecisions.add(extractValuePrecision(pReached, descendant));
    }/*from ww  w  . j  av  a  2 s  . c  o  m*/

    // join all unique precisions into a single precision
    VariableTrackingPrecision mergedPrecision = Iterables.getLast(uniquePrecisions);
    for (VariableTrackingPrecision precision : uniquePrecisions) {
        mergedPrecision = mergedPrecision.join(precision);
    }

    return mergedPrecision;
}

From source file:com.google.inject.servlet.ManagedFilterPipeline.java

public synchronized void initPipeline(ServletContext servletContext) throws ServletException {

    //double-checked lock, prevents duplicate initialization
    if (initialized)
        return;//from  w  w w .ja  v  a2 s .c o m

    // Used to prevent duplicate initialization.
    Set<Filter> initializedSoFar = Sets.newIdentityHashSet();

    for (FilterDefinition filterDefinition : filterDefinitions) {
        filterDefinition.init(servletContext, injector, initializedSoFar);
    }

    //next, initialize servlets...
    servletPipeline.init(servletContext, injector);

    //everything was ok...
    initialized = true;
}

From source file:com.google.inject.servlet.ManagedServletPipeline.java

public void destroy() {
    Set<HttpServlet> destroyedSoFar = Sets.newIdentityHashSet();
    for (ServletDefinition servletDefinition : servletDefinitions) {
        servletDefinition.destroy(destroyedSoFar);
    }//  w  ww  .jav  a  2s.  c  o  m
}

From source file:org.ldp4j.application.data.validation.Validator.java

private Validator() {
    this.dataSetVC = Lists.newArrayList();
    this.individualVC = Lists.newArrayList();
    this.propertyVC = Lists.newArrayList();
    this.checkedVC = Sets.newIdentityHashSet();
}

From source file:com.google.inject.servlet.DynamicFilterPipeline.java

@Override
public void destroyPipeline() {
    servletPipeline.destroy();/*from  w  w  w  . ja v  a2 s .co m*/

    Set<Filter> destroyedSoFar = Sets.newIdentityHashSet();
    for (FilterDefinition filterDefinition : filterDefinitions()) {
        filterDefinition.destroy(destroyedSoFar);
    }
}

From source file:com.haulmont.cuba.core.sys.EntityManagerImpl.java

@Override
public <T extends Entity> T merge(T entity) {
    log.debug("merge {}", entity);

    if (PersistenceHelper.isManaged(entity))
        return entity;

    String storeName = support.getStorageName(delegate.unwrap(UnitOfWork.class));
    entityListenerMgr.fireListener(entity, EntityListenerType.BEFORE_ATTACH, storeName);

    if ((PersistenceHelper.isNew(entity) || !PersistenceHelper.isDetached(entity)) && entity.getId() != null) {
        // if a new instance is passed to merge(), we suppose it is persistent but "not detached"
        Entity destEntity = findOrCreate(entity.getClass(), entity.getId());
        deepCopyIgnoringNulls(entity, destEntity, Sets.newIdentityHashSet());
        //noinspection unchecked
        return (T) destEntity;
    }/*from  w  ww  .j a  v  a  2  s . c  o m*/

    T merged = internalMerge(entity);
    support.registerInstance(merged, this);
    return merged;
}

From source file:com.googlecode.concurrentlinkedhashmap.IsValidConcurrentLinkedHashMap.java

@SuppressWarnings("rawtypes")
private void checkLinks(ConcurrentLinkedHashMap<? extends K, ? extends V> map, DescriptionBuilder builder) {
    long weightedSize = 0;
    Set<Node> seen = Sets.newIdentityHashSet();
    for (Node node : map.evictionDeque) {
        String errorMsg = String.format("Loop detected: %s, saw %s in %s", node, seen, map);
        builder.expectThat(errorMsg, seen.add(node), is(true));
        weightedSize += ((WeightedValue) node.get()).weight;
        checkNode(map, node, builder);//from w w w. j ava  2  s .  c  om
    }

    builder.expectThat("Size != list length", map.size(), is(seen.size()));
    builder.expectThat(
            "WeightedSize != link weights" + " [" + map.weightedSize() + " vs. " + weightedSize + "]"
                    + " {size: " + map.size() + " vs. " + seen.size() + "}",
            map.weightedSize(), is(weightedSize));
}

From source file:org.fao.geonet.api.records.formatters.groovy.TransformEngine.java

private void processChildren(TransformationContext context, GPathResult md, List<GPathResult> sortedChildren,
        StringBuilder resultantXml) throws IOException {
    if (sortedChildren.isEmpty()) {
        return;/* w  w w . j  a  v  a  2s . c  o m*/
    }

    if (md != null) {
        Sorter sorter = this.handlers.findSorter(context, md);
        if (sorter != null) {
            Collections.sort(sortedChildren, sorter);
        }
    }

    final Set<GPathResult> visitedByGroup = Sets.newIdentityHashSet();
    int size = sortedChildren.size();
    for (int i = 0; i < size; i++) {
        GPathResult child = sortedChildren.get(i);

        if (!visitedByGroup.contains(child)) {
            visitedByGroup
                    .addAll(processElement(context, child, sortedChildren.subList(i + 1, size), resultantXml));
        }
    }
}