Package org.haystack

Examples of org.haystack.HDictBuilder


/**
* 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);
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);
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());

        a = new HDictBuilder().add("x").add("y", "str").toDict();
        verifyEq(a, new HDictBuilder().add("x").add("y", "str").toDict());
        verifyEq(a, new HDictBuilder().add("y", "str").add("x").toDict());
        verifyNotEq(a, new HDictBuilder().add("x", "str").add("y", "str").toDict());
        verifyNotEq(a, new HDictBuilder().add("x").add("y", "strx").toDict());
        verifyNotEq(a, new HDictBuilder().add("y", "str").toDict());
        verifyNotEq(a, new HDictBuilder().add("x").toDict());
        verifyNotEq(a, new HDictBuilder().add("x").add("yy", "str").toDict());
    }
View Full Code Here

        verifyNotEq(a, new HDictBuilder().add("x").add("yy", "str").toDict());
    }

    public void testZinc() {
        verifyZinc("", HDict.EMPTY);
        verifyZinc("foo_12", new HDictBuilder().add("foo_12").toDict());
        verifyZinc("fooBar:123ft", new HDictBuilder().add("fooBar", 123, "ft").toDict());
        verifyZinc("dis:\"Bob\" bday:1970-06-03 marker",
                new HDictBuilder().add("dis", "Bob").add("bday", HDate.make(1970, 6, 3)).add("marker").toDict());
        verifyZinc("dis  :  \"Bob\"  bday : 1970-06-03  marker",
                new HDictBuilder().add("dis", "Bob").add("bday", HDate.make(1970, 6, 3)).add("marker").toDict());
    }
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

        addPoint(equip, dis + "-RTemp", "\u00B0F", "return air temp sensor");
        addPoint(equip, dis + "-ZoneSP", "\u00B0F", "zone air temp sp writable");
    }

    private void addPoint(HDict equip, String dis, String unit, String markers) {
        HDictBuilder b = new HDictBuilder().add("id", HRef.make(dis)).add("dis", dis).add("point", HMarker.VAL)
                .add("his", HMarker.VAL).add("siteRef", equip.get("siteRef")).add("equipRef", equip.get("id"))
                .add("kind", unit == null ? "Bool" : "Number").add("tz", "New_York");
        if (unit != null)
            b.add("unit", unit);
        StringTokenizer st = new StringTokenizer(markers);
        while (st.hasMoreTokens())
            b.add(st.nextToken());
        recs.put(dis, b.toDict());
    }
View Full Code Here

        HDict[] rows = new HDict[grid.numRows()];
        Iterator<HRow> it = grid.iterator();
        for (int i = 0; it.hasNext();)
            rows[i++] = it.next();
        for (int i = 0; i < rows.length; ++i)
            rows[i] = new HDictBuilder().add(rows[i]).add("navId", rows[i].id().val).toDict();
        return HGridBuilder.dictsToGrid(rows);
    }
View Full Code Here

     */
    private HGrid getToGrid(HttpServletRequest req) {
        if (req.getParameterMap() == null)
            return HGrid.EMPTY;

        HDictBuilder b = new HDictBuilder();
        @SuppressWarnings("unchecked")
        Iterator<Entry<String, String[]>> it = req.getParameterMap().entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, String[]> entry = it.next();
            String name = entry.getKey();
            String valStr = entry.getValue()[0];

            HVal val;
            try {
                val = new HZincReader(valStr).readScalar();
            }
            catch (Exception e) {
                val = HStr.make(valStr);
            }
            b.add(name, val);
        }
        return HGridBuilder.dictToGrid(b.toDict());
    }
View Full Code Here

TOP

Related Classes of org.haystack.HDictBuilder

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.