2014年12月12日金曜日

開発環境

Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&D (Brett McLaughlin (著)、Gary Pollice (著)、David West (著)、 O'Reilly Media)のChapter 1. Well-Designed Apps Rock: Great Software Begins Here、CODE MAGNETS(No. 636)を解いてみる。

その他参考書籍

CODE MAGNETS(No. 636)

コード(BBEdit, Emacs)

Inventory.java

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

public class Inventory {
    private List guitars;

    // ...

    public List search(Guitar searchGuitar) {
        List matchingGuitars = new LinkedList();
        for (Iterator i = guitars.iterator(); i.hasNext();) {
            Guitar guitar = (Guitar)i.next();
            if (searchGuitar.getBuilder() != guitar.getBuilder())
                continue;
            String model = searchGuitar.getModel();
            if ((model != null) && (!model.equals("")) &&
                (!model.equals(guitar.getModel())))
                continue;
            if (searchGuitar.getType() != guitar.getType())
                continue;
            if (searchGuitar.getBackWood() != guitar.getBackWood())
                continue;
            if (searchGuitar.getTopWood() != guitar.getTopWood())
                continue;
            matchingGuitars.add(guitar);
        }
        return matchingGuitars;
    }
}

入出力結果(Terminal)

$ javac Inventory.java
Note: Inventory.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
$

0 コメント:

コメントを投稿