Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:
this < that => <0
this == that => 0
this > that => >0
This method may also be accessed via the <
<=
<=>
>=
and >
shortcut operators. If not overridden the default
implementation compares the toStr
representations. Also see docLang.
Examples:
3.compare(8) => -1
8.compare(3) => 1
8.compare(8) => 0
3 <=> 8 => -1 // shortcut for 3.compare(8)
Compare this object to the specified for equality. This
method may be accessed via the == and != shortcut operators.
If not overridden the default implementation compares for
reference equality using the === operator. If this method
is overridden, then hash() must also be overridden such that
any two objects which return true for equals() must return
the same value for hash(). This method must accept null
and
return false.
Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.
Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:
Return a string representation of this object.
Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:
a->x a.trap("x", null)
a->x() a.trap("x", null)
a->x = b a.trap("x", [b])
a->x(b) a.trap("x", [b])
a->x(b, c) a.trap("x", [b, c])
The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.
This method called whenever an it-block is applied to an
object. The default implementation calls the function with this
,
and then returns this
.
Static
_Return if the given instance inherits from the spec via nominal typing. Use specIs() to check nominal typing between two types. Also see fits() and specFits() to check via structural typing.
Note that dict values will only match the generic sys.Dict
type. Use fits() for structural type matching.
Examples:
is("hi", Str) >> true
is("hi", Dict) >> false
is({}, Dict) >> true
is({equip}, Equip) >> false
is(Str, Spec) >> true
Static
choiceGiven a choice spec, return the most specific choice subtype implemented by the instance. If the instance implements zero or more than one subtype of the choice, then return null or raise an exception based on the checked flag. The instance may be anything accepted by the toRec() function.
Example:
choiceOf({discharge, duct}, DuctSection) >> DischargeDuct
choiceOf({hot, water}, Fluid) >> HotWater
Static
echoWrite x.toStr
to standard output followed by newline. If x
is null then print "null". If no argument is provided then
print an empty line.
Optional
x: JsObjStatic
fitsReturn if the given instance fits the spec via structural typing. Use specFits() to check structural typing between two types. Also see is() and specIs() to check via nominal typing. Use fitsExplain() to explain why fits returns true or false.
If the val is a Dict, then the default behavior is to only
check the dict's tags against the given spec. In this mode
all spec query slots are ignored. Pass the {graph}
option
to also check queries to validate the graph of entities.
For example, the graph option can be used with equip specs
to validate required points.
Options:
graph
: marker to also check graph of references such as
required pointsignoreRefs
: marker to not validate if refs exist or match
target specExamples:
fits("foo", Str) >> true
fits(123, Str) >> false
fits({equip}, Equip) >> true
fits({equip}, Site) >> false
fits(vav, MyVavSpec) >> validate tags only
fits(vav, MyVavSpec, {graph}) >> validate tags and required points
Static
fitsReturn grid which explains how data fits the given spec. This function takes one or more recs and returns a grid. For each rec zero or more rows are returned with an error why the rec does not fit the given type. If a rec does fit the type, then zero rows are returned for that record.
If you pass null for the spec, then each record is fit
against its declared spec
tag. If a given rec is missing a spec
tag then it is reported an error.
See fits() for list of options.
Example:
// validate tags on records only
readAll(vav and hotWaterHeating).fitsExplain(G36ReheatVav)
// validate tags and required points and other graph queries
readAll(vav and hotWaterHeating).fitsExplain(G36ReheatVav, {graph})
Static
fitsMatch dict recs against specs to find all the specs that fit. The recs argument can be anything accepted by toRecList(). Specs must be a Spec or list of Specs. If specs argument is omitted, then we match against all the non-abstract types currently in scope. Only the most specific subtype is returned.
Result is a grid for each input rec with the following columns:
See fits() for a list of supported fit options.
Example:
readAll(equip).fitsMatchAll
Static
instanceLoad or lookup a instance from a Xeto library by its string or ref qname as a Dict. If not found raise exception or return null based on checked flag.
NOTE: this function returns the instance using Haystack level fidelity
Examples:
instance("icons::apple") // qname string
instance(@icons::apple) // qname Ref id
instance("icons::bad-name") // raises exception if not found
instance("icons::bad-name", false) // unchecked returns null
Optional
checked: booleanStatic
instancesLookup instances from Xeto libs as a list of dicts.
Scope may one of the following:
If the filter is null, then it filters the instances from the scope.
NOTE: this function returns the instances using Haystack level fidelity
Examples:
instances() // all instances in scope
specLib("icons").instances // instances in a given library
instances(null, a and b) // filter instances with filter expression
Static
instantiateCreate the default instance for a given spec. Raise exception if spec is abstract.
The default behavior for dict types is to return a single
Dict. However, if the type has a constrainted query, then an
entire graph can be instantiated via the {graph}
option in
which case a Dict[] is returned. In graph mode an id
is
generated for recs for cross-linking.
Also see xeto::LibNamespace.instantiate.
NOTE: this function forces the haystack
option to force all
non-Haystack scalars to be simple strings.
Options:
graph
: marker tag to instantiate a graph of recsabstract
: marker to supress error if spec is abstractExamples:
// evaluates to 2000-01-01
instantiate(Date)
// evaluates to dict {equip, vav, hotWaterHeating, ...}
instantiate(G36ReheatVav)
// evaluates to dict[] of vav + points from constrained query
instantiate(G36ReheatVav, {graph})
Static
makeStatic
queryEvaluate a relationship query and return record dict. If no
matches found throw UnknownRecErr or return null based on
checked flag. If there are multiple matches it is
indeterminate which one is returned. Subject must be a
record id or dict in the database. Spec must be a Spec
typed as a sys::Query
. Also see queryAll.
Example:
read(point).query(spec("ph::Point.equips"))
Static
queryEvaluate a relationship query and return grid of results.
Subject must be a record id or dict in the database. Spec
must be a Spec typed as a sys::Query
. Also see query.
Options:
limit
: max number of recs to returnsort
: sort by display name Example:
read(ahu).queryAll(spec("ph::Equip.points"))Static
queryEvaluate a relationship query and return the named constraints as a dict. The query slot names are the dict names and the matching record dicts are the dict values. Missing matches are silently ignored and ambiguous matches return an indeterminate record.
Example:
// spec
MyAhu: Equip {
points: {
dat: DischargeAirTempSensor
rat: DischargeAirTempSensor
}
}
// axon
myAhuPoints: read(ahu).queryNamed(spec("mylib::MyAhu.points"))
// result
{
dat: {dis:"DAT", discharge, air, temp, sensor, ...},
rat: {dis:"RAT", return, air, temp, sensor, ...}
}
Static
specLoad or lookup a Xeto spec by its string or ref qname. Return the dict representation. If not found raise exception or return null based on checked flag.
NOTE: returns the same Spec instance as returned by xeto::LibNamespace. The spec meta is modeled using full fidelity and not haystack fidelity. Use specMeta to normalize to haystack fidelity for use inside Axon.
Examples:
spec("ph::Meter") // type string
spec(@ph::Meter) // type id
spec("sys::Spec.of") // slot
spec("foo::Bad") // raises exception if not found
spec("foo::Bad", false) // unchecked returns null
Optional
checked: booleanStatic
specStatic
specStatic
specStatic
specReturn if spec a
inherits from spec b
based on nominal
typing. This method checks the explicit inheritance
hierarchy via specBase(). Use is() to
check if an instance is of a given type. Also see fits()
and specFits() to check using structural
typing.
Examples:
specIs(Str, Scalar) >> true
specIs(Scalar, Scalar) >> false
specIs(Equip, Dict) >> true
specIs(Meter, Equip) >> true
specIs(Meter, Point) >> false
Static
specLoad or lookup a Xeto library by its string or ref name. Return the dict representation. If not found raise exception or return null based on checked flag.
Examples:
specLib("ph.points") // load by dotted name
specLib(@lib:ph.points) // load by lib ref id
specLib("bad.lib.name") // raises exception if not found
specLib("bad.lib.name", false) // unchecked returns null
Optional
checked: booleanStatic
specList Xeto libraries as a list of their dict representation. Is scope is null then return all installed libs (libs not yet loaded will not have their metadata). Otherwise scope must be a filter expression used to filter the dict representation.
Examples:
specLibs() // all installed libs
specLibs(loaded) // only libs loaded into memory
Optional
scope: ExprStatic
specStatic
specStatic
specReturn simple name of spec.
Examples:
specName(Dict) >> "Dict"
specName(Site) >> "Site"
Static
specReturn the Xeto spec of the given value. Raise exception if value type is not mapped into the data type system. Also see is() and fits().
Examples:
specOf("hi") >> sys::Str
specOf(@id) >> sys::Ref
specOf({}) >> sys::Dict
specOf({spec:@ph::Equip}) >> ph::Dict
Optional
checked: booleanStatic
specStatic
specReturn fully qualified name of the spec:
Examples:
specQName(Dict) >> "sys::Dict"
specQName(Site) >> "ph::Site"
Static
specsList Xeto specs as a list of their dict representation. Scope may one of the following:
A filter may be specified to filter the specs found in the
scope. The dict representation for filtering supports a
"slots" tag on each spec with a Dict of the effective slots
name. This allows filtering slots using the syntax slots->someName
.
NOTE: returns the same Spec instances as returned by xeto::LibNamespace. The spec meta is modeled using full fidelity and not haystack fidelity. Use specMeta to normalize to haystack fidelity for use inside Axon.
Examples:
specs() // specs in using scope
specLib("ph").specs // specs in a given library
specs(null, abstract) // filter specs with filter expression
specs(null, slots->ahu) // filter specs have ahu tag
Static
specStatic
specStatic
spec
Axon functions for working with xeto specs