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


Java BiPredicate.test方法代码示例

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


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

示例1: removeIf

import java.util.function.BiPredicate; //导入方法依赖的package包/类
boolean removeIf(BiPredicate<? super K, ? super V> filter) {
  checkNotNull(filter);
  boolean changed = false;
  for (K key : keySet()) {
    while (true) {
      V value = get(key);
      if (value == null || !filter.test(key, value)) {
        break;
      } else if (LocalCache.this.remove(key, value)) {
        changed = true;
        break;
      }
    }
  }
  return changed;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:17,代码来源:LocalCache.java

示例2: findAll

import java.util.function.BiPredicate; //导入方法依赖的package包/类
/**
 * Finds all values matching the predicate, returns as a map.
 */
public static <K,V> Map<K,V> findAll(Map<K,V> receiver, BiPredicate<K,V> predicate) {
    // try to preserve some properties of the receiver (see the groovy javadocs)
    final Map<K,V> map;
    if (receiver instanceof TreeMap) {
        map = new TreeMap<>();
    } else {
        map = new LinkedHashMap<>();
    }
    for (Map.Entry<K,V> kvPair : receiver.entrySet()) {
        if (predicate.test(kvPair.getKey(), kvPair.getValue())) {
            map.put(kvPair.getKey(), kvPair.getValue());
        }
    }
    return map;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:Augmentation.java

示例3: merge

import java.util.function.BiPredicate; //导入方法依赖的package包/类
private List<K> merge(final List<K> partition1, final List<K> partition2, final BiPredicate<K, K> isGreater) {
    final List<K> output = new ArrayList<>();

    int ptr1 = 0, ptr2 = 0;
    while(output.size() < partition1.size() + partition2.size() && ptr1 < partition1.size() && ptr2 < partition2.size()) {
        if(isGreater.test(partition1.get(ptr1), partition2.get(ptr2))) {
            output.add(partition2.get(ptr2++));
        } else {
            output.add(partition1.get(ptr1++));
        }
    }

    while(ptr1 < partition1.size()) output.add(partition1.get(ptr1++));
    while(ptr2 < partition2.size()) output.add(partition2.get(ptr2++));

    return output;
}
 
开发者ID:mihsathe,项目名称:algo-kit,代码行数:18,代码来源:MergeSort.java

示例4: isSorted

import java.util.function.BiPredicate; //导入方法依赖的package包/类
default int isSorted(final List<K> input, final BiPredicate<K,K> isGreater) {
    boolean sorted = true;
    boolean antiSorted = true;

    for(int i=1; i<input.size(); i++) {
        if(isGreater.test(input.get(i), input.get(i-1))) {
            antiSorted = false;
        } else {
            sorted = false;
        }
    }

    if(sorted) {
        return 1;
    } else if(antiSorted) {
        return -1;
    }

    return 0;
}
 
开发者ID:mihsathe,项目名称:algo-kit,代码行数:21,代码来源:Sorter.java

示例5: union

import java.util.function.BiPredicate; //导入方法依赖的package包/类
/**
 * Form the union of two closures
 */
public List<Type> union(List<Type> cl1, List<Type> cl2, BiPredicate<Type, Type> shouldSkip) {
    if (cl1.isEmpty()) {
        return cl2;
    } else if (cl2.isEmpty()) {
        return cl1;
    } else if (shouldSkip.test(cl1.head, cl2.head)) {
        return union(cl1.tail, cl2.tail, shouldSkip).prepend(cl1.head);
    } else if (cl1.head.tsym.precedes(cl2.head.tsym, this)) {
        return union(cl1.tail, cl2, shouldSkip).prepend(cl1.head);
    } else if (cl2.head.tsym.precedes(cl1.head.tsym, this)) {
        return union(cl1, cl2.tail, shouldSkip).prepend(cl2.head);
    } else {
        // unrelated types
        return union(cl1.tail, cl2, shouldSkip).prepend(cl1.head);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:Types.java

示例6: speedAfterStart

import java.util.function.BiPredicate; //导入方法依赖的package包/类
public void speedAfterStart(double timeSec, int trafficUnitsNumber, SpeedModel speedModel,
                            BiPredicate<TrafficUnit, Double> limitTrafficAndSpeed) {
    List<TrafficUnit> trafficUnits = FactoryTraffic.generateTraffic(trafficUnitsNumber,
            month, dayOfWeek, hour, country, city, trafficLight);
    for(TrafficUnit tu: trafficUnits){
        Vehicle vehicle = FactoryVehicle.build(tu);
        vehicle.setSpeedModel(speedModel);
        double speed = vehicle.getSpeedMph(timeSec);
        speed = Math.round(speed * tu.getTraction());
        if(limitTrafficAndSpeed.test(tu, speed)){
            printResult(tu, timeSec, speed);
        }
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:15,代码来源:Chapter04Functional.java

示例7: speedAfterStart

import java.util.function.BiPredicate; //导入方法依赖的package包/类
public void speedAfterStart(double timeSec, int trafficUnitsNumber, SpeedModel speedModel,
                            BiPredicate<TrafficUnit, Double> limitSpeed, BiConsumer<TrafficUnit, Double> printResult) {
    List<TrafficUnit> trafficUnits = FactoryTraffic.generateTraffic(trafficUnitsNumber,
            month, dayOfWeek, hour, country, city, trafficLight);
    for(TrafficUnit tu: trafficUnits){
        Vehicle vehicle = FactoryVehicle.build(tu);
        vehicle.setSpeedModel(speedModel);
        double speed = vehicle.getSpeedMph(timeSec);
        speed = Math.round(speed * tu.getTraction());
        if(limitSpeed.test(tu, speed)){
            printResult.accept(tu, speed);
        }
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:15,代码来源:Chapter05Streams.java

示例8: predicate

import java.util.function.BiPredicate; //导入方法依赖的package包/类
static <Test, R> FstCondition<R> predicate(Test test, BiPredicate<Test, R> m) {
    return new FstCondition<R>() {
        @Override
        public boolean test(int index, R obj) {
            if (test == null) {
                return false;
            }
            return m.test(test, obj);
        }
    };
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:12,代码来源:FstCondition.java

示例9: equals

import java.util.function.BiPredicate; //导入方法依赖的package包/类
@Override
public boolean equals(Instruction other, BiPredicate<IndexedDexItem, IndexedDexItem> equality) {
  if (other == null || (this.getClass() != other.getClass())) {
    return false;
  }
  Format35c o = (Format35c) other;
  return o.A == A && o.C == C && o.D == D && o.E == E && o.F == F && o.G == G
      && equality.test(BBBB, o.BBBB);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:10,代码来源:Format35c.java

示例10: insert

import java.util.function.BiPredicate; //导入方法依赖的package包/类
/**
 * Insert a type in a closure
 */
public List<Type> insert(List<Type> cl, Type t, BiPredicate<Type, Type> shouldSkip) {
    if (cl.isEmpty()) {
        return cl.prepend(t);
    } else if (shouldSkip.test(t, cl.head)) {
        return cl;
    } else if (t.tsym.precedes(cl.head.tsym, this)) {
        return cl.prepend(t);
    } else {
        // t comes after head, or the two are unrelated
        return insert(cl.tail, t, shouldSkip).prepend(cl.head);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Types.java

示例11: equals

import java.util.function.BiPredicate; //导入方法依赖的package包/类
@Override
public boolean equals(Instruction other, BiPredicate<IndexedDexItem, IndexedDexItem> equality) {
  if (other == null || this.getClass() != other.getClass()) {
    return false;
  }
  Format22c o = (Format22c) other;
  return o.A == A && o.B == B && equality.test(CCCC, o.CCCC);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:9,代码来源:Format22c.java

示例12: equals

import java.util.function.BiPredicate; //导入方法依赖的package包/类
@Override
public boolean equals(Instruction other, BiPredicate<IndexedDexItem, IndexedDexItem> equality) {
  if (other == null || (this.getClass() != other.getClass())) {
    return false;
  }
  Format31c o = (Format31c) other;
  return o.AA == AA && equality.test(BBBBBBBB, o.BBBBBBBB);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:9,代码来源:Format31c.java

示例13: equals

import java.util.function.BiPredicate; //导入方法依赖的package包/类
@Override
public boolean equals(Instruction other, BiPredicate<IndexedDexItem, IndexedDexItem> equality) {
  if (other == null || (this.getClass() != other.getClass())) {
    return false;
  }
  Format3rc o = (Format3rc) other;
  return o.AA == AA && o.CCCC == CCCC && equality.test(BBBB, o.BBBB);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:9,代码来源:Format3rc.java

示例14: every

import java.util.function.BiPredicate; //导入方法依赖的package包/类
/**
 * Used to determine if the given predicate is valid (i.e. returns true for all items in this map).
 */
public static <K,V> boolean every(Map<K,V> receiver, BiPredicate<K,V> predicate) {
    for (Map.Entry<K,V> kvPair : receiver.entrySet()) {
        if (predicate.test(kvPair.getKey(), kvPair.getValue()) == false) {
            return false;
        }
    }
    return true;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:Augmentation.java

示例15: sort

import java.util.function.BiPredicate; //导入方法依赖的package包/类
public List<K> sort(final List<K> input, final BiPredicate<K, K> isGreater) {
    int sortedResult = isSorted(input, isGreater);

    if (sortedResult == 1) return input;
    if (sortedResult == -1) {
        Collections.reverse(input);
        return input;
    }

    final int size = input.size();

    // Pick one number at a time
    for (int i=0; i<size; i++) {

        K min = input.get(i);
        int minIndex = i;
        // Find min in rest of the array
        for(int j=i+1; j<size; j++) {
            if(isGreater.test(min, input.get(j))) {
                min = input.get(j);
                minIndex = j;
            }
        }
        
        // Now assign minIndex to i
        K temp = input.get(minIndex);
        input.set(minIndex, input.get(i));
        input.set(i, temp);
    }

    return input;
}
 
开发者ID:mihsathe,项目名称:algo-kit,代码行数:33,代码来源:SelectionSort.java


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