Mercurial > hg > Database > Alice
changeset 290:4074077d118d
Refactor iterating process with for-each sentence.
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Oct 2013 03:26:38 +0900 |
parents | 3f29a59267e2 |
children | 58f2989b045c |
files | src/alice/test/codesegment/api/StartCodeSegment.java src/alice/test/codesegment/local/bitonicsort/DataList.java src/alice/test/codesegment/local/bitonicsort/ShowData.java src/alice/test/codesegment/local/wordcount/CorrectResult.java src/alice/test/topology/aquarium/CheckLocalIndex.java |
diffstat | 5 files changed, 24 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/codesegment/api/StartCodeSegment.java Fri Oct 18 03:22:37 2013 +0900 +++ b/src/alice/test/codesegment/api/StartCodeSegment.java Fri Oct 18 03:26:38 2013 +0900 @@ -18,38 +18,35 @@ @Override public void run() { - for (int i = 0;i<args.length;i++){ - if ("-update".equals(args[i])){ + for (String arg : args) { + if ("-update".equals(arg)) { UpdateCodeSegment cs1 = new UpdateCodeSegment(); cs1.ds1.setKey("key"); int[] array = new int[65536]; array[0] = 0; - ods.update("local", "key", array); - - } else if ("-put".equals(args[i])){ + ods.update("local", "key", array); + + } else if ("-put".equals(arg)) { new PutCodeSegment().execute(); - - } else if ("-take".equals(args[i])){ + + } else if ("-take".equals(arg)) { new PutCodeSegment().execute(); new TakeCodeSegment("num"); - - } else if ("-flip".equals(args[i])){ + + } else if ("-flip".equals(arg)) { new FlipCodeSegment("key").execute(); - } else if ("-peek".equals(args[i])){ + } else if ("-peek".equals(arg)) { System.out.println("start peek Test"); String key = "peek"; int size = 100000; DataList list = new DataList(size); Random rnd = new Random(); - for (int cnt = 0; cnt < size; cnt++){ - list.table[cnt] = rnd.nextInt(100000)+10; + for (int cnt = 0; cnt < size; cnt++) { + list.table[cnt] = rnd.nextInt(100000) + 10; } ods.put(key, list); new PeekCodeSegment(key); - } - - } }
--- a/src/alice/test/codesegment/local/bitonicsort/DataList.java Fri Oct 18 03:22:37 2013 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/DataList.java Fri Oct 18 03:26:38 2013 +0900 @@ -31,9 +31,8 @@ } public void showData(){ - for(int i = 0;i<table.length;i++){ - System.out.print(table[i]+ " "); - + for (int aTable : table) { + System.out.print(aTable + " "); } System.out.println(); }
--- a/src/alice/test/codesegment/local/bitonicsort/ShowData.java Fri Oct 18 03:22:37 2013 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/ShowData.java Fri Oct 18 03:26:38 2013 +0900 @@ -21,16 +21,16 @@ public void run() { System.out.println(System.currentTimeMillis() -SetTask.t +" ms"); int size = 0; - for (int i= 0;i < info.length; i++){ - DataList dlist = info[i].asClass(DataList.class); + for (Receiver anInfo : info) { + DataList dlist = anInfo.asClass(DataList.class); size += dlist.table.length; } DataList list = new DataList(size); int start = 0; - for (int i= 0;i < info.length; i++){ - DataList dlist = info[i].asClass(DataList.class); + for (Receiver anInfo : info) { + DataList dlist = anInfo.asClass(DataList.class); System.arraycopy(dlist.table, 0, list.table, start, dlist.table.length); start += dlist.table.length; }
--- a/src/alice/test/codesegment/local/wordcount/CorrectResult.java Fri Oct 18 03:22:37 2013 +0900 +++ b/src/alice/test/codesegment/local/wordcount/CorrectResult.java Fri Oct 18 03:26:38 2013 +0900 @@ -22,10 +22,10 @@ int line_num = 0; int word_num = 0; Result result; - for (int i=0;i<array.length;i++){ - result = array[i].asClass(Result.class); - line_num +=result.line_num; - word_num +=result.word_num; + for (Receiver anArray : array) { + result = anArray.asClass(Result.class); + line_num += result.line_num; + word_num += result.word_num; } System.out.println(System.currentTimeMillis() - StartWordCount.t); System.out.println(line_num+" "+word_num);
--- a/src/alice/test/topology/aquarium/CheckLocalIndex.java Fri Oct 18 03:22:37 2013 +0900 +++ b/src/alice/test/topology/aquarium/CheckLocalIndex.java Fri Oct 18 03:26:38 2013 +0900 @@ -21,12 +21,10 @@ public void run() { @SuppressWarnings("unchecked") List<String> r = list.asClass(List.class); - for (Iterator<String> ir = r.iterator();ir.hasNext();) { - String node = ir.next(); - if (!node.equals(data.from)){ + for (String node : r) { + if (!node.equals(data.from)) { ods.update(node, data.key, data.getVal()); } - } new CheckLocalIndex(data.key, data.index);