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


Java Predicate.or方法代码示例

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


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

示例1: hasComponentFor

import java.util.function.Predicate; //导入方法依赖的package包/类
@Override
public boolean hasComponentFor(String sourceId) {
  List<Component> topLevelComponents = getWidgetPane().getTiles().stream()
      .map(Tile::getContent)
      .collect(Collectors.toList());
  Predicate<Sourced> isSameSource = s -> s.getSources().stream()
      .map(DataSource::getId)
      .anyMatch(sourceId::equals);
  Predicate<Sourced> isSubSource = s -> s.getSources().stream()
      .map(i -> i.getId() + "/")
      .anyMatch(sourceId::startsWith);
  Predicate<Sourced> isNotContainer = s -> !(s instanceof ComponentContainer);
  Predicate<Sourced> hasComponent = isSameSource.or(isSubSource.and(isNotContainer));
  return topLevelComponents.stream()
      .flatMap(TypeUtils.castStream(Sourced.class))
      .anyMatch(hasComponent)
      || topLevelComponents.stream()
      .flatMap(TypeUtils.castStream(ComponentContainer.class))
      .flatMap(ComponentContainer::allComponents)
      .flatMap(TypeUtils.castStream(Sourced.class))
      .anyMatch(hasComponent);
}
 
开发者ID:wpilibsuite,项目名称:shuffleboard,代码行数:23,代码来源:DashboardTab.java

示例2: or

