LambdaIntrospector implements Function<Object, String> { @Override public String apply(Object lambda) { if (lambda.toString().equals("INSTANCE")) { return getExpressionHash(lambda); } if (lambda instanceof Supplier) { lambda = (( Supplier ) lambda).get(); } SerializedLambda extracted = extractLambda( (Serializable) lambda ); String result = getFingerprintsForClass( lambda, extracted ).get( extracted.getImplMethodName() ); if (result == null) { if ( !extracted.getCapturingClass().equals( extracted.getImplClass() ) ) { result = extracted.getCapturingClass().replace( '/', '.' ) + "::" + extracted.getImplMethodName(); } else { throw new UnsupportedOperationException( "Unable to introspect lambda " + lambda ); } } return result; }  @Override String apply(Object lambda); static final String LAMBDA_INTROSPECTOR_CACHE_SIZE; }
@Test public void testLambdaFingerprint() { LambdaIntrospector lambdaIntrospector = new LambdaIntrospector(); Predicate1<Person> predicate1 = p -> p.getAge() > 35; String fingerprint = lambdaIntrospector.apply(predicate1); assertTrue(fingerprint.contains("ALOAD 0")); assertTrue(fingerprint.contains("INVOKEVIRTUAL org/drools/mvel/compiler/Person.getAge()I")); }
@Test public void testMaterializedLambdaFingerprint() { LambdaIntrospector lambdaIntrospector = new LambdaIntrospector(); String fingerprint = lambdaIntrospector.apply(LambdaPredicate21D56248F6A2E8DA3990031D77D229DD.INSTANCE); assertEquals("4DEB93975D9859892B1A5FD4B38E2155", fingerprint); }