File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed
approvaltests-util/src/main/java Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 99import com .spun .util .io .StackElementLevelSelector ;
1010import com .spun .util .io .StackElementSelector ;
1111import org .lambda .functions .Function2 ;
12+ import org .lambda .query .Queryable ;
1213
1314import javax .mail .Message ;
1415import javax .swing .JFileChooser ;
@@ -223,14 +224,11 @@ private static String handleInnerClasses(String className)
223224 }
224225 public static String unrollLambda (String methodName )
225226 {
226- Matcher javaMatcher = unrollJavaLambdaPattern .matcher (methodName );
227- if (javaMatcher .matches ())
228- { return javaMatcher .group (1 ); }
229- Matcher kotlinMatcher = unrollKotlinLambdaPattern .matcher (methodName );
230- if (kotlinMatcher .matches ())
231- { return kotlinMatcher .group (1 ); }
232- return methodName ;
227+ return lambdaPatterns .select (p -> p .matcher (methodName )).where (Matcher ::matches ).select (m -> m .group (1 ))
228+ .firstOrDefault (methodName );
233229 }
234- private static final Pattern unrollJavaLambdaPattern = Pattern .compile ("lambda\\ $(.*)\\ $\\ d+" );
235- private static final Pattern unrollKotlinLambdaPattern = Pattern .compile ("(.*?)(\\ $lambda-\\ d+)+" );
230+ private static final Pattern unrollJavaLambdaPattern = Pattern .compile ("lambda\\ $(.*)\\ $\\ d+" );
231+ private static final Pattern unrollKotlinLambdaPattern = Pattern .compile ("(.*?)(\\ $lambda-\\ d+)+" );
232+ private static final Queryable <Pattern > lambdaPatterns = Queryable .as (unrollJavaLambdaPattern ,
233+ unrollKotlinLambdaPattern );
236234}
Original file line number Diff line number Diff line change @@ -49,12 +49,16 @@ public Queryable<In> where(Function1<In, Boolean> funct)
4949 }
5050 public In first ()
5151 {
52- return this . isEmpty () ? null : this . get ( 0 );
52+ return firstOrDefault ( null );
5353 }
5454 public In first (Function1 <In , Boolean > filter )
5555 {
5656 return Query .first (this , filter );
5757 }
58+ public In firstOrDefault (In defaultValue )
59+ {
60+ return this .isEmpty () ? defaultValue : this .get (0 );
61+ }
5862 public boolean all (Function1 <In , Boolean > filter )
5963 {
6064 return Query .all (this , filter );
You can’t perform that action at this time.
0 commit comments