Main icon indicating copy to clipboard operation
Main copied to clipboard

Java8 Tippers- from IntelliJ

Open orimarco opened this issue 9 years ago • 0 comments

Part II of #1085

  1. Anonymous type can be replaced with lambda:

  2. putIfAbsent: (had that one already, but without checking the type is Map)

    if (stats.get(key) == null)
      stats.put(key, new RealStatistics());
  1. for loop replaceable with foreach:
        for (int ¢ = 0; ¢ < modifiers.size(); ++¢)
          if (modifiers.get(¢) instanceof MarkerAnnotation && (modifiers.get(¢) + "").contains("@Test") && (modifiers.get(¢) + "").contains("@Test"))
            return true;

to

          for (Object modifier : modifiers)
              if (modifier instanceof MarkerAnnotation && (modifier + "").contains("@Test") && (modifier + "").contains("@Test"))
                  return true;
  1. for loop can be collapsed with stream API: (Have a Nanos for that - ForEach, ForEachFiltered) (a) foreach
   for (final List<Tipper<? extends ASTNode>> ¢ : implementation)
      if (¢ != null)
        disable(c, ¢);

to

      implementation.stream().filter(¢ -> ¢ != null).forEach((final List<Tipper<? extends ASTNode>> ¢) -> disable(c, ¢));

(b)collect

    final List<Expression> operands = new ArrayList<>();

    for (final Expression ¢ : hop.operands(flatten.of($)))
      operands.add(make.notOf(¢));

to

    final List<Expression> operands = hop.operands(flatten.of($)).stream().map(make::notOf).collect(Collectors.toList());
  1. Lambda can be replaced with method reference:
  ReportGenerator.write(input, output, "δ ", (n1, n2) -> system.d(n1, n2));

to

    ReportGenerator.write(input, output, "δ ", system::d);
xs.stream().map(¢ -> az.stringLiteral(¢).getLiteralValue()).toArray(n -> new String[n])

to


xs.stream().map(¢ -> az.stringLiteral(¢).getLiteralValue()).toArray(String[]::new);

  1. Unnecessary Boxing.

  2. Unnecessary Unboxing.

orimarco avatar Jan 17 '17 07:01 orimarco