Example usage for com.google.common.base Predicates not

List of usage examples for com.google.common.base Predicates not

Introduction

In this page you can find the example usage for com.google.common.base Predicates not.

Prototype

public static <T> Predicate<T> not(Predicate<T> predicate) 

Source Link

Document

Returns a predicate that evaluates to true if the given predicate evaluates to false .

Usage

From source file:org.nickelproject.util.testUtil.ClasspathUtil.java

private static Iterable<String> getClassPath() {
    // Removes some paths that eclipse adds during testing.
    return Iterables.filter(Lists.newArrayList(System.getProperty("java.class.path").split(File.pathSeparator)),
            Predicates.not(Predicates.containsPattern(Pattern.quote(kEclipseFilter))));
}

From source file:com.google.api.tools.framework.model.MessageType.java

/**
 * Returns all fields which have non-message type.
 *//*from  w ww. j av  a  2 s .co  m*/
public Iterable<Field> getNonMessageFields() {
    return FluentIterable.from(fields).filter(Predicates.not(Field.HAS_MESSAGE_TYPE));
}

From source file:org.carrot2.workbench.core.ui.AttributeGroups.java

/**
 * Create editors based on the given {@link GroupingMethod}.
 *///from   w w  w.  j ava  2s  .  c om
private void createEditors(Composite parent) {
    /*
     * Create a filtered view of attribute descriptors.
     */
    BindableDescriptor descriptor = this.descriptor.only(Predicates.not(new InternalAttributePredicate(false)))
            .only(new HasEditorPredicate());
    if (filterPredicate != null) {
        descriptor = descriptor.only(filterPredicate);
    }

    /*
     * CARROT-818: Check if there is anything for display. 
     */
    if (descriptor.attributeDescriptors.isEmpty()) {
        createMessage(mainControl, this, "No attributes.");
    }

    /*
     * Group attributes.
     */
    descriptor = descriptor.group(grouping);

    /*
     * Create sections for attribute groups.
     */
    for (Object groupKey : descriptor.attributeGroups.keySet()) {
        final String groupLabel;
        if (groupKey instanceof Class<?>) {
            groupLabel = ((Class<?>) groupKey).getSimpleName();
        } else {
            // Anything else, we simply convert to a string.
            groupLabel = StringUtils.abbreviate(groupKey.toString(), 160);
        }

        createEditorGroup(mainControl, groupKey.toString(), groupLabel, descriptor,
                descriptor.attributeGroups.get(groupKey), this);
    }

    /*
     * If we have a NONE grouping, then skip creating section headers.
     */
    if (grouping == GroupingMethod.NONE) {
        if (descriptor.attributeGroups.size() > 0) {
            Utils.logError("There should be no groups if grouping is NONE.", false);
        }

        if (!descriptor.attributeDescriptors.isEmpty()) {
            createUntitledEditorGroup(mainControl, descriptor, descriptor.attributeDescriptors, this);
        }
    } else {
        /*
         * Otherwise, add remaining attributes under a synthetic group.
         */
        if (!descriptor.attributeDescriptors.isEmpty()) {
            createEditorGroup(mainControl, UNGROUPED_ATTRIBUTES_GROUP, UNGROUPED_ATTRIBUTES_GROUP, descriptor,
                    descriptor.attributeDescriptors, this);
        }
    }
}

From source file:edu.udo.scaffoldhunter.gui.dialogs.TooltipConfigurationDialog.java

private JPanel buildPropertyPanel() {
    FormLayout layout = new FormLayout("p, 3dlu, c:p:g(.5), 3dlu, c:p:g(.5)");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();//from  ww  w.  j  a  v a  2  s  .com

    List<PropertyDefinition> propDefs = Orderings.PROPERTY_DEFINITION_BY_TITLE
            .sortedCopy(dataset.getPropertyDefinitions().values());

    Collections.sort(propDefs, Orderings.PROPERTY_DEFINITION_BY_PROPERTY_TYPE);
    Iterable<PropertyDefinition> molPropDefs = Iterables.filter(propDefs,
            Predicates.not(SHPredicates.IS_SCAFFOLD_PROPDEF));
    Iterable<PropertyDefinition> scaffoldPropDefs = Iterables.filter(propDefs,
            SHPredicates.IS_SCAFFOLD_PROPDEF);
    if (!Iterables.isEmpty(molPropDefs)) {
        builder.appendSeparator(I18n.get("Tooltip.PropertyTitles.Molecule"));
        builder.nextLine();
        buildTitle(builder, true);
        for (PropertyDefinition propDef : molPropDefs) {
            addProperty(builder, propDef);
            builder.nextLine();
        }
    }

    if (!Iterables.isEmpty(scaffoldPropDefs)) {
        builder.appendSeparator(I18n.get("Tooltip.PropertyTitles.Scaffold"));
        buildTitle(builder, false);
        for (PropertyDefinition propDef : scaffoldPropDefs) {
            addProperty(builder, propDef);
            builder.nextLine();
        }
    }

    return builder.getPanel();
}

