From 0669d3e06127a04c2a419a10664a259847e194fb Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Wed, 10 Dec 2014 14:32:44 +0100 Subject: Assignment No.10 after correction --- .../in/inf/java1/aufgabe10/LineWordCount.java | 79 ---------------------- 1 file changed, 79 deletions(-) delete mode 100644 src/de/fhswf/in/inf/java1/aufgabe10/LineWordCount.java (limited to 'src/de/fhswf/in/inf/java1/aufgabe10/LineWordCount.java') diff --git a/src/de/fhswf/in/inf/java1/aufgabe10/LineWordCount.java b/src/de/fhswf/in/inf/java1/aufgabe10/LineWordCount.java deleted file mode 100644 index e4356a3..0000000 --- a/src/de/fhswf/in/inf/java1/aufgabe10/LineWordCount.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * - */ -package de.fhswf.in.inf.java1.aufgabe10; - -import java.util.concurrent.ConcurrentSkipListMap; - -/** - * Counts the words in one line. - * - * @author $Author: $ - * @version $Revision: $, $Date: $ UTC - */ -public class LineWordCount implements Runnable -{ - - private String[] lineArray; - - private ConcurrentSkipListMap lineWordMap; - - private static final Integer NEWVALUE = new Integer(1); - - /** - * Creates the object which will be threaded. - * - * @param wordMap - * The wordMap into which the counts should be added. - * @param line - * The line to be counted. - */ - public LineWordCount(ConcurrentSkipListMap wordMap, - String line) - { - if (wordMap == null) - { - throw new IllegalArgumentException("WordMap can't be null."); - } - if (line == null) - { - throw new IllegalArgumentException("Line can't be null."); - } - if (line.isEmpty()) - { - throw new IllegalArgumentException("Line can't be empty."); - } - lineWordMap = wordMap; - lineArray = line.split("[^\\p{IsAlphabetic}\\p{Digit}]+"); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Runnable#run() - */ - @Override - public final void run() - { - for (String word : lineArray) - { - // Split creates empty String, if first char is a split char. - if (!word.isEmpty()) - { - word = word.toLowerCase(); - boolean success; - - do - { - success = true; - Integer tmp = lineWordMap.putIfAbsent(word, NEWVALUE); - if (tmp != null) - { - success = lineWordMap.replace(word, tmp, tmp + 1); - } - } - while (!success); - } - } - } -} -- cgit v1.2.3-70-g09d2