DefaultPerceptorBuilder.java :  » Java-3D » robo-cup-soccer3d-framework » jp » seraph » jsade » perceptor » Java Open Source

Java Open Source » Java 3D » robo cup soccer3d framework 
robo cup soccer3d framework » jp » seraph » jsade » perceptor » DefaultPerceptorBuilder.java
/**
 *
 */
package jp.seraph.jsade.perceptor;

import java.util.HashMap;
import java.util.Map;

import jp.seraph.jsade.message.MessageUtil;
import jp.seraph.jsade.sexpression.Node;

/**
 *
 *
 */
public class DefaultPerceptorBuilder implements PerceptorBuilder {
    /**
     * PerceptorPerceptorBuilderMapPerceptorBuilder
     *
     * @param aBuilderMap
     */
    public DefaultPerceptorBuilder(Map<String, PerceptorBuilder> aBuilderMap){
        this.init(aBuilderMap);
    }

    /**
     *
     */
    public DefaultPerceptorBuilder(){
        Map<String, PerceptorBuilder> tBuilderMap = new HashMap<String, PerceptorBuilder>();

        tBuilderMap.put("GS", new GameStateBuilder());
        tBuilderMap.put("GYR", new GyroBuilder());
        tBuilderMap.put("HJ", new HingeJointBuilder());
        tBuilderMap.put("See", new SeeBuilder());
        tBuilderMap.put("time", new TimeBuilder());
        tBuilderMap.put("FRP", new ForceResistanceBulder());
        tBuilderMap.put("hear", new HearBulder());

        this.init(tBuilderMap);
    }

    private void init(Map<String, PerceptorBuilder> aBuilderMap){
        mBuilderMap = aBuilderMap;
    }

    private Map<String, PerceptorBuilder> mBuilderMap;

    /**
     *
     * @see jp.seraph.jsade.perceptor.PerceptorBuilder#build(jp.seraph.jsade.sexpression.Node)
     */
    public Perceptor build(Node aNode) throws IllegalArgumentException {
        if (aNode.childCount() <= 1 || aNode.getChild(0).isNode())
            throw new IllegalArgumentException();

        String tPerceptorName = aNode.getLeftString();
        PerceptorBuilder tBuilder = mBuilderMap.get(tPerceptorName);
        if (tBuilder == null)
            throw new IllegalArgumentException(MessageUtil.unsupportedPerceptor(tPerceptorName));

        return tBuilder.build(aNode);
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.