From source file:brooklyn.location.basic.LocationPropertiesFromBrooklynProperties.java

/**
 * Gets all properties that start with the given {@code fullPrefix}, stripping off
 * the prefix in the returned map./*from  w  w  w  .  j a  va2  s  .  com*/
 * 
 * Returns only those properties whose key suffix is a single word (i.e. contains no dots).
 * We do this special (sub-optimal!) filtering because we want sub-scoped things 
 * (e.g. could want brooklyn.location.privateKeyFile, but not brooklyn.location.named.*). 
 */
protected Map<String, Object> getMatchingSingleWordProperties(String fullPrefix, Map<String, ?> properties) {
    BrooklynProperties filteredProperties = ConfigUtils.filterForPrefixAndStrip(properties, fullPrefix);
    return ConfigUtils.filterFor(filteredProperties, Predicates.not(Predicates.containsPattern("\\.")))
            .asMapWithStringKeys();
}

From source file:edu.udo.scaffoldhunter.gui.dataimport.ImportMappingsDialog.java

/**
 * This creates a {@link JTable} that is used to map each {@link Property}
 * from the {@link ImportJob} to a internal {@link Property}
 * /*from   www. j ava 2  s.c o  m*/
 * @param source
 *            the {@link ImportJob}
 * @return a new {@link JTable}
 */
private JTable getMappingTable(ImportJob source) {
    MappingTableModel tableModel = new MappingTableModel(source);
    tableModels.put(source, tableModel);

    JTable table = new JTable(tableModel);
    table.setBorder(BorderFactory.createEmptyBorder());

    /*
     * PropertyDefinition column
     */
    table.getColumnModel().getColumn(MappingTableModel.PROPERTY_DEFINITION_COLUMN)
            .setCellRenderer(new PropertyDefinitionRenderer(null));
    if (sources.getDataset() == null) {
        /*
         * If we are importing Properties into a new Dataset
         */
        table.getColumnModel().getColumn(MappingTableModel.PROPERTY_DEFINITION_COLUMN)
                .setCellEditor(new PropertyDefinitionCellEditor(this, propertyDefinitions,
                        source.getResults().getProbablyNumeric(), Collections.<PropertyDefinition>emptyList()));
    } else {
        /*
         * If we are merging Properties into an existing Dataset
         */
        Iterable<PropertyDefinition> existingPropDefs = Iterables.filter(
                sources.getDataset().getPropertyDefinitions().values(),
                Predicates.not(SHPredicates.IS_SCAFFOLD_PROPDEF));
        table.getColumnModel().getColumn(MappingTableModel.PROPERTY_DEFINITION_COLUMN)
                .setCellEditor(new PropertyDefinitionCellEditor(this, propertyDefinitions,
                        source.getResults().getProbablyNumeric(), existingPropDefs));
    }

    /*
     * Merge strategy column
     */
    table.getColumnModel().getColumn(MappingTableModel.MERGE_STRATEGY_COLUMN)
            .setCellRenderer(new MergeStrategyRenderer(sources, source, null));
    table.getColumnModel().getColumn(MappingTableModel.MERGE_STRATEGY_COLUMN)
            .setCellEditor(new MergeStrategyEditor());

    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setRowHeight(table.getRowHeight() + 10);
    table.setRowMargin(5);
    table.getColumnModel().setColumnMargin(5);
    table.getTableHeader().setReorderingAllowed(false);

    /*
     * sizing the columns
     */
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (int i = 0; i < table.getColumnCount(); i++) {
        if (i == MappingTableModel.PROPERTY_DEFINITION_COLUMN)
            table.getColumnModel().getColumn(i).setPreferredWidth(table.getColumnModel()
                    .getColumn(MappingTableModel.SOURCE_PROPERTY_COLUMN).getPreferredWidth());
        else
            packTableColumn(table, table.getColumnModel().getColumn(i));
    }
    return table;
}

From source file:forge.deck.generation.DeckGeneratorBase.java

protected void adjustDeckSize(int targetSize) {
    // fix under-sized or over-sized decks, due to integer arithmetic
    int actualSize = tDeck.countAll();
    if (actualSize < targetSize) {
        addSome(targetSize - actualSize, tDeck.toFlatList());
    } else if (actualSize > targetSize) {
        Predicate<PaperCard> exceptBasicLand = Predicates
                .not(Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, PaperCard.FN_GET_RULES));

        for (int i = 0; i < 3 && actualSize > targetSize; i++) {
            Iterable<PaperCard> matchingCards = Iterables.filter(tDeck.toFlatList(), exceptBasicLand);
            List<PaperCard> toRemove = Aggregates.random(matchingCards, actualSize - targetSize);
            tDeck.removeAllFlat(toRemove);

            for (PaperCard c : toRemove) {
                tmpDeck.append("Removed:").append(c.getName()).append("\n");
            }//from  w  w  w . j a  v  a  2s.  co  m
            actualSize = tDeck.countAll();
        }
    }
}

From source file:org.gradle.model.internal.manage.schema.extract.StructStrategy.java

public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext,
        final ModelSchemaCache cache) {
    ModelType<R> type = extractionContext.getType();
    Class<? super R> clazz = type.getRawClass();
    if (clazz.isAnnotationPresent(Managed.class)) {
        validateType(type, extractionContext);

        Iterable<Method> methods = Arrays.asList(clazz.getMethods());
        if (!clazz.isInterface()) {
            methods = filterIgnoredMethods(methods);
        }/* w  w w .j  ava 2 s  .  co m*/
        ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods,
                new Function<Method, String>() {
                    public String apply(Method method) {
                        return method.getName();
                    }
                });

        ensureNoOverloadedMethods(extractionContext, methodsByName);

        List<ModelProperty<?>> properties = Lists.newLinkedList();
        List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length);
        ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering();

        for (String methodName : methodsByName.keySet()) {
            if (methodName.startsWith("get") && !methodName.equals("get")) {
                ImmutableList<Method> getterMethods = methodsByName.get(methodName);

                // The overload check earlier verified that all methods for are equivalent for our purposes
                // So, taking the first one with the most specialized return type is fine.
                Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods);

                boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers());

                if (sampleMethod.getParameterTypes().length != 0) {
                    throw invalidMethod(extractionContext, "getter methods cannot take parameters",
                            sampleMethod);
                }

                Character getterPropertyNameFirstChar = methodName.charAt(3);
                if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                    throw invalidMethod(extractionContext,
                            "the 4th character of the getter method name must be an uppercase character",
                            sampleMethod);
                }

                ModelType<?> returnType = ModelType.returnType(sampleMethod);

                String propertyNameCapitalized = methodName.substring(3);
                String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
                String setterName = "set" + propertyNameCapitalized;
                ImmutableList<Method> setterMethods = methodsByName.get(setterName);

                boolean isWritable = !setterMethods.isEmpty();
                if (isWritable) {
                    Method setter = setterMethods.get(0);

                    if (!abstractGetter) {
                        throw invalidMethod(extractionContext,
                                "setters are not allowed for non-abstract getters", setter);
                    }
                    validateSetter(extractionContext, returnType, setter);
                    handled.addAll(setterMethods);
                }

                if (abstractGetter) {
                    ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet
                            .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() {
                                public ModelType<?> apply(Method input) {
                                    return ModelType.of(input.getDeclaringClass());
                                }
                            }));

                    boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() {
                        public boolean apply(Method input) {
                            return input.getAnnotation(Unmanaged.class) != null;
                        }
                    });

                    properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses,
                            unmanaged));
                }
                handled.addAll(getterMethods);
            }
        }

        Iterable<Method> notHandled = Iterables.filter(methodsByName.values(),
                Predicates.not(Predicates.in(handled)));

        // TODO - should call out valid getters without setters
        if (!Iterables.isEmpty(notHandled)) {
            throw invalidMethods(extractionContext, "only paired getter/setter methods are supported",
                    notHandled);
        }

        Class<R> concreteClass = type.getConcreteClass();
        Class<? extends R> implClass = classGenerator.generate(concreteClass);
        final ModelStructSchema<R> schema = ModelSchema.struct(type, properties, implClass);
        extractionContext.addValidator(new Action<ModelSchemaExtractionContext<R>>() {
            @Override
            public void execute(ModelSchemaExtractionContext<R> validatorModelSchemaExtractionContext) {
                ensureCanBeInstantiated(extractionContext, schema);
            }
        });
        Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties,
                new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() {
                    public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) {
                        return toPropertyExtractionContext(extractionContext, property, cache);
                    }
                });

        return new ModelSchemaExtractionResult<R>(schema, propertyDependencies);
    } else {
        return null;
    }
}

From source file:com.google.api.tools.framework.model.MessageType.java

/**
 * Returns all fields which have non-cyclic types.
 *//*from  w  w w . j  av a2 s  .c om*/
public Iterable<Field> getNonCyclicFields() {
    return FluentIterable.from(fields).filter(Predicates.not(Field.IS_CYCLIC));
}

From source file:com.platzhaltr.readr.MogrifiedReaderMaker.java

/**
 * Builds the predicate reader.//from   ww  w.  j  a  va  2s.com
 *
 * @param objects
 *            the objects
 * @param reader
 *            the reader
 * @return the reader
 */
private Reader buildPredicateReader(final List<Object> objects, Reader reader) {
    // multiple predicates
    if (objects.size() > 1) {
        final List<Predicate<String>> predicates = Lists.newLinkedList();
        for (final Object object : objects) {
            @SuppressWarnings("unchecked")
            final Predicate<String> predicate = (Predicate<String>) object;
            predicates.add(predicate);
        }
        reader = new PredicateFilterReader(reader, Predicates.<String>not(Predicates.<String>or(predicates)));

        // a single predicate
    } else {
        @SuppressWarnings("unchecked")
        final Predicate<String> predicate = (Predicate<String>) objects.get(0);
        reader = new PredicateFilterReader(reader, Predicates.not(predicate));
    }
    return reader;
}