envagent.java

来自「一个agent 工具包,可以开发移动设备应用,考虑了安全措施」· Java 代码 · 共 49 行

JAVA
49
字号
import SOMA.agent.*;
import SOMA.naming.*;
import SOMA.naming.domain.*;

import java.util.*;

/**
 * Another try to interact with the Environment and
 * the Domain Name Service.
 *
 * @author	Giulio Piancastelli
 * @version	0.1 - Sunday 10th February, 2002
 */
public class EnvAgent extends Agent {
	
	private Vector placesToVisit = new Vector();
	
	public void run() {
		
		PlaceID home = agentSystem.getPlaceID();
		
		if (home.isDomain()) {
			// Get children domains
			DomainNameService dns = agentSystem.getEnvironment().domainNameService;
			Vector children = dns.getChildrenDNS(); // a Vector of PlaceIDs
			for (int index = children.size() - 1; index >= 0; index--) {
				PlaceID place = (PlaceID) children.get(index);
				placesToVisit.add(place);
			}
			// Get places in this domain
			Vector places = new Vector(Arrays.asList(agentSystem.getPlaces()));
			places.remove(home);
			for (int index = places.size() - 1; index >= 0; index--) {
				PlaceID place = (PlaceID) places.get(index);
				placesToVisit.add(place);
			}
		} else {
			placesToVisit.add(home);
		}
		// Print results
		for (int index = placesToVisit.size() - 1; index >= 0; index--) {
			PlaceID place = (PlaceID) placesToVisit.get(index);
			agentSystem.getOut().println(place);
		}	
		
	}
	
} // end RegionTourAgent

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?