Bladeren bron

local class

Eric Foster 6 jaren geleden
bovenliggende
commit
56012dac18

+ 52
- 18
ZCWLambdas/.idea/workspace.xml Bestand weergeven

@@ -2,10 +2,12 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="ca475bf5-bfb8-47c8-9af1-d8f2b40d1985" name="Default" comment="">
5
-      <change afterPath="$PROJECT_DIR$/src/main/java/Main.java" afterDir="false" />
6
-      <change afterPath="$PROJECT_DIR$/src/main/java/Person.java" afterDir="false" />
7
-      <change afterPath="$PROJECT_DIR$/src/main/java/PersonSearch.java" afterDir="false" />
8
-      <change beforePath="$PROJECT_DIR$/../README.md" beforeDir="false" />
5
+      <change afterPath="$PROJECT_DIR$/src/main/java/CheckPerson.java" afterDir="false" />
6
+      <change afterPath="$PROJECT_DIR$/src/main/java/PrintPersons.java" afterDir="false" />
7
+      <change afterPath="$PROJECT_DIR$/src/main/java/TestPersonAge.java" afterDir="false" />
8
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
9
+      <change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
10
+      <change beforePath="$PROJECT_DIR$/src/main/java/PersonSearch.java" beforeDir="false" />
9 11
     </list>
10 12
     <ignored path="$PROJECT_DIR$/target/" />
11 13
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -32,16 +34,30 @@
32 34
           </provider>
33 35
         </entry>
34 36
       </file>
35
-      <file leaf-file-name="PersonSearch.java" pinned="false" current-in-tab="false">
36
-        <entry file="file://$PROJECT_DIR$/src/main/java/PersonSearch.java">
37
+      <file leaf-file-name="PrintPersons.java" pinned="false" current-in-tab="false">
38
+        <entry file="file://$PROJECT_DIR$/src/main/java/PrintPersons.java">
39
+          <provider selected="true" editor-type-id="text-editor">
40
+            <state relative-caret-position="105">
41
+              <caret line="7" column="13" lean-forward="true" selection-start-line="7" selection-start-column="13" selection-end-line="7" selection-end-column="13" />
42
+            </state>
43
+          </provider>
44
+        </entry>
45
+      </file>
46
+      <file leaf-file-name="TestPersonAge.java" pinned="false" current-in-tab="true">
47
+        <entry file="file://$PROJECT_DIR$/src/main/java/TestPersonAge.java">
37 48
           <provider selected="true" editor-type-id="text-editor">
38 49
             <state>
39
-              <caret column="27" selection-start-column="27" selection-end-column="27" />
50
+              <caret column="13" selection-start-column="13" selection-end-column="13" />
40 51
             </state>
41 52
           </provider>
42 53
         </entry>
43 54
       </file>
44
-      <file leaf-file-name="Main.java" pinned="false" current-in-tab="true">
55
+      <file leaf-file-name="CheckPerson.java" pinned="false" current-in-tab="false">
56
+        <entry file="file://$PROJECT_DIR$/src/main/java/CheckPerson.java">
57
+          <provider selected="true" editor-type-id="text-editor" />
58
+        </entry>
59
+      </file>
60
+      <file leaf-file-name="Main.java" pinned="false" current-in-tab="false">
45 61
         <entry file="file://$PROJECT_DIR$/src/main/java/Main.java">
46 62
           <provider selected="true" editor-type-id="text-editor">
47 63
             <state relative-caret-position="30">
@@ -55,6 +71,7 @@
55 71
   <component name="FileTemplateManagerImpl">
56 72
     <option name="RECENT_TEMPLATES">
57 73
       <list>
74
+        <option value="Interface" />
58 75
         <option value="Class" />
59 76
       </list>
60 77
     </option>
@@ -68,6 +85,12 @@
68 85
         <option value="$PROJECT_DIR$/src/main/java/Person.java" />
69 86
         <option value="$PROJECT_DIR$/src/main/java/Search.java" />
70 87
         <option value="$PROJECT_DIR$/src/main/java/Main.java" />