import java.util.function.Predicate; //导入方法依赖的package包/类
@SafeVarargs
public static <T> Predicate<T> or(Predicate<T>... predicates) {
    Predicate<T> predicate = predicates[0];

    for (int i = 1; i < predicates.length; i++) {
        predicate = predicate.or(predicates[i]);
    }

    return predicate;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:11,代码来源:Predicates.java

示例3: main

import java.util.function.Predicate; //导入方法依赖的package包/类
public static void main(String[] args) {
	Predicate<Employee> male = e -> e.getSex() == Sex.MALE;
	Predicate<Employee> female = e -> e.getSex() == Sex.FEMALE;
	Predicate<Employee> ageLessThan30 = e -> e.getAge() < 30;
	Predicate<Employee> salaryLessThan20 = e -> e.getSalary() < 20000;
	Predicate<Employee> salaryGreaterThan25 = e -> e.getSalary() > 25000;
	Predicate<Employee> salaryLessThan20OrGreateThan25 = salaryLessThan20.or(salaryGreaterThan25);

	Predicate<Employee> allMaleSalaryLessThan20 = male.and(salaryLessThan20);
	Predicate<Employee> allMaleAgeLessThan30 = male.and(ageLessThan30);
	Predicate<Employee> allFemaleSalaryGreaterThan25 = female.and(salaryGreaterThan25);

	Predicate<Employee> allMaleSalaryLessThan20OrGreateThan25 = male.and(salaryLessThan20OrGreateThan25);

	List<Employee> employees = EmployeeStub.getEmployees();
	System.out.println("All employees");
	System.out.println(employees);
	System.out.println("\n\n");
	
	System.out.println("All Male Salary less than 20");
	System.out.println(employees.stream().filter(allMaleSalaryLessThan20).collect(Collectors.toList()));
	System.out.println("All male Age less than 30");
	System.out.println(employees.stream().filter(allMaleAgeLessThan30).collect(Collectors.toList()));
	System.out.println("All females salary greater than 25");
	System.out.println(employees.stream().filter(allFemaleSalaryGreaterThan25).collect(Collectors.toList()));
	
	System.out.println("All males salary either less than 20 or greater than 25");
	System.out.println(employees.stream().filter(allMaleSalaryLessThan20OrGreateThan25).collect(Collectors.toList()));
}
 
开发者ID:gauravrmazra,项目名称:gauravbytes,代码行数:30,代码来源:Java8FilteringWithPredicates.java

示例4: filterForExport

import java.util.function.Predicate; //导入方法依赖的package包/类
public static Person filterForExport(Person original, int yearsToKeep, long endTime) {
  // filter the patient's history to only the last __ years
  // but also include relevant history from before that. Exclude
  // any history that occurs after the specified end_time -- typically
  // this is the current time/System.currentTimeMillis().

  long cutoffDate = endTime - Utilities.convertTime("years", yearsToKeep);

  Predicate<HealthRecord.Entry> notFutureDated = e -> e.start <= endTime;
  
  // TODO: clone the patient so that we export only the last _ years 
  // but the rest still exists, just in case
  Person filtered = original; //.clone();
  //filtered.record = original.record.clone();

  final HealthRecord record = filtered.record;
  
  for (Encounter encounter : record.encounters) { 
    // keep conditions if still active, regardless of start date
    Predicate<HealthRecord.Entry> conditionActive = c -> record.conditionActive(c.type);
    // or if the condition was active at any point since the cutoff date
    Predicate<HealthRecord.Entry> activeWithinCutoff = c -> c.stop != 0L && c.stop > cutoffDate;
    Predicate<HealthRecord.Entry> keepCondition = conditionActive.or(activeWithinCutoff); 
    filterEntries(encounter.conditions, cutoffDate, endTime, keepCondition);

    // allergies are essentially the same as conditions
    filterEntries(encounter.allergies, cutoffDate, endTime, keepCondition);

    // some of the "future death" logic could potentially add a future-dated death certificate
    Predicate<Observation> isCauseOfDeath =
        o -> DeathModule.CAUSE_OF_DEATH_CODE.code.equals(o.type);
    // keep cause of death unless it's future dated
    Predicate<Observation> keepObservation = isCauseOfDeath.and(notFutureDated);
    filterEntries(encounter.observations, cutoffDate, endTime, keepObservation);

    // keep all death certificates, unless they are future-dated
    Predicate<Report> isDeathCertificate = r -> DeathModule.DEATH_CERTIFICATE.code.equals(r.type);
    Predicate<Report> keepReport = isDeathCertificate.and(notFutureDated);
    filterEntries(encounter.reports, cutoffDate, endTime, keepReport);

    filterEntries(encounter.procedures, cutoffDate, endTime, null);

    // keep medications if still active, regardless of start date
    filterEntries(encounter.medications, cutoffDate, endTime, 
        med -> record.medicationActive(med.type));

    filterEntries(encounter.immunizations, cutoffDate, endTime, null);

    // keep careplans if they are still active, regardless of start date
    filterEntries(encounter.careplans, cutoffDate, endTime, cp -> record.careplanActive(cp.type));
  }

  Predicate<Encounter> encounterNotEmpty = e ->
      !e.conditions.isEmpty() && !e.allergies.isEmpty()
      && !e.observations.isEmpty() && !e.reports.isEmpty()
      && !e.procedures.isEmpty() && !e.medications.isEmpty()
      && !e.immunizations.isEmpty() && !e.careplans.isEmpty();

  Predicate<Encounter> isDeathCertification = 
      e -> !e.codes.isEmpty() && DeathModule.DEATH_CERTIFICATION.equals(e.codes.get(0));
  Predicate<Encounter> keepEncounter = 
      encounterNotEmpty.or(isDeathCertification.and(notFutureDated));

  // finally filter out any empty encounters
  filterEntries(record.encounters, cutoffDate, endTime, keepEncounter);

  return filtered;
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:69,代码来源:Exporter.java

示例5: either

import java.util.function.Predicate; //导入方法依赖的package包/类
public static <T> Predicate<T> either(Predicate<T> first, Predicate<T> second) {
    return first.or(second);
}
 
开发者ID:membaza,项目名称:users-service,代码行数:4,代码来源:PredicateUtil.java

示例6: isOpen

import java.util.function.Predicate; //导入方法依赖的package包/类
@Override
public boolean isOpen(int col, int row, int tileWidth, int tileHeight, Predicate<Node> ignore) {
  // overload to also ignore the highlight (it's not an actual tile)
  return super.isOpen(col, row, tileWidth, tileHeight, ignore.or(n -> n == gridHighlight));
}
 
开发者ID:wpilibsuite,项目名称:shuffleboard,代码行数:6,代码来源:WidgetPane.java

示例7: parsePredicate

import java.util.function.Predicate; //导入方法依赖的package包/类
public static Predicate<DataObject> parsePredicate(String filter) {
    if (filter.startsWith("(")) {
        int closingBracketIndex = findClosingBracketIndex(filter);
        Predicate<DataObject> predicate = parsePredicate(filter.substring(1, closingBracketIndex));

        if (closingBracketIndex != filter.length() - 1) {
            String secondFilterPart = filter.substring(closingBracketIndex + 1).trim();
            if (startsWithIgnoreCase(secondFilterPart, AND.name())) {
                return predicate.and(parsePredicate(secondFilterPart.substring(3).trim()));
            } else if (startsWithIgnoreCase(secondFilterPart, OR.name())) {
                return predicate.or(parsePredicate(secondFilterPart.substring(2).trim()));
            } else {
                throw new IllegalArgumentException("Illegal combiner : " + secondFilterPart);
            }
        } else {
            return predicate;
        }
    }
    String[] words = parseWords(filter);

    if (words.length < 3) {
        throw new IllegalArgumentException("Incomplete filter : " + filter);
    }
    String firstWord = wordAtPosition(words, 0)
            .orElseThrow(() -> new IllegalArgumentException("Should not be called with empty string"));
    String secondWord = wordAtPosition(words, 1)
            .orElseThrow(() -> new IllegalArgumentException("Should not be called with empty string"));
    String thirdWord = wordAtPosition(words, 2)
            .orElseThrow(() -> new IllegalArgumentException("Should not be called with empty string"));

    Operator operator = Operator.fromValue(secondWord);
    Predicate<DataObject> operatorPredicate = predicateFactories.get(operator).build(firstWord, thirdWord);

    Optional<String> fourthWord = wordAtPosition(words, 3);
    if (fourthWord.isPresent()) {
        Combiner combiner = Combiner.valueOf(fourthWord.get());
        String[] remainingWords = ArrayUtils.subarray(words, 4, words.length);
        String remainingFilterString = StringUtils.join(remainingWords, " ");
        switch (combiner) {
            case AND:
                return operatorPredicate.and(parsePredicate(remainingFilterString));
            case OR:
                return operatorPredicate.or(parsePredicate(remainingFilterString));
        }
    }

    return operatorPredicate;
}
 
开发者ID:Kindrat,项目名称:cassandra-client,代码行数:49,代码来源:DataFilter.java

示例8: execute

import java.util.function.Predicate; //导入方法依赖的package包/类
@Override
protected void execute() {
    EventHistoryService eventHistoryService = get(EventHistoryService.class);

    Stream<Event<?, ?>> events = eventHistoryService.history().stream();

    boolean dumpAll = all || !(mastership || device || link || topology || host);

    if (!dumpAll) {
        Predicate<Event<?, ?>> filter = (defaultIs) -> false;

        if (mastership) {
            filter = filter.or(evt -> evt instanceof MastershipEvent);
        }
        if (device) {
            filter = filter.or(evt -> evt instanceof DeviceEvent);
        }
        if (link) {
            filter = filter.or(evt -> evt instanceof LinkEvent);
        }
        if (topology) {
            filter = filter.or(evt -> evt instanceof TopologyEvent);
        }
        if (host) {
            filter = filter.or(evt -> evt instanceof HostEvent);
        }
        if (cluster) {
            filter = filter.or(evt -> evt instanceof ClusterEvent);
        }

        events = events.filter(filter);
    }

    if (maxSize > 0) {
        events = events.limit(maxSize);
    }

    if (outputJson()) {
        ArrayNode jsonEvents = events.map(this::json).collect(toArrayNode());
        printJson(jsonEvents);
    } else {
        events.forEach(this::printEvent);
    }

}
 
开发者ID:shlee89,项目名称:athena,代码行数:46,代码来源:EventsCommand.java

示例9: abortIf

import java.util.function.Predicate; //导入方法依赖的package包/类
public RetryPolicy abortIf(Predicate<RetryContext> abortPredicate) {
    return new RetryPolicy(maxRetries, retryOn, abortOn, retryPredicate, abortPredicate.or(abortPredicate), backoff, timeout);
}
 
开发者ID:vsilaev,项目名称:tascalate-concurrent,代码行数:4,代码来源:RetryPolicy.java


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