File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <modelVersion >4.0.0</modelVersion >
6+
7+ <groupId >com.fd</groupId >
8+ <artifactId >lazy</artifactId >
9+ <version >1.0-SNAPSHOT</version >
10+
11+ <properties >
12+ <java-version >1.8</java-version >
13+ <maven .compiler.source>1.8</maven .compiler.source>
14+ <maven .compiler.target>1.8</maven .compiler.target>
15+ </properties >
16+
17+ <dependencies >
18+ <dependency >
19+ <groupId >org.testng</groupId >
20+ <artifactId >testng</artifactId >
21+ <version >6.14.3</version >
22+ <scope >test</scope >
23+ </dependency >
24+
25+ <dependency >
26+ <groupId >com.oath.cyclops</groupId >
27+ <artifactId >cyclops</artifactId >
28+ <version >10.3.0</version >
29+ </dependency >
30+
31+
32+ </dependencies >
33+
34+
35+ </project >
Original file line number Diff line number Diff line change 1+ package com .fd .lazy ;
2+
3+ /**
4+ * @author fdanismaz
5+ * date: 6/3/19 4:10 PM
6+ */
7+ public interface FunctionPointer <T > {
8+
9+ T get (int i );
10+ }
Original file line number Diff line number Diff line change 1+ package com .fd .lazy ;
2+
3+ /**
4+ * @author fdanismaz
5+ * date: 6/3/19 3:48 PM
6+ */
7+ public class SampleSupplier {
8+
9+ public static int CALL_TRACKER = 0 ;
10+
11+ public String getMessage () {
12+ return "Hello World. This method is called " + ++CALL_TRACKER + " times" ;
13+ }
14+
15+ public String getMessage (int i ) {
16+ return "Hello World. Passed value is : " + i ;
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package com .fd .lazy ;
2+
3+ import cyclops .function .Memoize ;
4+ import org .testng .Assert ;
5+ import org .testng .annotations .Test ;
6+
7+ import java .util .function .Supplier ;
8+
9+ /**
10+ * @author fdanismaz
11+ * date: 6/3/19 3:49 PM
12+ */
13+ public class TestSampleSupplier {
14+
15+ SampleSupplier sampleSupplier = new SampleSupplier ();
16+
17+ Supplier <String > message = Memoize .memoizeSupplier (sampleSupplier ::getMessage );
18+
19+ FunctionPointer <String > message2 = sampleSupplier ::getMessage ;
20+
21+ @ Test
22+ public void testSupplier () {
23+ System .out .println (message .get ());
24+ System .out .println (message .get ());
25+ System .out .println (message .get ());
26+ System .out .println (message .get ());
27+ System .out .println (message .get ());
28+ System .out .println (message .get ());
29+ System .out .println (message .get ());
30+ Assert .assertEquals (SampleSupplier .CALL_TRACKER , 1 );
31+ }
32+
33+ @ Test
34+ public void test () {
35+ System .out .println (message2 .get (6 ));
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments