Пример #1
0
 public static Map filterLoadedValues(Map<String, String> in) {
   Map<String, Float> out = new HashMap<>();
   for (Iterator iterator = in.entrySet().iterator(); iterator.hasNext(); ) {
     Map.Entry entry = (Map.Entry) iterator.next();
     out.put(entry.getKey().toString(), Float.valueOf(entry.getValue().toString()));
   }
   return out;
 }
Пример #2
0
 public static Map filterLoadedValuesLambda(Map<String, String> in) {
   return in.entrySet()
       .stream()
       .collect(
           Collectors.toMap(
               e -> e.getKey().toString(), e -> Float.valueOf(e.getValue().toString())));
 }
Пример #3
0
 public static void main(String args[]) {
   Map<String, String> in = new HashMap<>();
   in.put("val1", "10.0");
   in.put("val2", "60.0");
   Map<String, Float> mOriginal = filterLoadedValues(in);
   Map<String, Float> mLambda = filterLoadedValuesLambda(in);
   System.out.println("\nOriginal Entries\n--");
   mOriginal.entrySet().stream().forEach(TransformMap::printEntry);
   System.out.println("\nLambda Entries\n--");
   mLambda.entrySet().stream().forEach(TransformMap::printEntry);
 }
Пример #4
0
  public boolean matches(Criteria criteria) {
    score = 0;

    boolean kill = false;
    boolean anyMatches = false;
    for (Criterion criterion : criteria) {
      Answer answer = answers.get(criterion.getAnswer().getQuestionText());
      boolean match =
          criterion.getWeight() == Weight.DontCare || answer.match(criterion.getAnswer());
      if (!match && criterion.getWeight() == Weight.MustMatch) {
        kill = true;
      }
      if (match) {
        score += criterion.getWeight().getValue();
      }
      anyMatches |= match;
      // ...
    }
    if (kill) return false;
    return anyMatches;
  }
Пример #5
0
 public List<Answer> find(Predicate<Answer> pred) {
   return answers.values().stream().filter(pred).collect(Collectors.toList());
 }
Пример #6
0
 public List<Answer> classicFind(Predicate<Answer> pred) {
   List<Answer> results = new ArrayList<Answer>();
   for (Answer answer : answers.values()) if (pred.test(answer)) results.add(answer);
   return results;
 }
Пример #7
0
 public void add(Answer answer) {
   answers.put(answer.getQuestionText(), answer);
 }