File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
src/demo/java/org/codefx/libfx/collection/transform Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ package org .codefx .libfx .collection .transform ;
2
+
3
+ import java .util .Set ;
4
+
5
+ /**
6
+ * Demonstrates how to use the {@link EqualityTransformingSet}.
7
+ * <p>
8
+ * The demonstrated example is based on the situation that we want a set of strings which uses only their length for
9
+ * equality comparison.
10
+ */
11
+ public class EqualityTransformingSetDemo {
12
+
13
+ /**
14
+ * A set of strings which uses the length for equality.
15
+ */
16
+ private final Set <String > lengthSet ;
17
+
18
+ /**
19
+ * Creates a new demo.
20
+ */
21
+ public EqualityTransformingSetDemo () {
22
+ lengthSet = EqualityTransformingCollectionBuilder
23
+ .forType (String .class )
24
+ .withEquals ((a , b ) -> a .length () == b .length ())
25
+ .withHash (String ::length )
26
+ .buildSet ();
27
+ }
28
+
29
+ /**
30
+ * Runs this demo.
31
+ *
32
+ * @param args
33
+ * command line arguments (will not be used)
34
+ */
35
+ public static void main (String [] args ) {
36
+ EqualityTransformingSetDemo demo = new EqualityTransformingSetDemo ();
37
+
38
+ demo .addSomeElements ();
39
+ }
40
+
41
+ private void addSomeElements () {
42
+ lengthSet .add ("a" );
43
+ lengthSet .add ("b" );
44
+ print (lengthSet .toString ());
45
+ }
46
+
47
+ private static void print () {
48
+ System .out .println ();
49
+ }
50
+
51
+ private static void print (String text ) {
52
+ System .out .println (text );
53
+ }
54
+
55
+ }
You can’t perform that action at this time.
0 commit comments