当前位置: 首页>>代码示例>>Java>>正文


Java Predicate.test方法代码示例

本文整理汇总了Java中java.util.function.Predicate.test方法的典型用法代码示例。如果您正苦于以下问题:Java Predicate.test方法的具体用法?Java Predicate.test怎么用?Java Predicate.test使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.function.Predicate的用法示例。


在下文中一共展示了Predicate.test方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findAllItems

import java.util.function.Predicate; //导入方法依赖的package包/类
/**
 * Trouve tous les éléments du magasin validant un prédicat.
 * 
 * @param predicate Prédicat.
 * @return Les éléments trouvés.
 */
public List<T> findAllItems(Predicate<T> predicate) {

	/* Obtient le nom du projet courant. */
	IProject currentProject = UiUtils.getCurrentEditorProject();

	List<T> found = new ArrayList<>();

	List<T> items = this.getAllItems();
	for (T item : items) {

		/* Filtre sur le nom du projet. */
		if (currentProject != null && !currentProject.equals(ResourceUtils.getProject(item))) {
			continue;
		}

		if (predicate.test(item)) {
			found.add(item);
		}
	}

	return found;
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:29,代码来源:ResourceStore.java

示例2: main

import java.util.function.Predicate; //导入方法依赖的package包/类
public static void main(String[] args) {

        List<String> text = Arrays.stream(scann.nextLine().split("\\s+"))
                .collect(Collectors.toList());

        Predicate<String> checkUpperCase = s ->
                s.charAt(0) == s.toUpperCase().charAt(0);
        ArrayList<String> result = new ArrayList<>();

        for (String str :
                text) {
            if(checkUpperCase.test(str)) {
                result.add(str);
            }
        }
        System.out.println(result.size());
        result.forEach(System.out::println);
    }
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:19,代码来源:p03_CountUppercaseWords.java

示例3: isOverlapping

import java.util.function.Predicate; //导入方法依赖的package包/类
/**
 * Checks if a tile with the given width and height would overlap a pre-existing tile at the point {@code (col, row)},
 * ignoring some nodes when calculating collisions. Note that this method does <i>not</i> perform bounds checking;
 * use {@link #isOpen(int, int, int, int, Predicate) isOpen} to check if a widget can be placed at that point.
 *
 * @param col        the column index of the point to check
 * @param row        the row index of the point to check
 * @param tileWidth  the width of the tile
 * @param tileHeight the height of the tile
 * @param ignore     a predicate to use to ignore nodes when calculating collisions
 */
public boolean isOverlapping(int col, int row, int tileWidth, int tileHeight, Predicate<Node> ignore) {
  for (Node child : getChildren()) {
    if (ignore.test(child)) {
      continue;
    }
    // All "real" children have a column index, row index, and column and row spans
    // Other children (like the grid lines) don't have these properties and will throw null pointers
    // when trying to access these properties
    if (GridPane.getColumnIndex(child) != null) {
      int x = GridPane.getColumnIndex(child);
      int y = GridPane.getRowIndex(child);
      int width = GridPane.getColumnSpan(child);
      int height = GridPane.getRowSpan(child);
      if (x + width > col && y + height > row
          && x - tileWidth < col && y - tileHeight < row) {
        // There's an intersection
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:wpilibsuite,项目名称:shuffleboard,代码行数:34,代码来源:TilePane.java

示例4: where

import java.util.function.Predicate; //导入方法依赖的package包/类
public ListHelper<T> where(Predicate<? super T> filter) {
    Objects.requireNonNull(filter);

    final Iterator<T> each = this.items.iterator();
    while (each.hasNext()) {
        T item = each.next();
        if (!filter.test(item)) {
            each.remove();
        }
    }
    return this;
}
 
开发者ID:liuxx001,项目名称:bird-java,代码行数:13,代码来源:ListHelper.java

示例5: filter

import java.util.function.Predicate; //导入方法依赖的package包/类
@Override
public final Array<T> filter(Predicate<ArrayValue<T>> predicate) {
    int count = 0;
    final int length = this.length();
    final ArrayCursor<T> cursor = cursor();
    final Array<T> matches = Array.of(type(), length, loadFactor());
    for (int i=0; i<length; ++i) {
        cursor.moveTo(i);
        final boolean match = predicate.test(cursor);
        if (match) matches.setValue(count++, cursor.getValue());
    }
    return count == length ? matches : matches.copy(0, count);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:14,代码来源:SparseArrayWithLongCoding.java

示例6: createConditionalTarget

import java.util.function.Predicate; //导入方法依赖的package包/类
static @NonNull final Supplier<? extends String[]> createConditionalTarget(
        @NonNull final PropertyEvaluator eval,
        @NonNull final Predicate<PropertyEvaluator> predicate,
        @NonNull final String[] ifTargets,
        @NonNull final String[] elseTargets) {
    return () -> {
        return predicate.test(eval) ?
                ifTargets:
                elseTargets;
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ActionProviderSupport.java

示例7: from

import java.util.function.Predicate; //导入方法依赖的package包/类
public static PrivilegedResource from(Resource resource, Predicate<Resource> predicate) {
	if (resource == null) {
		return null;
	}
	if (!predicate.test(resource)) {
		return null;
	}
	PrivilegedResource result = new PrivilegedResource();
	convert(resource, result, predicate);
	return result;
}
 
开发者ID:melthaw,项目名称:spring-backend-boilerplate,代码行数:12,代码来源:PrivilegedResource.java

示例8: removeIf

import java.util.function.Predicate; //导入方法依赖的package包/类
public boolean removeIf(Predicate<? super Entry<K,V>> filter) {
    if (filter == null) throw new NullPointerException();
    if (m instanceof ConcurrentSkipListMap)
        return ((ConcurrentSkipListMap<K,V>)m).removeEntryIf(filter);
    // else use iterator
    Iterator<Map.Entry<K,V>> it =
        ((SubMap<K,V>)m).new SubMapEntryIterator();
    boolean removed = false;
    while (it.hasNext()) {
        Map.Entry<K,V> e = it.next();
        if (filter.test(e) && m.remove(e.getKey(), e.getValue()))
            removed = true;
    }
    return removed;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ConcurrentSkipListMap.java

示例9: findMatcher

import java.util.function.Predicate; //导入方法依赖的package包/类
private static Matcher findMatcher(Matcher matcher, Predicate<Matcher> predicate) {
    if (matcher instanceof AllOfMatcher) {
        for (Matcher entry: (AllOfMatcher)matcher) {
            if (predicate.test(entry)) {
                return entry;
            }
        }
    } else if (predicate.test(matcher)) {
        return matcher;
    }
    return null;
}
 
开发者ID:i49,项目名称:cascade,代码行数:13,代码来源:Matchers.java

示例10: removeIf

import java.util.function.Predicate; //导入方法依赖的package包/类
/**
 * Removes all elements satisfying the given predicate, from index
 * i (inclusive) to index end (exclusive).
 */
boolean removeIf(Predicate<? super E> filter, int i, final int end) {
    Objects.requireNonNull(filter);
    int expectedModCount = modCount;
    final Object[] es = elementData;
    // Optimize for initial run of survivors
    for (; i < end && !filter.test(elementAt(es, i)); i++)
        ;
    // Tolerate predicates that reentrantly access the collection for
    // read (but writers still get CME), so traverse once to find
    // elements to delete, a second pass to physically expunge.
    if (i < end) {
        final int beg = i;
        final long[] deathRow = nBits(end - beg);
        deathRow[0] = 1L;   // set bit 0
        for (i = beg + 1; i < end; i++)
            if (filter.test(elementAt(es, i)))
                setBit(deathRow, i - beg);
        if (modCount != expectedModCount)
            throw new ConcurrentModificationException();
        expectedModCount++;
        modCount++;
        int w = beg;
        for (i = beg; i < end; i++)
            if (isClear(deathRow, i - beg))
                es[w++] = es[i];
        shiftTailOverGap(es, w, end);
        return true;
    } else {
        if (modCount != expectedModCount)
            throw new ConcurrentModificationException();
        return false;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:ArrayList.java

示例11: onInventoryOpen

import java.util.function.Predicate; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent event) {
    final MatchPlayer opener = playerFinder.getParticipant(event.getActor());
    if(opener == null) return;

    final Inventory inventory = event.getInventory();
    final Predicate<Filter> passesFilter = passesFilter(inventory.getHolder());
    if(passesFilter == null) return;

    logger.fine(() -> opener.getName() + " opened a " + inventory.getHolder().getClass().getSimpleName());

    // Find all Fillers that apply to the holder of the opened inventory
    final List<Filler> fillers = this.fillers.stream()
                                             .filter(filler -> passesFilter.test(filler.filter()))
                                             .collect(Collectors.toImmutableList());
    if(fillers.isEmpty()) return;

    logger.fine(() -> "Found fillers " + fillers.stream()
                                                .map(Filler::identify)
                                                .collect(java.util.stream.Collectors.joining(", ")));

    // Find all Caches that the opened inventory is part of
    final List<Fillable> fillables = new ArrayList<>();
    for(Cache cache : caches) {
        if(passesFilter.test(cache.region()) && passesFilter.test(cache.filter())) {
            fillables.add(new FillableCache(cache));
        }
    }
    // If the inventory is not in any Cache, just fill it directly
    if(fillables.isEmpty()) {
        fillables.add(new FillableInventory(inventory));
    }

    fillables.forEach(fillable -> fillable.fill(opener, fillers));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:36,代码来源:FillListener.java

示例12: handleCommand

import java.util.function.Predicate; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void handleCommand(final Object message) {
    Predicate drop = dropMessagesOfType.get(message.getClass());
    if (drop == null || !drop.test(message)) {
        super.handleCommand(message);
    }

    if (collectorActor != null) {
        collectorActor.tell(message, ActorRef.noSender());
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:13,代码来源:EntityOwnershipShardTest.java

示例13: remove

import java.util.function.Predicate; //导入方法依赖的package包/类
/**
 * Removes any link matching the predicate.
 *
 * @param predicate the predicate that decides which item to removeHotbar
 * @return true if the hotbar changed
 */
public boolean remove(Predicate<ConfigIcon> predicate) {
    int initialSize = size;
    for (int i = 0; i < 9; i++) {
        if (predicate.test(icons[i])) {
            if (icons[i] == null)
                size--;
            icons[i] = null;
        }
    }
    return size != initialSize;
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:18,代码来源:Hotbar.java

示例14: doCompare

import java.util.function.Predicate; //导入方法依赖的package包/类
/**
 * Compare Function.
 * 
 * @param compareOp Compare Operator function See {@link CompareOp}
 * @param value Value to compare with {@link #initialValue}
 * @param type Type of the column value See{@link DataType}
 * @param columnName Name of the column whose value to be compared
 * @return true if values matches otherwise false.
 */

public boolean doCompare(final CompareOp compareOp, final Object value, DataType type,
    byte[] columnName) {
  if (!(type instanceof TypePredicate)) {
    throw new MFilterException("Column type for column '" + Bytes.toString(columnName)
        + "' must implement TypePredicate to support push down predicates");
  }
  Predicate predicate = ((TypePredicate) type).getPredicate(compareOp, initialValue);
  return predicate.test(value);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:CompareFilter.java

示例15: filter

import java.util.function.Predicate; //导入方法依赖的package包/类
@Override
public final Array<Long> filter(Predicate<ArrayValue<Long>> predicate) {
    final ArrayCursor<Long> cursor = cursor();
    final ArrayBuilder<Long> builder = ArrayBuilder.of(length(), type());
    for (int i=0; i<length(); ++i) {
        cursor.moveTo(i);
        final boolean match = predicate.test(cursor);
        if (match) {
            builder.addLong(cursor.getLong());
        }
    }
    return builder.toArray();
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:14,代码来源:MappedArrayOfLongs.java


注:本文中的java.util.function.Predicate.test方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。