Package org.haystack

Examples of org.haystack.HDict$MapEntry


/**
* DictTest tests the HDict class
*/
public class DictTest extends Test {
    public void testEmpty() {
        HDict tags = new HDictBuilder().toDict();
        verify(tags == HDict.EMPTY);
        verifyEq(tags, HDict.EMPTY);

        // size
        verifyEq(tags.size(), 0);
        verifyEq(tags.isEmpty(), true);

        // missing tag
        verifyEq(tags.has("foo"), false);
        verifyEq(tags.missing("foo"), true);
        verifyEq(tags.get("foo", false), null);
        try {
            tags.get("foo");
            fail();
        }
        catch (UnknownNameException e) {
            verify(true);
        }
        try {
            tags.get("foo", true);
            fail();
        }
        catch (UnknownNameException e) {
            verify(true);
        }
View Full Code Here


            verify(true);
        }
    }

    public void testBasics() {
        HDict tags = new HDictBuilder().add("id", HRef.make("aaaa-bbbb")).add("site").add("geoAddr", "Richmond, Va")
                .add("area", 1200, "ft").add("date", HDate.make(2000, 12, 3)).toDict();

        // size
        verifyEq(tags.size(), 5);
        verifyEq(tags.isEmpty(), false);

        // configured tags
        verifyEq(tags.get("id"), HRef.make("aaaa-bbbb"));
        verifyEq(tags.get("site"), HMarker.VAL);
        verifyEq(tags.get("geoAddr"), HStr.make("Richmond, Va"));
        verifyEq(tags.get("area"), HNum.make(1200, "ft"));
        verifyEq(tags.get("date"), HDate.make(2000, 12, 3));

        // missing tag
        verifyEq(tags.has("foo"), false);
        verifyEq(tags.missing("foo"), true);
        verifyEq(tags.get("foo", false), null);
        try {
            tags.get("foo");
            fail();
        }
        catch (UnknownNameException e) {
            verify(true);
        }
        try {
            tags.get("foo", true);
            fail();
        }
        catch (UnknownNameException e) {
            verify(true);
        }
View Full Code Here

            verify(true);
        }
    }

    public void testEquality() {
        HDict a = new HDictBuilder().add("x").toDict();
        verifyEq(a, new HDictBuilder().add("x").toDict());
        verifyNotEq(a, new HDictBuilder().add("x", 3).toDict());
        verifyNotEq(a, new HDictBuilder().add("y").toDict());
        verifyNotEq(a, new HDictBuilder().add("x").add("y").toDict());
View Full Code Here

        verifyZinc("dis  :  \"Bob\"  bday : 1970-06-03  marker",
                new HDictBuilder().add("dis", "Bob").add("bday", HDate.make(1970, 6, 3)).add("marker").toDict());
    }

    void verifyZinc(String s, HDict tags) {
        HDict x = new HZincReader(s).readDict();
        if (tags.size() <= 1)
            verifyEq(tags.toZinc(), s);
        verifyEq(x, tags);
    }
View Full Code Here

        addSite("C", "Washington", "DC", 3000);
        addSite("D", "Boston", "MA", 4000);
    }

    private void addSite(String dis, String geoCity, String geoState, int area) {
        HDict site = new HDictBuilder().add("id", HRef.make(dis)).add("dis", dis).add("site", HMarker.VAL)
                .add("geoCity", geoCity).add("geoState", geoState).add("geoAddr", "" + geoCity + "," + geoState)
                .add("tz", "New_York").add("area", HNum.make(area, "ft\u00B2")).toDict();
        recs.put(dis, site);

        addMeter(site, dis + "-Meter");
View Full Code Here

        addAhu(site, dis + "-AHU1");
        addAhu(site, dis + "-AHU2");
    }

    private void addMeter(HDict site, String dis) {
        HDict equip = new HDictBuilder().add("id", HRef.make(dis)).add("dis", dis).add("equip", HMarker.VAL)
                .add("elecMeter", HMarker.VAL).add("siteMeter", HMarker.VAL).add("siteRef", site.get("id")).toDict();
        recs.put(dis, equip);
        addPoint(equip, dis + "-KW", "kW", "elecKw");
        addPoint(equip, dis + "-KWH", "kWh", "elecKwh");
    }
View Full Code Here

        addPoint(equip, dis + "-KW", "kW", "elecKw");
        addPoint(equip, dis + "-KWH", "kWh", "elecKwh");
    }

    private void addAhu(HDict site, String dis) {
        HDict equip = new HDictBuilder().add("id", HRef.make(dis)).add("dis", dis).add("equip", HMarker.VAL)
                .add("ahu", HMarker.VAL).add("siteRef", site.get("id")).toDict();
        recs.put(dis, equip);
        addPoint(equip, dis + "-Fan", null, "discharge air fan cmd");
        addPoint(equip, dis + "-Cool", null, "cool cmd");
        addPoint(equip, dis + "-Heat", null, "heat cmd");
View Full Code Here

    //////////////////////////////////////////////////////////////////////////

    @Override
    protected HGrid onNav(String navId) {
        // test database navId is record id
        HDict base = null;
        if (navId != null)
            base = readById(HRef.make(navId));

        // map base record to site, equip, or point
        String filter = "site";
        if (base != null) {
            if (base.has("site"))
                filter = "equip and siteRef==" + base.id().toCode();
            else if (base.has("equip"))
                filter = "point and equipRef==" + base.id().toCode();
            else
                filter = "navNoChildren";
        }

        // read children of base record
View Full Code Here

    //////////////////////////////////////////////////////////////////////////
    // About
    //////////////////////////////////////////////////////////////////////////

    void verifyAbout() throws Exception {
        HDict r = client.about();
        verifyEq(r.getStr("haystackVersion"), "2.0");
        verifyEq(r.getStr("productName"), "SkySpark");
        verifyEq(r.getStr("tz"), HTimeZone.getDefault().name);
    }
View Full Code Here

    void verifyRead() throws Exception {
        // read
        String disA = "Gaithersburg";
        String disB = "Carytown";
        HDict recA = client.read("site and dis==\"" + disA + "\"");
        HDict recB = client.read("site and dis==\"" + disB + "\"");
        verifyEq(recA.dis(), disA);
        verifyEq(client.read("badTagShouldBeThere", false), null);
        try {
            client.read("badTagShouldBeThere");
            fail();
        }
        catch (UnknownRecException e) {
            verifyException(e);
        }

        // readAll
        HGrid grid = client.readAll("site");
        verifyGridContains(grid, "dis", disA);
        verifyGridContains(grid, "dis", disB);
        verifyGridContains(grid, "id", recA.id());
        verifyGridContains(grid, "id", recB.id());

        // readAll limit
        verify(grid.numRows() > 2);
        verifyEq(client.readAll("site", 2).numRows(), 2);

        // readById
        HDict rec = client.readById(recA.id());
        verifyEq(rec.dis(), disA);
        HRef badId = HRef.make("badBadId");
        verifyEq(client.readById(badId, false), null);
        try {
            client.readById(badId);
            fail();
View Full Code Here

TOP

Related Classes of org.haystack.HDict$MapEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.