88
+        <option value="$PROJECT_DIR$/src/main/java/PersonSearch.java" />
89
+        <option value="$PROJECT_DIR$/src/main/java/CheckPerson.java" />
90
+        <option value="$PROJECT_DIR$/src/main/java/Persons.java" />
91
+        <option value="$PROJECT_DIR$/src/main/java/PrintPersons.java" />
92
+        <option value="$PROJECT_DIR$/src/main/java/TestPerson.java" />
93
+        <option value="$PROJECT_DIR$/src/main/java/TestPersonAge.java" />
71 94
       </list>
72 95
     </option>
73 96
   </component>
@@ -220,22 +243,23 @@
220 243
       <option name="presentableId" value="Default" />
221 244
       <updated>1529496977466</updated>
222 245
       <workItem from="1529496978846" duration="59000" />
223
-      <workItem from="1530014838012" duration="901000" />
246
+      <workItem from="1530014838012" duration="1914000" />
224 247
     </task>
225 248
     <servers />
226 249
   </component>
227 250
   <component name="TimeTrackingManager">
228
-    <option name="totallyTimeSpent" value="960000" />
251
+    <option name="totallyTimeSpent" value="1973000" />
229 252
   </component>
230 253
   <component name="ToolWindowManager">
231 254
     <frame x="-301" y="-1045" width="1862" height="1030" extended-state="0" />
255
+    <editor active="true" />
232 256
     <layout>
233 257
       <window_info anchor="right" id="Palette" order="3" />
234 258
       <window_info anchor="bottom" id="TODO" order="6" />
235 259
       <window_info anchor="right" id="Palette&#9;" order="3" />
236 260
       <window_info id="Image Layers" order="2" />
237 261
       <window_info anchor="right" id="Capture Analysis" order="3" />
238
-      <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
262
+      <window_info active="true" anchor="bottom" id="Event Log" order="7" side_tool="true" visible="true" weight="0.3294979" />
239 263
       <window_info anchor="right" id="Maven Projects" order="3" />
240 264
       <window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
241 265
       <window_info anchor="bottom" id="Version Control" order="7" />
@@ -243,7 +267,7 @@
243 267
       <window_info anchor="bottom" id="Terminal" order="7" />
244 268
       <window_info id="Capture Tool" order="2" />
245 269
       <window_info id="Designer" order="2" />
246
-      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24973147" />
270
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24973147" />
247 271
       <window_info anchor="right" id="Database" order="3" />
248 272
       <window_info anchor="bottom" id="Find" order="1" weight="0.3294979" />
249 273
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
@@ -266,6 +290,16 @@
266 290
     <option name="myLimit" value="2678400000" />
267 291
   </component>
268 292
   <component name="editorHistoryManager">
293
+    <entry file="file://$PROJECT_DIR$/src/main/java/Main.java">
294
+      <provider selected="true" editor-type-id="text-editor">
295
+        <state relative-caret-position="30">
296
+          <caret line="2" selection-start-line="2" selection-end-line="2" />
297
+        </state>
298
+      </provider>
299
+    </entry>
300
+    <entry file="file://$PROJECT_DIR$/src/main/java/CheckPerson.java">
301
+      <provider selected="true" editor-type-id="text-editor" />
302
+    </entry>
269 303
     <entry file="file://$PROJECT_DIR$/src/main/java/Person.java">
270 304
       <provider selected="true" editor-type-id="text-editor">
271 305
         <state relative-caret-position="210">
@@ -279,17 +313,17 @@
279 313
         </state>
280 314
       </provider>
281 315
     </entry>
282
-    <entry file="file://$PROJECT_DIR$/src/main/java/PersonSearch.java">
316
+    <entry file="file://$PROJECT_DIR$/src/main/java/PrintPersons.java">
283 317
       <provider selected="true" editor-type-id="text-editor">
284
-        <state>
285
-          <caret column="27" selection-start-column="27" selection-end-column="27" />
318
+        <state relative-caret-position="105">
319
+          <caret line="7" column="13" lean-forward="true" selection-start-line="7" selection-start-column="13" selection-end-line="7" selection-end-column="13" />
286 320
         </state>
