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:at.ac.univie.isc.asio.insight.VndError.java

/**
 * Circular reference safe root finder.//  w  ww  .j  a va 2s.  c  om
 *
 * @param throwable any non-null exception
 * @return root exception or an AssertionError if a circular reference is detected
 */
private static Throwable findRoot(Throwable throwable) {
    final Set<Throwable> seen = Sets.newIdentityHashSet();
    seen.add(throwable);
    Throwable cause;
    while ((cause = throwable.getCause()) != null) {
        throwable = cause;
        if (!seen.add(throwable)) {
            return circularPlaceholder(throwable);
        }
    }
    return throwable;
}

From source file:com.yahoo.yqlplus.engine.internal.plan.ast.OperatorStep.java

@Override
public Set<? extends Value> getInputs() {
    if (compute != null) {
        final Set<Value> inputs = Sets.newIdentityHashSet();
        compute.visitNode(new OperatorTreeVisitor() {
            @Override//from w ww .j a v a 2 s . c o m
            public void visit(Object arg) {
                if (arg instanceof Value) {
                    inputs.add((Value) arg);
                }
            }
        });
        inputs.addAll(before);
        return inputs;
    } else {
        return before;
    }
}

From source file:com.github.benmanes.caffeine.IsValidConcurrentLinkedStack.java

void checkForLoop(ConcurrentLinkedStack<E> stack, DescriptionBuilder builder) {
    Set<Node<E>> seen = Sets.newIdentityHashSet();
    Node<E> node = stack.top;
    while (node != null) {
        if (node.get() != null) {
            Node<E> current = node;
            Supplier<String> errorMsg = () -> String.format("Loop detected: %s in %s", current, seen);
            builder.expectThat(errorMsg, seen.add(node), is(true));
            builder.expectThat("not completed", node.isDone(), is(true));
        }//w  ww  .  j a v  a  2s .  c om
        node = node.next;
    }
    builder.expectThat("stack size", stack, hasSize(seen.size()));
}

From source file:co.cask.cdap.internal.io.ReflectionPutWriter.java

@Override
public void write(T object, Put put) throws IOException {
    index = 0;// ww  w  .j a  va 2 s.  co m
    seenRefs = Sets.newIdentityHashSet();
    super.writeRecord(put, object, schema);
}

From source file:com.github.benmanes.caffeine.cache.IsValidLinkedDeque.java

void checkIterator(LinkedDeque<E> deque, Iterator<E> iterator, DescriptionBuilder desc) {
    Set<E> seen = Sets.newIdentityHashSet();
    while (iterator.hasNext()) {
        E element = iterator.next();/*from   www.  j  a v  a 2 s.c om*/
        checkElement(deque, element, desc);
        Supplier<String> errorMsg = () -> String.format("Loop detected: %s in %s", element, seen);
        desc.expectThat(errorMsg, seen.add(element), is(true));
    }
    desc.expectThat("deque size", deque, hasSize(seen.size()));
}

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

void checkIterator(Deque<? extends Linked<? extends E>> deque, Iterator<? extends Linked<? extends E>> iterator,
        DescriptionBuilder builder) {/*from w  w  w. j av a2 s.com*/
    Set<Linked<?>> seen = Sets.newIdentityHashSet();
    while (iterator.hasNext()) {
        Linked<?> element = iterator.next();
        checkElement(deque, element, builder);
        String errorMsg = String.format("Loop detected: %s in %s", element, seen);
        builder.expectThat(errorMsg, seen.add(element), is(true));
    }
    builder.expectThat(deque, hasSize(seen.size()));
}

From source file:com.github.benmanes.caffeine.IsValidConcurrentLinkedLazyQueue.java

void checkForLoop(ConcurrentLinkedLazyQueue<E> queue, DescriptionBuilder builder) {
    Set<Node<E>> seen = Sets.newIdentityHashSet();
    Node<E> node = queue.head.next;
    while (node != null) {
        Node<E> current = node;
        Supplier<String> errorMsg = () -> String.format("Loop detected: %s in %s", current, seen);
        builder.expectThat(errorMsg, seen.add(node), is(true));
        builder.expectThat("not tail", node, is(not(queue.head)));
        builder.expectThat("not completed", node.isDone(), is(true));
        builder.expectThat("not null value", node.value, is(not(nullValue())));

        builder.expectThat("links", node.prev.next, is(node));
        node = node.next;/*from   www  . ja  v  a  2 s . com*/
    }
    builder.expectThat("queue size", queue, hasSize(seen.size()));
}

From source file:com.github.benmanes.caffeine.IsValidSingleConsumerQueue.java

void checkForLoop(SingleConsumerQueue<E> queue, DescriptionBuilder builder) {
    builder.expectThat("Expected sentinel node", queue.head.value, is(nullValue()));
    Set<Node<E>> seen = Sets.newIdentityHashSet();
    Node<E> node = queue.head.next;
    while (node != null) {
        Node<E> current = node;
        Supplier<String> errorMsg = () -> String.format("Loop detected: %s in %s", current, seen);
        builder.expectThat(errorMsg, seen.add(node), is(true));
        builder.expectThat("not tail", node, is(not(queue.head)));
        builder.expectThat("not completed", node.isDone(), is(true));
        builder.expectThat("not null value", node.value, is(not(nullValue())));
        node = node.next;/*from  www.  j a v a2  s.c o  m*/
    }
    builder.expectThat("queue size", queue, hasSize(seen.size()));
}

From source file:co.cask.cdap.data.dataset.DatasetInstantiator.java

/**
 * Constructor from data fabric.//from   w w w . j ava  2s  .c  om
 *
 * @param namespace the {@link Id.Namespace} in which this dataset is used
 * @param datasetFramework the dataset framework to use to get datasets
 * @param owners the {@link Id} which is using this dataset
 * @param classLoader the class loader to use for loading dataset classes
 * @param metricsContext the metrics context to use for collecting dataset metrics.
 *                         If null, no metrics are collected
 */
public DatasetInstantiator(Id.Namespace namespace, DatasetFramework datasetFramework, ClassLoader classLoader,
        @Nullable Iterable<? extends Id> owners, @Nullable MetricsContext metricsContext) {
    this.namespace = namespace;
    this.metricsContext = metricsContext;
    this.txAware = Sets.newIdentityHashSet();
    this.datasetInstantiator = new SystemDatasetInstantiator(datasetFramework, classLoader,
            new ConstantClassLoaderProvider(classLoader), owners);
}

From source file:com.haulmont.cuba.core.app.CrossDataStoreReferenceLoader.java

public Map<Class<? extends Entity>, List<CrossDataStoreProperty>> getCrossPropertiesMap() {
    Map<Class<? extends Entity>, List<CrossDataStoreProperty>> crossPropertiesMap = new HashMap<>();
    traverseView(view, crossPropertiesMap, Sets.newIdentityHashSet());
    return crossPropertiesMap;
}