org.jgrapht.graph.MaskVertexSet Maven / Gradle / Ivy
/*
* (C) Copyright 2007-2017, by France Telecom and Contributors.
*
* JGraphT : a free Java graph-theory library
*
* This program and the accompanying materials are dual-licensed under
* either
*
* (a) the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation, or (at your option) any
* later version.
*
* or (per the licensee's choosing)
*
* (b) the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation.
*/
package org.jgrapht.graph;
import java.io.*;
import java.util.*;
import java.util.function.*;
import org.jgrapht.util.*;
/**
* Helper for {@link MaskSubgraph}.
*
* @author Guillaume Boulmier
* @since July 5, 2007
*/
class MaskVertexSet
extends AbstractSet
implements Serializable
{
private static final long serialVersionUID = 3751931017141472763L;
private final Set vertexSet;
private final Predicate mask;
public MaskVertexSet(Set vertexSet, Predicate mask)
{
this.vertexSet = vertexSet;
this.mask = mask;
}
/**
* {@inheritDoc}
*/
@Override
public boolean contains(Object o)
{
if (!vertexSet.contains(o)) {
return false;
}
V v = TypeUtil.uncheckedCast(o, null);
return !mask.test(v);
}
/**
* {@inheritDoc}
*/
@Override
public Iterator iterator()
{
return vertexSet.stream().filter(mask.negate()).iterator();
}
/**
* {@inheritDoc}
*/
@Override
public int size()
{
return (int) vertexSet.stream().filter(mask.negate()).count();
}
}
// End MaskVertexSet.java