2015年1月9日金曜日

開発環境

Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&D (Brett McLaughlin (著)、 Gary Pollice (著)、 David West (著) 、 O'Reilly Media)のChapter 5. Good Design = Flexible Software: Give Your Software a 30-minute Workout、CODE MAGNETS(No. 3245)を解いてみる。

その他参考書籍

CODE MAGNETS(No. 3245)

コード(BBEdit, Emacs)

InstrumentSpec.java

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

public class InstrumentSpec {
    private Map<String, Object>  properties;

    public InstrumentSpec(Map<String, Object> properties) {
        if (properties == null) {
            this.properties = new HashMap<String, Object>();
        } else {
            this.properties = new HashMap<String, Object>(properties);
        }
    }
    
    public Object getProperty(String propertyName) {
        return properties.get(propertyName);
    }
    
    public Map getProperties() {
        return properties;
    }

    public boolean matches(InstrumentSpec otherSpec) {
        for (Iterator i = otherSpec.getProperties().keySet().iterator();
             i.hasNext();) {
            String propertyName = (String)i.next();
            if (!properties.get(propertyName)
                .equals(otherSpec.getProperty(propertyName))) {
                return false;
            }
        }
        return true;
    }
}

入出力結果(Terminal)

$ javac -Xlint:unchecked InstrumentSpec.java
$

0 コメント:

コメントを投稿