view src/alice/test/topology/share/CheckLocalIndex.java @ 279:2e1d9854a6d6

Refactor iterating process with for-each sentence.
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Fri, 18 Oct 2013 02:02:12 +0900
parents 68f6e0fa4a89
children f60c00746ff6
line wrap: on
line source

package alice.test.topology.share;

import java.util.Iterator;
import java.util.List;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;

public class CheckLocalIndex extends CodeSegment {

	private Receiver data = ids.create(CommandType.PEEK);
	private Receiver list = ids.create(CommandType.PEEK);
	private Receiver host = ids.create(CommandType.PEEK);

	
	public CheckLocalIndex(String key, int index) {
		this.host.setKey("host");
		this.list.setKey("_CLIST");
		this.data.setKey(key, index);
	}
	
	@Override
	public void run() {
		@SuppressWarnings("unchecked")
		List<String> r = list.asClass(List.class);
		int count = 0;
		boolean flag = false;
		for (String node : r) {
			if (node.equals("parent")) {
				flag = true;
			}
			if (!node.equals(this.data.from)) {
				ods.update(node, data.key, data.getVal());
				count++;
			}
		}
		if (count == 0 && flag) {
			ods.put("parent", "data", data.getVal());
		}
		new CheckLocalIndex(data.key, data.index);
		
	}

}