Example usage for com.google.common.collect Iterables filter

List of usage examples for com.google.common.collect Iterables filter

Introduction

In this page you can find the example usage for com.google.common.collect Iterables filter.

Prototype

@GwtIncompatible("Class.isInstance")
@CheckReturnValue
public static <T> Iterable<T> filter(final Iterable<?> unfiltered, final Class<T> desiredType) 

Source Link

Document

Returns all elements in unfiltered that are of the type desiredType .

Usage

From source file:edu.umn.msi.tropix.persistence.service.impl.utils.PersistenceModelUtils.java

public static <T extends TropixObject> Iterable<T> typeFilter(final Iterable<T> objects,
        final Iterable<TropixObjectType> types) {
    return Iterables.filter(objects, new Predicate<TropixObject>() {
        public boolean apply(final TropixObject object) {
            return Iterables.any(types, new Predicate<TropixObjectType>() {
                public boolean apply(final TropixObjectType type) {
                    return type.isInstance(object);
                }/*from  w w  w  . j av  a  2s  . c  om*/
            });
        }
    });
}

From source file:org.janusgraph.util.datastructures.IterablesUtil.java

public static final <O> Iterable<O> limitedIterable(final Iterable<O> iterable, final int limit) {
    return Iterables.filter(iterable, new Predicate<O>() {

        int count = 0;

        @Override//from ww  w.j a  v a 2s .  c o  m
        public boolean apply(@Nullable O o) {
            count++;
            return count <= limit;
        }
    });
}

From source file:org.trnltk.util.DiffUtil.java

public static String[] diffLines(final String line1, final String line2, final boolean ignoreWhiteSpace) {
    final diff_match_patch dmp = new diff_match_patch();

    final LinkedList<diff_match_patch.Diff> diffs = dmp.diff_main(line1, line2);

    if (CollectionUtils.isEmpty(diffs)) {
        return null;
    } else {//w ww  . j a  v  a2s. com
        if (ignoreWhiteSpace) {
            final LinkedList<diff_match_patch.Diff> filteredDiffs = Lists
                    .newLinkedList(Iterables.filter(diffs, new Predicate<diff_match_patch.Diff>() {
                        @Override
                        public boolean apply(diff_match_patch.Diff input) {
                            if (input.operation.equals(diff_match_patch.Operation.EQUAL))
                                return false;
                            else if (StringUtils.isBlank(input.text))
                                return false;

                            return true;
                        }
                    }));

            if (filteredDiffs.isEmpty())
                return null;
        }

        dmp.diff_cleanupSemantic(diffs);

        final String[] diffLines = diffToFormattedLines(diffs, ignoreWhiteSpace);
        if (ignoreWhiteSpace) {
            if (StringUtils.isBlank(diffLines[1]) && StringUtils.isBlank(diffLines[2]))
                return null;
        }

        return diffLines;
    }
}

From source file:com.zimbra.soap.admin.type.Stat.java

public static Iterator<Stat> filterByName(Iterable<Stat> unfiltered, String statName) {
    return Iterables.filter(unfiltered, new FilterByName(statName)).iterator();
}

From source file:org.incode.module.commchannel.dom.impl.type.CommunicationChannelType.java

public static List<CommunicationChannelType> matching(final Class<? extends CommunicationChannel> cls) {
    return Lists.newArrayList(Iterables.filter(Arrays.asList(values()), input -> input.cls == cls));
}

From source file:org.eclipse.xtext.scoping.Scopes.java

public static Iterable<IEObjectDescription> selectCompatible(Iterable<IEObjectDescription> exportedObjects,
        final EClass clazz) {
    return Iterables.filter(exportedObjects, new Predicate<IEObjectDescription>() {
        @Override//w  w  w.  j  a v a2 s  .  com
        public boolean apply(IEObjectDescription input) {
            return EcoreUtil2.isAssignableFrom(clazz, input.getEClass());
        }
    });
}

From source file:com.android.builder.internal.aapt.AaptUtils.java

/**
 * Obtains resource configs that are densities.
 *
 * @param configs the resource configs/*from   w  w w  . ja  v a2s. c  o m*/
 * @return resource configs that are recognized as densities as per
 * {@link Density#getEnum(String)}
 */
public static Iterable<String> getDensityResConfigs(@NonNull Iterable<String> configs) {
    return Iterables.filter(configs, IS_DENSITY);
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.util.BendpointsHelper.java

/**
 * Checks whether two objects are lists of GMF Bendpoints which are
 * equivalent (i.e. the same number of points with the same coordinates in
 * the same order)./*  w  ww. ja v a  2 s.c  o  m*/
 * 
 * @param oldValue
 *            the first (old) value.
 * @param newValue
 *            the second (new) value.
 * @return <code>true</code> if the two given values are equivalent lists of
 *         GMF Bendpoints.
 */
public static boolean areSameBendpoints(Object oldValue, Object newValue) {
    boolean isTouch = false;
    if (oldValue instanceof Collection<?> && newValue instanceof Collection<?>) {
        List<RelativeBendpoint> newPoints = Lists
                .newArrayList(Iterables.filter((Collection<?>) newValue, RelativeBendpoint.class));
        List<RelativeBendpoint> oldPoints = Lists
                .newArrayList(Iterables.filter((Collection<?>) oldValue, RelativeBendpoint.class));
        if (newPoints.size() == oldPoints.size()) {
            isTouch = true;
            for (int i = 0; i < newPoints.size(); i++) {
                RelativeBendpoint newPoint = newPoints.get(i);
                RelativeBendpoint oldPoint = oldPoints.get(i);

                boolean sourceTouch = newPoint.getSourceX() == oldPoint.getSourceX()
                        && newPoint.getSourceY() == oldPoint.getSourceY();
                boolean targetTouch = newPoint.getTargetX() == oldPoint.getTargetX()
                        && newPoint.getTargetY() == oldPoint.getTargetY();

                if (!(sourceTouch && targetTouch)) {
                    isTouch = false;
                    break;
                }
            }
        }
    }
    return isTouch;
}

From source file:de.faustedition.Runtime.java

public static void main(Class<? extends Runnable> clazz, String[] args) throws IOException {
    Locale.setDefault(new Locale("en", "us"));

    File configFile = null;/*from   w  w  w  .ja v a 2  s .co m*/
    for (String arg : args) {
        if ("-debug".equalsIgnoreCase(arg)) {
        } else if (configFile == null) {
            configFile = new File(arg);
        }
    }

    final Logger rootLogger = Logger.getLogger("");
    for (ConsoleHandler ch : Iterables.filter(Arrays.asList(rootLogger.getHandlers()), ConsoleHandler.class)) {
        rootLogger.removeHandler(ch);
    }
    SLF4JBridgeHandler.install();

    final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            new String[] { "/application-context.xml" }, false);

    final MutablePropertySources ps = applicationContext.getEnvironment().getPropertySources();
    ps.addLast(new PropertiesPropertySource("system", System.getProperties()));
    if (configFile != null) {
        ps.addLast(new ResourcePropertySource(new FileSystemResource(configFile)));
    }
    ps.addLast(new ResourcePropertySource("classpath:/config-default.properties"));

    applicationContext.registerShutdownHook();
    applicationContext.refresh();
    applicationContext.getBean(clazz).run();
}

From source file:com.eviware.loadui.ui.fx.views.workspace.SystemPropertiesDialog.java

public static void initialize() {
    ArrayList<String> list = Lists
            .newArrayList(Iterables.filter(System.getProperties().keySet(), String.class));
    Collections.sort(list);/*from  w w  w  .j a  v a  2s .  com*/
    properties.setAll(list);
}