287 321
       </provider>
288 322
     </entry>
289
-    <entry file="file://$PROJECT_DIR$/src/main/java/Main.java">
323
+    <entry file="file://$PROJECT_DIR$/src/main/java/TestPersonAge.java">
290 324
       <provider selected="true" editor-type-id="text-editor">
291
-        <state relative-caret-position="30">
292
-          <caret line="2" selection-start-line="2" selection-end-line="2" />
325
+        <state>
326
+          <caret column="13" selection-start-column="13" selection-end-column="13" />
293 327
         </state>
294 328
       </provider>
295 329
     </entry>

+ 6
- 6
ZCWLambdas/README.md Bestand weergeven

@@ -32,7 +32,7 @@ public class Person {
32 32
 Suppose that the members of your social networking application are stored in a `List<Person>` 
33 33
 instance.
34 34
 
35
-### Approach 1: Create Methods That PersonSearch for Members That Match One Characteristic
35
+### Approach 1: Create Methods That PrintPersons for Members That Match One Characteristic
36 36
 One simplistic approach is to create several methods; each method searches for members that match 
37 37
 one characteristic, such as gender or age. The following method prints members that are older than 
38 38
 a specified age:
@@ -46,7 +46,7 @@ public static void printPersonsOlderThan(List<Person> roster, int age) {
46 46
     }
47 47
 }
48 48
 ```
49
-### Approach 2: Create More Generalized PersonSearch Methods
49
+### Approach 2: Create More Generalized PrintPersons Methods
50 50
 The following method is more generic than printPersonsOlderThan; it prints members within a 
51 51
 specified range of ages:
52 52
 
@@ -67,7 +67,7 @@ trying to create a separate method for each possible search query can still lead
67 67
 You can instead separate the code that specifies the criteria for which you want to search in a different 
68 68
 class.
69 69
 
70
-### Approach 3: Specify PersonSearch Criteria Code in a Local Class
70
+### Approach 3: Specify PrintPersons Criteria Code in a Local Class
71 71
 
72 72
 The following method prints members that match search criteria that you specify:
73 73
 
@@ -98,8 +98,8 @@ interface CheckPerson {
98 98
 ### Your Mission
99 99
 Using the 3rd approach, create a branch for each of the following implementations:
100 100
 
101
-* Specify PersonSearch Criteria Code in a Local Class
102
-* Specify PersonSearch Criteria Code in an Anonymous Class
103
-* Specify PersonSearch Criteria Code with a Lambda Expression
101
+* Specify PrintPersons Criteria Code in a Local Class
102
+* Specify PrintPersons Criteria Code in an Anonymous Class
103
+* Specify PrintPersons Criteria Code with a Lambda Expression
104 104
 
105 105
 **Don't forget your test!**

+ 3
- 0
ZCWLambdas/src/main/java/CheckPerson.java Bestand weergeven

@@ -0,0 +1,3 @@
1
+public interface CheckPerson {
2
+    boolean test(Person p);
3
+}

+ 0
- 2
ZCWLambdas/src/main/java/PersonSearch.java Bestand weergeven

@@ -1,2 +0,0 @@
1
-public class PersonSearch {
2
-}

+ 11
- 0
ZCWLambdas/src/main/java/PrintPersons.java Bestand weergeven

@@ -0,0 +1,11 @@
1
+import java.util.List;
2
+
3
+public class PrintPersons {
4
+    public static void printPersons(List<Person> roster, CheckPerson tester) {
5
+        for (Person p : roster) {
6
+            if (tester.test(p)) {
7
+                p.printPerson();
8
+            }
9
+        }
10
+    }
11
+}

+ 8
- 0
ZCWLambdas/src/main/java/TestPersonAge.java Bestand weergeven

@@ -0,0 +1,8 @@
1
+public class TestPersonAge implements CheckPerson {
2
+    @Override
3
+    public boolean test(Person p) {
4
+        if (low <= p.getAge() && p.getAge() < high) {
5
+            p.printPerson();
6
+        }
7
+    }
8
+}