Mercurial > hg > Database > Alice
view src/alice/test/codesegment/local/wordcount/WordCount.java @ 246:6f8236208875
not use MappedByteBuffer
author | sugi |
---|---|
date | Tue, 21 May 2013 16:29:49 +0900 |
parents | a560b92bfd72 |
children | 913ee9dfec4f |
line wrap: on
line source
package alice.test.codesegment.local.wordcount; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; public class WordCount extends CodeSegment{ private Receiver info1 = ids.create(CommandType.TAKE); public WordCount(){ info1.setKey("array"); } @Override public void run() { Range r = info1.asClass(Range.class); int word_flag = 0; int word_num = 0; int line_num = 0; int i = 0; for (; i < r.array.length; i++) { if (r.array[i] == 0x20) { // 空白 word_flag = 1; } else if (r.array[i] == 0x0A) { // 改行 line_num += 1; word_flag = 1; } else { word_num += word_flag; word_flag = 0; } } //System.out.println(i); //System.out.println(r.array.length); word_num += word_flag; if (r.nextchar!='\0'){ // null means last block // buf.get(r.end) is next block's char. // buf.get(r.end-1) is this block's last char if ((r.array[i-1] == 0x0A||r.array[i-1] == 0x20) && (r.nextchar == 0x0A||r.nextchar == 0x20)){ word_num--; } } Result result = new Result(line_num,word_num); ods.put("result", result); new WordCount(); } }