浏览代码

finished lab

Connor Dunnigan 6 年前
父节点
当前提交
01b085ce11

+ 12
- 0
pom.xml 查看文件

@@ -7,6 +7,18 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>collections</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 0
- 5
src/main/java/io/zipcoder/ParenChecker.java 查看文件

@@ -21,7 +21,6 @@ public class ParenChecker {
21 21
         }
22 22
         return stack.isEmpty();
23 23
     }
24
-
25 24
     public boolean haveClosing(String str){
26 25
         Stack<Character> stack = new Stack<Character>();
27 26
 
@@ -47,10 +46,6 @@ public class ParenChecker {
47 46
                 }
48 47
             }
49 48
         }
50
-
51 49
         return stack.isEmpty();
52 50
     }
53
-
54
-
55
-
56 51
 }

+ 31
- 2
src/main/java/io/zipcoder/WC.java 查看文件

@@ -2,12 +2,13 @@ package io.zipcoder;
2 2
 
3 3
 import java.io.FileNotFoundException;
4 4
 import java.io.FileReader;
5
-import java.util.Iterator;
6
-import java.util.Scanner;
7 5
 import java.util.*;
8 6
 
7
+
9 8
 public class WC {
9
+
10 10
     private Iterator<String> si;
11
+    private Map<String, Integer> words = new HashMap<>();
11 12
 
12 13
     public WC(String fileName) {
13 14
         try {
@@ -21,4 +22,32 @@ public class WC {
21 22
     public WC(Iterator<String> si) {
22 23
         this.si = si;
23 24
     }
25
+
26
+    public void addWordCount(){
27
+        while(si.hasNext()){
28
+            String input = si.next().toLowerCase();
29
+            String word = input.replaceAll("[^a-z]", "");
30
+            if(words.containsKey(word)){
31
+                words.put(word,words.get(word)+1);
32
+            } else{
33
+                words.put(word,1);
34
+            }
35
+        }
36
+    }
37
+    public void getWordCount(){
38
+        words.entrySet().stream()
39
+                .sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
40
+                .forEach(stringIntegerEntry ->
41
+                        System.out.println(stringIntegerEntry.getValue() +
42
+                                " " + stringIntegerEntry.getKey()));
43
+    }
44
+    public Integer getCountByNameOfWord(String word){
45
+        Integer count = -1;
46
+        for(String wrd : words.keySet()){
47
+            if(wrd.equals(word)){
48
+                return words.get(wrd);
49
+            }
50
+        }
51
+        return count;
52
+    }
24 53
 }

+ 724
- 0
src/main/resources/alad10.txt 查看文件

@@ -0,0 +1,724 @@
1
+******The Project Gutenberg Etext of Aladdin and the Lamp******
2
+******This file should be named alad10.txt or alad10.zip*******
3
+
4
+Corrected EDITIONS of our etexts get a new NUMBER, alad11.txt
5
+VERSIONS based on separate sources get new LETTER, alad10a.txt
6
+ 
7
+This choice was made by popular demand for an etext companion to
8
+Walt Disney's movie Aladdin.  We are considering another follow-
9
+up piece of Beauty and the Beast, if you are interested.
10
+
11
+This electronic text was prepared by Kristin Schultz:
12
+KSCHULTZ@MACC.WISC.EDU
13
+
14
+Information about Project Gutenberg (one page)
15
+
16
+We produce about two million dollars for each hour we work.  The
17
+fifty hours is one conservative estimate for how long it we take
18
+to get any etext selected, entered, proofread, edited, copyright
19
+searched and analyzed, the copyright letters written, etc.  This
20
+projected audience is one hundred million readers.  If our value
21
+per text is nominally estimated at one dollar, then we produce 2
22
+million dollars per hour; this year we will have to do four text
23
+files per month:  thus upping our productivity from one million.
24
+The Goal of Project Gutenberg is to Give Away One Trillion Etext
25
+Files by the December 31, 2001.  [10,000 x 100,000,000=Trillion]
26
+This is ten thousand titles each to one hundred million readers,
27
+which is 10% of the expected number of computer users by the end
28
+of the year 2001.
29
+
30
+We need your donations more than ever!
31
+
32
+All donations should be made to "Project Gutenberg/IBC", and are
33
+tax deductible to the extent allowable by law ("IBC" is Illinois
34
+Benedictine College).  (Subscriptions to our paper newsletter go
35
+to IBC, too)
36
+
37
+For these and other matters, please mail to:
38
+
39
+David Turner, Project Gutenberg
40
+Illinois  Benedictine  College
41
+5700  College  Road
42
+Lisle, IL 60532-0900
43
+
44
+Email requests to:
45
+Internet:    chipmonk@eagle.ibc.edu (David Turner)
46
+Compuserve:  >INTERNET: chipmonk@eagle.ibc.edu (David Turner)
47
+Attmail:     internet!chipmonk@eagle.ibc.edu (David Turner)
48
+MCImail:     (David Turner)
49
+ADDRESS TYPE: MCI / EMS: INTERNET / MBX:chipmonk@eagle.ibc.edu
50
+
51
+When all other email fails try our Michael S. Hart, Executive Director:
52
+hart@vmd.cso.uiuc.edu (internet)   hart@uiucvmd   (bitnet)
53
+
54
+We would prefer to send you this information by email
55
+(Internet, Bitnet, Compuserve, ATTMAIL or MCImail).
56
+
57
+******
58
+If you have an FTP program (or emulator), please:
59
+
60
+FTP directly to the Project Gutenberg archives: Œftp mrcnext.cso.uiuc.edu
61
+login:  anonymous
62
+password:  your@login
63
+cd etext/etext91
64
+or cd etext92
65
+or cd etext93 [for new books]  [now also in cd etext/etext93]
66
+or cd etext/articles [get suggest gut for more information]
67
+dir [to see files]
68
+get or mget [to get files. . .set bin for zip files]
69
+GET 0INDEX.GUT
70
+for a list of books
71
+and
72
+GET NEW GUT for general information
73
+and
74
+MGET GUT* for newsletters.
75
+
76
+**Information prepared by the Project Gutenberg legal advisor** 
77
+(Three Pages) 
78
+
79
+****START**THE SMALL PRINT!**FOR PUBLIC DOMAIN ETEXTS**START****
80
+
81
+Why is this "Small Print!" statement here?  You know: lawyers.
82
+They tell us you might sue us if there is something wrong with
83
+your copy of this etext, even if you got it for free from
84
+someone other than us, and even if what's wrong is not our
85
+fault.  So, among other things, this "Small Print!" statement
86
+disclaims most of our liability to you.  It also tells you how
87
+you can distribute copies of this etext if you want to.
88
+
89
+*BEFORE!* YOU USE OR READ THIS ETEXT
90
+
91
+By using or reading any part of this PROJECT GUTENBERG-tm etext,
92
+you indicate that you understand, agree to and accept this
93
+"Small Print!" statement.  If you do not, you can receive a
94
+refund of the money (if any) you paid for this etext by sending
95
+a request within 30 days of receiving it to the person you got
96
+it from.  If you received this etext on a physical medium (such
97
+as a disk), you must return it with your request.
98
+
99
+ABOUT PROJECT GUTENBERG-TM ETEXTS
100
+
101
+This PROJECT GUTENBERG-tm etext, like most PROJECT GUTENBERG-tm
102
+etexts, is a "public domain" work distributed by Professor
103
+Michael S. Hart through the Project Gutenberg Association (the
104
+"Project").  Among other things, this means that no one owns a
105
+United States copyright on or for this work, so the Project (and
106
+you!) can copy and distribute it in the United States without
107
+permission and without paying copyright royalties.  Special
108
+rules, set forth below, apply if you wish to copy and distribute
109
+this etext under the Project's "PROJECT GUTENBERG" trademark.
110
+
111
+To create these etexts, the Project expends considerable efforts
112
+to identify, transcribe and proofread public domain works.
113
+Despite these efforts, the Project's etexts and any medium they
114
+may be on may contain "Defects".  Among other things, Defects
115
+may take the form of incomplete, inaccurate or corrupt data,
116
+transcription errors, a copyright or other intellectual property
117
+infringement, a defective or damaged disk or other etext medium,
118
+a computer virus, or computer codes that damage or cannot be
119
+read by your equipment.
120
+
121
+DISCLAIMER
122
+
123
+But for the "Right of Replacement or Refund" described below,
124
+[1] the Project (and any other party you may receive this etext
125
+from as a PROJECT GUTENBERG-tm etext) disclaims all liability to
126
+you for damages, costs and expenses, including legal fees, and
127
+[2] YOU HAVE NO REMEDIES FOR NEGLIGENCE OR UNDER STRICT LIABILI-
128
+TY, OR FOR BREACH OF WARRANTY OR CONTRACT, INCLUDING BUT NOT
129
+LIMITED TO INDIRECT, CONSEQUENTIAL, PUNITIVE OR INCIDENTAL
130
+DAMAGES, EVEN IF YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH
131
+DAMAGES.
132
+
133
+If you discover a Defect in this etext within 90 days of
134
+receiving it, you can receive a refund of the money (if any) you
135
+paid for it by sending an explanatory note within that time to
136
+the person you received it from.  If you received it on a
137
+physical medium, you must return it with your note, and such
138
+person may choose to alternatively give you a replacement copy.
139
+If you received it electronically, such person may choose to
140
+alternatively give you a second opportunity to receive it elec-
141
+tronically.
142
+
143
+THIS ETEXT IS OTHERWISE PROVIDED TO YOU "AS-IS".  NO OTHER
144
+WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, ARE MADE TO YOU AS
145
+TO THE ETEXT OR ANY MEDIUM IT MAY BE ON, INCLUDING BUT NOT
146
+LIMITED TO WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
147
+PARTICULAR PURPOSE.
148
+
149
+Some states do not allow disclaimers of implied warranties or
150
+the exclusion or limitation of consequential damages, so the
151
+above disclaimers and exclusions may not apply to you, and you
152
+may have other legal rights.
153
+
154
+INDEMNITY
155
+
156
+You will indemnify and hold the Project, its directors,
157
+officers, members and agents harmless from all liability, cost
158
+and expense, including legal fees, that arise from any
159
+distribution of this etext for which you are responsible, and
160
+from [1] any alteration, modification or addition to the etext
161
+for which you are responsible, or [2] any Defect.
162
+
163
+DISTRIBUTION UNDER "PROJECT GUTENBERG-tm"
164
+
165
+You may distribute copies of this etext electronically, or by
166
+disk, book or any other medium if you either delete this "Small
167
+Print!" and all other references to Project Gutenberg, or:
168
+
169
+[1]  Only give exact copies of it.  Among other things, this re-
170
+     quires that you do not remove, alter or modify the etext or
171
+     this "small print!" statement.  You may however, if you
172
+     wish, distribute this etext in machine readable binary,
173
+     compressed, mark-up, or proprietary form, including any
174
+     form resulting from conversion by word processing or hyper-
175
+     text software, but only so long as *EITHER*:
176
+
177
+     [*]  The etext, when displayed, is clearly readable.  We
178
+          consider an etext *not* clearly readable if it
179
+          contains characters other than those intended by the
180
+          author of the work, although tilde (~), asterisk (*)
181
+          and underline (_) characters may be used to convey
182
+          punctuation intended by the author, and additional
183
+          characters may be used to indicate hypertext links.
184
+
185
+     [*]  The etext may be readily converted by the reader at no
186
+          expense into plain ASCII, EBCDIC or equivalent form by
187
+          the program that displays the etext (as is the case,
188
+          for instance, with most word processors).
189
+
190
+     [*]  You provide, or agree to also provide on request at no
191
+          additional cost, fee or expense, a copy of the etext
192
+          in its original plain ASCII form (or in EBCDIC or
193
+          other equivalent proprietary form).
194
+
195
+[2]  Honor the etext refund and replacement provisions of this
196
+     "Small Print!" statement.
197
+
198
+[3]  Pay a trademark license fee of 20% (twenty percent) of the
199
+     net profits you derive from distributing this etext under
200
+     the trademark, determined in accordance with generally
201
+     accepted accounting practices.  The license fee:
202
+
203
+     [*]  Is required only if you derive such profits.  In
204
+          distributing under our trademark, you incur no
205
+          obligation to charge money or earn profits for your
206
+          distribution.
207
+
208
+     [*]  Shall be paid to "Project Gutenberg Association /
209
+          Illinois Benedictine College" (or to such other person
210
+          as the Project Gutenberg Association may direct)
211
+          within the 60 days following each date you prepare (or
212
+          were legally required to prepare) your year-end tax
213
+          return with respect to your income for that year.
214
+
215
+WHAT IF YOU *WANT* TO SEND MONEY EVEN IF YOU DON'T HAVE TO?
216
+
217
+The Project gratefully accepts contributions in money, time,
218
+scanning machines, OCR software, public domain etexts, royalty
219
+free copyright licenses, and every other sort of contribution
220
+you can think of.  Money should be paid to "Project Gutenberg
221
+Association / Illinois Benedictine College".
222
+
223
+WRITE TO US! We can be reached at:
224
+
225
+Internet:     dircompg@ux1.cso.uiuc.edu
226
+Bitnet:       hart@uiucvmd
227
+CompuServe:   >internet:dircompg@.vmd.cso.uiuc.edu
228
+Attmail:      internet!ux1.cso.uiuc.edu!dircomp
229
+
230
+or
231
+Project Gutenberg
232
+Illinois Benedictine College
233
+5700 College Road
234
+Lisle, IL 60532
235
+
236
+Drafted by CHARLES B. KRAMER, Attorney
237
+CompuServe:  72600,2026
238
+  Internet:  72600.2026@compuserve.com
239
+       Tel:  (212) 254-5093
240
+*END*THE SMALL PRINT! FOR PUBLIC DOMAIN ETEXTS*Ver.08.29.92*END*
241
+
242
+
243
+The Project Gutenberg Etext of Aladdin and the Wonderful Lamp
244
+ 
245
+ 
246
+There once lived a poor tailor, who had a son called Aladdin,
247
+a careless, idle boy who would do nothing but play all day long in
248
+the streets with little idle boys like himself.  This so grieved the
249
+father that he died; yet, in spite of his mother's tears and prayers,
250
+Aladdin did not mend his ways.  One day, when he was playing in the
251
+streets as usual, a stranger asked him his age, and if he was not
252
+the son of Mustapha the tailor.  "I am, sir," replied Aladdin;
253
+"but he died a long while ago."  On this the stranger, who was
254
+a famous African magician, fell on his neck and kissed him saying:
255
+"I am your uncle, and knew you from your likeness to my brother.
256
+Go to your mother and tell her I am coming."  Aladdin ran home
257
+and told his mother of his newly found uncle.  "Indeed, child," she
258
+said, "your father had a brother, but I always thought he was dead."
259
+However, she prepared supper, and bade Aladdin seek his uncle,
260
+who came laden with wine and fruit.  He fell down and kissed the
261
+place where Mustapha used to sit, bidding Aladdin's mother not to
262
+be surprised at not having seen him before, as he had been forty
263
+years out of the country.  He then turned to Aladdin, and asked
264
+him his trade, at which the boy hung his head, while his mother
265
+burst into tears.  On learning that Aladdin was idle and would
266
+learn no trade, he offered to take a shop for him and stock it with
267
+merchandise.  Next day he bought Aladdin a fine suit of clothes and
268
+took him all over the city, showing him the sights, and brought him home
269
+at nightfall to his mother, who was overjoyed to see her son so fine.
270
+ 
271
+Next day the magician led Aladdin into some beautiful gardens a
272
+long way outside the city gates.  They sat down by a fountain and
273
+the magician pulled a cake from his girdle, which he divided
274
+between them.  Then they journeyed onwards till they almost reached
275
+the mountains.  Aladdin was so tired that he begged to go back,
276
+but the magician beguiled him with pleasant stories and lead him
277
+on in spite of himself.  At last they came to two mountains
278
+divided by a narrow valley.  "We will go no farther," said
279
+his uncle.  "I will show you something wonderful; only do you
280
+gather up sticks while I kindle a fire."  When it was lit the
281
+magician threw on it a powder he had about him, at the same time
282
+saying some magical words.  The earth trembled a little in front
283
+of them, disclosing a square flat stone with a brass ring in the
284
+middle to raise it by.  Aladdin tried to run away, but the
285
+magician caught him and gave him a blow that knocked him down.
286
+"What have I done, uncle?" he said piteously; whereupon the
287
+magician said more kindly:  "Fear nothing, but obey me.  Beneath
288
+this stone lies a treasure which is to be yours, and no one else
289
+may touch it, so you must to exactly as I tell you."  At the word
290
+treasure Aladdin forgot his fears, and grasped the ring as he was
291
+told, saying the names of his father and grandfather.  The stone
292
+came up quite easily, and some steps appeared.  "Go down," said
293
+the magician; "at the foot of those steps you will find an open
294
+door leading into three large halls.  Tuck up your gown and go
295
+through them without touching anything, or you will die instantly.
296
+These halls lead into a garden of fine fruit trees.  Walk on till
297
+you come to niche in a terrace where stands a lighted lamp.  Pour
298
+out the oil it contains, and bring it me."  He drew a ring from
299
+his finger and gave it to Aladdin, bidding him prosper.
300
+ 
301
+Aladdin found everything as the magician had said, gathered some
302
+fruit off the trees, and, having got the lamp, arrived at the
303
+mouth of the cave.  The magician cried out in a great hurry:
304
+"Make haste and give me the lamp."  This Aladdin refused to do until
305
+he was out of the cave.  The magician flew into a terrible passion,
306
+and throwing some more powder on to the fire, he said something,
307
+and the stone rolled back into its place.
308
+ 
309
+The man left the country, which plainly showed that he was no
310
+uncle of Aladdin's but a cunning magician, who had read in his
311
+magic books of a wonderful lamp, which would make him the most
312
+powerful man in the world.  Though he alone knew where to find it,
313
+he could only receive it from the hand of another.  He had picked
314
+out the foolish Aladdin for this purpose, intending to get the
315
+lamp and kill him afterwards.
316
+ 
317
+For two days Aladdin remained in the dark, crying and lamenting.
318
+At last he clasped his hands in prayer, and in so doing rubbed
319
+the ring, which the magician had forgotten to take from him.
320
+Immediately an enormous and frightful genie rose out of the earth,
321
+saying:  "What wouldst thou with me?  I am the Slave of the Ring,
322
+and will obey thee in all things."  Aladdin fearlessly replied,
323
+"Deliver me from this place!" whereupon the earth opened, and he
324
+found himself outside.  As soon as his eyes could bear the light
325
+he went home, but fainted on the threshold.  When he came to
326
+himself he told his mother what had passed, and showed her the
327
+lamp and the fruits he had gathered in the garden, which were in
328
+reality precious stones.  He then asked for some food.  "Alas!
329
+child," she said, "I have nothing in the house, but I have spun a
330
+little cotton and will go sell it."  Aladdin bade her keep her
331
+cotton, for he would sell the lamp instead.  As it was very dirty,
332
+she began to rub it, that it might fetch a higher price.
333
+Instantly a hideous genie appeared, and asked what she would have.
334
+She fainted away, but Aladdin, snatching the lamp, said boldly:
335
+"Fetch me something to eat!"  The genie returned with a silver
336
+bowl, twelve silver plates containing rich meats, two silver cups,
337
+and two bottles of wine.  Aladdin's mother, when she came to herself,
338
+said:  "Whence comes this splendid feast?"  "Ask not, but eat,"
339
+replied Aladdin.  So they sat at breakfast till it was dinner-time,
340
+and Aladdin told his mother about the lamp.  She begged him to sell it,
341
+and have nothing to do with devils.  "No," said Aladdin, "since chance
342
+hath made us aware of its virtues, we will use it, and the ring likewise,
343
+which I shall always wear on my finger."  When they had eaten all the
344
+genie had brought, Aladdin sold one of the silver plates, and so on
345
+until none were left.  He then had recourse to the genie, who gave him
346
+another set of plates, and thus they lived many years.
347
+ 
348
+One day Aladdin heard an order from the Sultan proclaimed that
349
+everyone was to stay at home and close his shutters while the
350
+Princess his daughter went to and from the bath.  Aladdin was
351
+seized by a desire to see her face, which was very difficult,
352
+as she always went veiled.  He hid himself behind the door of
353
+the bath, and peeped through a chink.  The Princess lifted her veil
354
+as she went in, and looked so beautiful that Aladdin fell in love
355
+with her at first sight.  He went home so changed that his mother
356
+was frightened.  He told her he loved the Princess so deeply he
357
+could not live without her, and meant to ask her in marriage of
358
+her father.  His mother, on hearing this, burst out laughing, but
359
+Aladdin at last prevailed upon her to go before the Sultan and
360
+carry his request.  She fetched a napkin and laid in it the magic
361
+fruits from the enchanted garden, which sparkled and shone like
362
+the most beautiful jewels.  She took these with her to please the
363
+Sultan, and set out, trusting in the lamp.  The Grand Vizier and
364
+the lords of council had just gone in as she entered the hall and
365
+placed herself in front of the Sultan.  He, however, took no
366
+notice of her.  She went every day for a week, and stood in the
367
+same place.  When the council broke up on the sixth day the Sultan
368
+said to his Vizier:  "I see a certain woman in the audience-chamber
369
+every day carrying something in a napkin.  Call her next time,
370
+that I may find out what she wants."  Next day, at a sign from
371
+the vizier, she went up to the foot of the throne and remained
372
+kneeling until the Sultan said to her:  "Rise, good woman, and
373
+tell me what you want."  She hesitated, so the Sultan sent away
374
+all but the Vizier, and bade her speak freely, promising to
375
+forgive her beforehand for anything she might say.  She then told
376
+him of her son's violent love for the Princess.  "I prayed him to
377
+forget her," she said, "but in vain; he threatened to do some
378
+desperate deed if I refused to go and ask your Majesty for the
379
+hand of the Princess.  Now I pray you to forgive not me alone,
380
+but my son Aladdin."  The Sultan asked her kindly what she had in
381
+the napkin, whereupon she unfolded the jewels and presented them.
382
+He was thunderstruck, and turning to the vizier, said:  "What
383
+sayest thou?  Ought I not to bestow the Princess on one who
384
+values her at such a price?"  The Vizier, who wanted her for his
385
+own son, begged the Sultan to withhold her for three months, in
386
+the course of which he hoped his son could contrive to make him a
387
+richer present.  The Sultan granted this, and told Aladdin's
388
+mother that, though he consented to the marriage, she must not
389
+appear before him again for three months.
390
+ 
391
+Aladdin waited patiently for nearly three months, but after two
392
+had elapsed, his mother, going into the city to buy oil, found
393
+everyone rejoicing, and asked what was going on.  "Do you not
394
+know," was the answer, "that the son of the Grand Vizier is to
395
+marry the Sultan's daughter tonight?"  Breathless she ran and told
396
+Aladdin, who was overwhelmed at first, but presently bethought
397
+him of the lamp.  He rubbed it and the genie appeared, saying:
398
+"What is thy will?"  Aladdin replied:  "The Sultan, as thou knowest,
399
+has broken his promise to me, and the vizier's son is to have
400
+the Princess.  My command is that to-night you bring hither
401
+the bride and bridegroom."  "Master, I obey," said the genie.
402
+Aladdin then went to his chamber, where, sure enough, at
403
+midnight the genie transported the bed containing the vizier's
404
+son and the Princess.  "Take this new-married man," he said, "and
405
+put him outside in the cold, and return at daybreak."  Whereupon
406
+the genie took the vizier's son out of bed, leaving Aladdin with
407
+the Princess.  "Fear nothing," Aladdin said to her; "you are my
408
+wife, promised to me by your unjust father, and no harm will come
409
+to you."  The Princess was too frightened to speak, and passed
410
+the most miserable night of her life, while Aladdin lay down
411
+beside her and slept soundly.  At the appointed hour the genie
412
+fetched in the shivering bridegroom, laid him in his place,
413
+and transported the bed back to the palace.
414
+ 
415
+Presently the Sultan came to wish his daughter good-morning.
416
+The unhappy Vizier's son jumped up and hid himself, while the
417
+Princess would not say a word and was very sorrowful.  The Sultan
418
+sent her mother to her, who said:  "How comes it, child, that you
419
+will not speak to your father?  What has happened?"  The Princess
420
+sighed deeply, and at last told her mother how, during the night,
421
+the bed had been carried into some strange house, and what had
422
+passed there. Her mother did not believe her in the least,
423
+but bade her rise and consider it an idle dream.
424
+ 
425
+The following night exactly the same thing happened, and next
426
+morning, on the Princess's refusing to speak, the Sultan
427
+threatened to cut off her head.  She then confessed all, bidding
428
+him ask the Vizier's son if it were not so.  The Sultan told the
429
+Vizier to ask his son, who owned the truth, adding that, dearly
430
+as he loved the Princess, he had rather die than go through
431
+another such fearful night, and wished to be separated from her.
432
+His wish was granted, and there was an end of feasting and rejoicing.
433
+ 
434
+When the three months were over, Aladdin sent his mother to
435
+remind the Sultan of his promise.  She stood in the same place as
436
+before, and the Sultan, who had forgotten Aladdin, at once
437
+remembered him, and sent for her.  On seeing her poverty the
438
+Sultan felt less inclined than ever to keep his word, and asked
439
+his Vizier's advice, who counselled him to set so high a value on
440
+the Princess that no man living would come up to it.  The Sultan
441
+than turned to Aladdin's mother, saying:  "Good woman, a sultan
442
+must remember his promises, and I will remember mine, but your
443
+son must first send me forty basins of gold brimful of jewels,
444
+carried by forty black slaves, led by as many white ones,
445
+splendidly dressed.  Tell him that I await his answer."  The
446
+mother of Aladdin bowed low and went home, thinking all was lost.
447
+She gave Aladdin the message adding, "He may wait long enough for
448
+your answer!"  "Not so long, mother, as you think," her son replied.
449
+"I would do a great deal more than that for the Princess."
450
+He summoned the genie, and in a few moments the eighty slaves arrived,
451
+and filled up the small house and garden.  Aladdin made them to set
452
+out to the palace, two by two, followed by his mother.  They were so
453
+richly dressed, with such splendid jewels, that everyone crowded
454
+to see them and the basins of gold they carried on their heads.
455
+They entered the palace, and, after kneeling before the Sultan,
456
+stood in a half-circle round the throne with their arms crossed,
457
+while Aladdin's mother presented them to the Sultan.  He hesitated
458
+no longer, but said:  "Good woman, return and tell your son that I
459
+wait for him with open arms."  She lost no time in telling Aladdin,
460
+bidding him make haste.  But Aladdin first called the genie.
461
+"I want a scented bath," he said, "a richly embroidered habit,
462
+a horse surpassing the Sultan's, and twenty slaves to attend me.
463
+Besides this, six slaves, beautifully dressed, to wait on my mother;
464
+and lastly, ten thousand pieces of gold in ten purses."  No sooner said
465
+then done.  Aladdin mounted his horse and passed through the streets,
466
+the slaves strewing gold as they went.  Those who had played with
467
+him in his childhood knew him not, he had grown so handsome.
468
+When the sultan saw him he came down from his throne, embraced him,
469
+and led him into a hall where a feast was spread, intending
470
+to marry him to the Princess that very day.  But Aladdin refused,
471
+saying, "I must build a palace fit for her," and took his leave.
472
+Once home, he said to the genie:  "Build me a palace of the finest
473
+marble, set with jasper, agate, and other precious stones.  In the
474
+middle you shall build me a large hall with a dome, its four walls
475
+of massy gold and silver, each side having six windows, whose lattices,
476
+all except one which is to be left unfinished, must be set with diamonds
477
+and rubies.  There must be stables and horses and grooms and slaves;
478
+go and see about it!"
479
+ 
480
+The palace was finished the next day, and the genie carried him
481
+there and showed him all his orders faithfully carried out, even
482
+to the laying of a velvet carpet from Aladdin's palace to the Sultan's.
483
+Aladdin's mother then dressed herself carefully, and walked to the
484
+palace with her slaves, while he followed her on horseback.
485
+The Sultan sent musicians with trumpets and cymbals to
486
+meet them, so that the air resounded with music and cheers.
487
+She was taken to the Princess, who saluted her and treated her with
488
+great honour.  At night the princess said good-bye to her father,
489
+and set out on the carpet for Aladdin's palace, with his mother
490
+at her side, and followed by the hundred slaves.  She was charmed
491
+at the sight of Aladdin, who ran to receive her.  "Princess," he
492
+said, "blame your beauty for my boldness if I have displeased you."
493
+She told him that, having seen him, she willingly obeyed
494
+her father in this matter.  After the wedding had taken place,
495
+Aladdin led her into the hall, where a feast was spread, and she
496
+supped with him, after which they danced till midnight.
497
+ 
498
+Next day Aladdin invited the Sultan to see the palace.  On
499
+entering the hall with the four-and-twenty windows with their
500
+rubies, diamonds and emeralds, he cried, "It is a world's wonder!
501
+There is only one thing that surprises me.  Was it by accident
502
+that one window was left unfinished?"  "No, sir, by design,"
503
+returned Aladdin.  "I wished your Majesty to have the glory of
504
+finishing this palace."  The Sultan was pleased, and sent for the
505
+best jewelers in the city.  He showed them the unfinished window,
506
+and bade them fit it up like the others.  "Sir," replied their
507
+spokesman, "we cannot find jewels enough."  The Sultan had his own
508
+fetched, which they soon used, but to no purpose, for in a month's
509
+time the work was not half done.  Aladdin knowing that their task
510
+was vain, bade them undo their work and carry the jewels back, and
511
+the genie finished the window at his command.  The Sultan was
512
+surprised to receive his jewels again, and visited Aladdin, who
513
+showed him the window finished.  The Sultan embraced him, the
514
+envious vizier meanwhile hinting that it was the work of enchantment.
515
+ 
516
+Aladdin had won the hearts of the people by his gentle bearing.
517
+He was made captain of the Sultan's armies, and won several
518
+battles for him, but remained as courteous as before, and lived
519
+thus in peace and content for several years.
520
+ 
521
+But far away in Africa the magician remembered Aladdin, and by
522
+his magic arts discovered that Aladdin, instead of perishing
523
+miserably in the cave, had escaped, and had married a princess,
524
+with whom he was living in great honour and wealth.  He knew that
525
+the poor tailor's son could only have accomplished this by means
526
+of the lamp, and travelled night and day till he reached the
527
+capital of China, bent on Aladdin's ruin.  As he passed through
528
+the town he heard people talking everywhere about a marvelous
529
+palace.  "Forgive my ignorance," he asked, "what is the palace you
530
+speak of?"  Have you not heard of Prince Aladdin's palace," was
531
+the reply, "the greatest wonder in the world?  I will direct you
532
+if you have a mind to see it."  The magician thanked him who spoke,
533
+and having seen the palace knew that it had been raised by the Genie
534
+of the Lamp, and became half mad with rage.  He determined to get
535
+hold of the lamp, and again plunge Aladdin into the deepest poverty.
536
+ 
537
+Unluckily, Aladdin had gone a-hunting for eight days, which gave
538
+the magician plenty of time.  He bought a dozen lamps, put them
539
+into a basket, and went to the palace, crying:  "New lamps for old!"
540
+followed by a jeering crowd.  The Princess, sitting in the hall of
541
+four-and-twenty windows, sent a slave to find out what the noise
542
+was about, who came back laughing, so that the Princess scolded her.
543
+"Madam," replied the slave, "who can help laughing to see an old fool
544
+offering to exchange fine new lamps for old ones?"  Another slave,
545
+hearing this, said, "There is an old one on the cornice there which
546
+he can have."  Now this was the magic lamp, which Aladdin had left there,
547
+as he could not take it out hunting with him.  The Princess, not knowing
548
+its value, laughingly bade the slave take it and make the exchange.
549
+She went and said to the magician:  "Give me a new lamp for this."
550
+He snatched it and bade the slave take her choice, amid the jeers
551
+of the crowd.  Little he cared, but left off crying his lamps,
552
+and went out of the city gates to a lonely place, where he remained till
553
+nightfall, when he pulled out the lamp and rubbed it.  The genie
554
+appeared, and at the magician's command carried him, together with
555
+the palace and the Princess in it, to a lonely place in Africa.
556
+ 
557
+Next morning the Sultan looked out of the window towards Aladdin's
558
+palace and rubbed his eyes, for it was gone.  He sent for the
559
+Vizier and asked what had become of the palace.  The Vizier looked
560
+out too, and was lost in astonishment.  He again put it down to
561
+enchantment, and this time the Sultan believed him, and sent
562
+thirty men on horseback to fetch Aladdin back in chains.  They met
563
+him riding home, bound him, and forced him to go with them on foot.
564
+The people, however, who loved him, followed, armed, to see
565
+that he came to no harm.  He was carried before the Sultan, who
566
+ordered the executioner to cut off his head.  The executioner made
567
+Aladdin kneel down, bandaged his eyes, and raised his scimitar to
568
+strike.  At that instant the Vizier, who saw that the crowd had
569
+forced their way into the courtyard and were scaling the walls
570
+to rescue Aladdin, called to the executioner to stay his hand.
571
+The people, indeed, looked so threatening that the Sultan gave
572
+way and ordered Aladdin to be unbound, and pardoned him in the
573
+sight of the crowd.  Aladdin now begged to know what he had done.
574
+"False wretch!" said the Sultan, "come hither," and showed him from
575
+the window the place where his palace had stood.  Aladdin was so
576
+amazed he could not say a word.  "Where is your palace and my
577
+daughter?" demanded the Sultan.  "For the first I am not so deeply
578
+concerned, but my daughter I must have, and you must find her or
579
+lose your head."  Aladdin begged for forty days in which to find
580
+her, promising if he failed to return at suffer death at the
581
+Sultan's pleasure.  His prayer was granted, and he went forth
582
+sadly from the Sultan's presence.
583
+ 
584
+For three days he wandered about like a madman, asking everyone
585
+what had become of his palace, but they only laughed and pitied him.
586
+He came to the banks of a river, and knelt down to say his prayers
587
+before throwing himself in.  In doing so he rubbed the ring he
588
+still wore.  The genie he had seen in the cave appeared, and
589
+asked his will.  "Save my life, genie," said Aladdin, "and bring
590
+my palace back."  That is not in my power," said the genie;
591
+"I am only the Slave of the Ring; you must ask him of the lamp."
592
+"Even so," said Aladdin, "but thou canst take me to the palace,
593
+and set me down under my dear wife's window."  He at once found
594
+himself in Africa, under the window of the Princess, and fell
595
+asleep out of sheer weariness.
596
+ 
597
+He was awakened by the singing of the birds, and his heart was lighter.
598
+He saw plainly that all his misfortunes were owning to the loss of the lamp,
599
+and vainly wondered who had robbed him of it.
600
+ 
601
+That morning the Princess rose earlier than she had done since
602
+she had been carried into Africa by the magician, whose company
603
+she was forced to endure once a day.  She, however, treated him
604
+so harshly that he dared not live there altogether.  As she
605
+was dressing, one of her women looked out and saw Aladdin.
606
+The Princess ran and opened the window, and at the noise she made,
607
+Aladdin looked up.  She called to him to come to her, and great
608
+was the joy of these lovers at seeing each other again.  After he
609
+had kissed her Aladdin said:  "I beg of you, Princess, in God's
610
+name, before we speak of anything else, for your own sake and
611
+mine, tell me what has become of an old lamp I left on the cornice
612
+in the hall of four-and-twenty windows when I went a-hunting."
613
+"Alas," she said, "I am the innocent cause of our sorrows," and
614
+told him of the exchange of the lamp.  "Now I know," cried
615
+Aladdin, "that we have to thank the African magician for this!
616
+Where is the lamp?"  "He carries it about with him," said the
617
+Princess.  "I know, for he pulled it out of his breast to show me.
618
+He wishes me to break my faith with you and marry him, saying that
619
+you were beheaded by my father's command.  He is forever speaking
620
+ill of you, but I only reply by my tears.  If I persist, I doubt
621
+not but he will use violence."  Aladdin comforted her, and left
622
+her for a while.  He changed clothes with the first person he met
623
+in the town, and having bought a certain powder returned to the
624
+Princess, who let him in by a little side door.  "Put on your
625
+most beautiful dress," he said to her, "and receive the magician
626
+with smiles, leading him to believe that you have forgotten me.
627
+Invite him to sup with you, and say you wish to taste the wine of
628
+his country.  He will go for some, and while he is gone I will tell
629
+you what to do."  She listened carefully to Aladdin and when he
630
+left her, arrayed herself gaily for the first time since she left
631
+China.  She put on a girdle and head-dress of diamonds and seeing
632
+in a glass that she was more beautiful than ever, received the
633
+magician, saying, to his great amazement:  "I have made up my mind
634
+that Aladdin is dead, and that all my tears will not bring him
635
+back to me, so I am resolved to mourn no more, and have therefore
636
+invited you to sup with me; but I am tired of the wines of China,
637
+and would fain taste those of Africa."  The magician flew to his
638
+cellar, and the Princess put the powder Aladdin had given her in
639
+her cup.  When he returned she asked him to drink her health in
640
+the wine of Africa, handing him her cup in exchange for his, as a
641
+sign she was reconciled to him.  Before drinking the magician made
642
+her a speech in praise of her beauty, but the Princess cut him
643
+short, saying:  "Let us drink first, and you shall say what you
644
+will afterwards."  She set her cup to her lips and kept it there,
645
+while the magician drained his to the dregs and fell back lifeless.
646
+The Princess then opened the door to Aladdin, and flung her arms
647
+around his neck; but Aladdin went to the dead magician, took the
648
+lamp out of his vest, and bade the genie carry the palace and all
649
+in it back to China.  This was done, and the Princess in her chamber
650
+felt only two little shocks, and little thought she was home again.
651
+ 
652
+The Sultan, who was sitting in his closet, mourning for his lost
653
+daughter, happened too look up, and rubbed his eyes, for there
654
+stood the palace as before!  He hastened thither, and Aladdin
655
+received him in the hall of the four-and-twenty windows, with the
656
+Princess at his side.  Aladdin told him what had happened, and
657
+showed him the dead body of the magician, that he might believe.
658
+A ten days' feast was proclaimed, and it seemed as if Aladdin might
659
+now live the rest of his life in peace; but it was not meant to be.
660
+ 
661
+The African magician had a younger brother, who was, if possible,
662
+more wicked and more cunning than himself.  He travelled to China
663
+to avenge his brother's death, and went to visit a pious woman
664
+called Fatima, thinking she might be of use to him.  He entered
665
+her cell and clapped a dagger to her breast, telling her to rise
666
+and do his bidding on pain of death.  He changed clothes with her,
667
+coloured his face like hers, put on her veil, and murdered her,
668
+that she might tell no tales.  Then he went towards the palace of
669
+Aladdin, and all the people, thinking he was the holy woman,
670
+gathered round him, kissing his hands and begging his blessing.
671
+When he got to the palace there was such a noise going on round
672
+him that the Princess bade her slave look out the window and ask
673
+what was the matter.  The slave said it was the holy woman, curing
674
+people by her touch of their ailments, whereupon the Princess,
675
+who had long desired to see Fatima, sent for her.  On coming to
676
+the Princess the magician offered up a prayer for her health and
677
+prosperity.  When he had done the Princess made him sit by her,
678
+and begged him to stay with her always.  The false Fatima, who
679
+wished for nothing better, consented, but kept his veil down for
680
+fear of discovery.  The princess showed him the hall, and asked
681
+him what he thought of it.  "It is truly beautiful," said the
682
+false Fatima.  "In my mind it wants but one thing."  And what is
683
+that?" said the Princess.  "If only a roc's egg," replied he,
684
+"were hung up from the middle of this dome, it would be the
685
+wonder of the world."
686
+ 
687
+After this the Princess could think of nothing but the roc's egg,
688
+and when Aladdin returned from hunting he found her in a very ill
689
+humour.  He begged to know what was amiss, and she told him that
690
+all her pleasure in the hall was spoilt or want of a roc's egg
691
+hanging from the dome.  "If that is all," replied Aladdin, "you
692
+shall soon be happy."  He left her and rubbed the lamp, and when
693
+the genie appeared commanded him to bring a roc's egg.  The genie
694
+gave such a loud and terrible shriek that the hall shook.
695
+ 
696
+"Wretch!" he cried, "is it not enough that I have done everything
697
+for you, but you must command me to bring my master and hang him
698
+up in the midst of this dome?  You and your wife and your palace
699
+deserve to be burnt to ashes, but that this request does not come
700
+from you, but from the brother of the African magician, whom you
701
+destroyed.  He is now in your palace disguised as the holy woman,
702
+whom he murdered.  He it was who put that wish into your wife's head.
703
+Take care of yourself, for he means to kill you."  So saying, the
704
+genie disappeared.
705
+ 
706
+Aladdin went back to the Princess, saying his head ached,
707
+and requesting that the holy Fatima should be fetched to
708
+lay her hands on it.  But when the magician came near,
709
+Aladdin, seizing his dagger, pierced him to the heart.
710
+"What have you done?" cried the Princess.  "You have
711
+killed the holy woman!"  "Not so," replied Aladdin,
712
+"but a wicked magician," and told her of how she had
713
+been deceived.
714
+ 
715
+After this Aladdin and his wife lived in peace.
716
+He succeeded the Sultan when he died, and reigned
717
+for many years, leaving behind him a long line of kings.
718
+
719
+
720
+ 
721
+End of the Project Gutenberg Etext of Aladdin and the Wonderful Lamp
722
+
723
+
724
+

+ 8
- 0
src/main/resources/someTextFile.txt 查看文件

@@ -0,0 +1,8 @@
1
+this is a sample test file to 
2
+validate the number of words
3
+being counted by the word counter 
4
+program
5
+
6
+word word word
7
+count count count count
8
+the the the the the the the 

+ 23
- 3
src/test/java/io/zipcoder/WCTest.java 查看文件

@@ -3,9 +3,29 @@ package io.zipcoder;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
-import java.util.ArrayList;
7
-import java.util.Arrays;
8
-
9 6
 public class WCTest {
10 7
 
8
+    @Test
9
+    public void testCounterWithStory(){
10
+        WC wordCounter = new WC(WC.class.getResource("/alad10.txt").getFile());
11
+        wordCounter.addWordCount();
12
+        wordCounter.getWordCount();
13
+        Integer expCount = 250;
14
+        Integer actCount = wordCounter.getCountByNameOfWord("and");
15
+        //Then
16
+        Assert.assertEquals(expCount,actCount);
17
+    }
18
+    @Test
19
+    public void testCounterWithTestFile(){
20
+
21
+        //Given
22
+        WC wordCounter = new WC(WC.class.getResource("/someTextFile.txt").getFile());
23
+        //When
24
+        wordCounter.addWordCount();
25
+        wordCounter.getWordCount();
26
+        Integer expCount = 9;
27
+        Integer actCount = wordCounter.getCountByNameOfWord("the");
28
+        //Then
29
+        Assert.assertEquals(expCount,actCount);
30
+    }
11 31
 }