Class FacetSet
- Namespace
- Cratis.Chronicle.Concepts.Patterns
- Assembly
- Cratis.Chronicle.dll
Represents an itemset of facets - the combination of contextual dimensions a pattern is expressed in.
public sealed record FacetSet : IEquatable<FacetSet>
- Inheritance
-
FacetSet
- Implements
- Inherited Members
- Extension Methods
Remarks
A set is canonical: facets are ordered by name, at most one facet per name survives, and facets without a value are dropped. Two sets built from the same facts therefore carry the same Key and compare equal, which is what lets a mined pattern be counted once no matter which order its facets were extracted in.
Constructors
FacetSet(IEnumerable<Facet>)
Initializes a new instance of the FacetSet class.
public FacetSet(IEnumerable<Facet> facets)
Parameters
facetsIEnumerable<Facet>The facets the set is made of.
FacetSet(IReadOnlyList<Facet>)
Initializes a new instance of the FacetSet class.
[JsonConstructor]
public FacetSet(IReadOnlyList<Facet> facets)
Parameters
facetsIReadOnlyList<Facet>The facets the set is made of.
Remarks
This is the constructor JSON deserialization binds to: its parameter matches the Facets property by name and type, which the serializer requires. Round-tripping re-runs canonicalization and rebuilds the Key, so a set is canonical no matter where it came from.
Fields
Empty
Represents the empty FacetSet - the set matching every context.
public static readonly FacetSet Empty
Field Value
Properties
Action
Gets the action the set names, or Unspecified when it names none.
public FacetValue Action { get; }
Property Value
ConstrainsAction
Gets a value indicating whether the set names an action rather than only the context it was taken in.
public bool ConstrainsAction { get; }
Property Value
Facets
Gets the facets the set is made of, ordered canonically.
public IReadOnlyList<Facet> Facets { get; }
Property Value
IsEmpty
Gets a value indicating whether the set constrains nothing.
public bool IsEmpty { get; }
Property Value
Key
Gets the canonical FacetSetKey identifying the set.
public FacetSetKey Key { get; }
Property Value
Specificity
Gets how specific the set is - the number of facets it constrains.
public int Specificity { get; }
Property Value
Methods
AsDictionary()
Gets the set as a dictionary of names to values.
public IReadOnlyDictionary<FacetName, FacetValue> AsDictionary()
Returns
- IReadOnlyDictionary<FacetName, FacetValue>
A dictionary holding every facet in the set.
Constrains(FacetName)
Check whether the set constrains a specific facet.
public bool Constrains(FacetName name)
Parameters
Returns
- bool
True when the set constrains it, false when not.
Equals(FacetSet?)
public bool Equals(FacetSet? other)
Parameters
otherFacetSet
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
From(IEnumerable<KeyValuePair<FacetName, FacetValue>>)
Creates a FacetSet from name and value pairs.
public static FacetSet From(IEnumerable<KeyValuePair<FacetName, FacetValue>> facets)
Parameters
facetsIEnumerable<KeyValuePair<FacetName, FacetValue>>The pairs to create from.
Returns
GetHashCode()
public override int GetHashCode()
Returns
IsSubsetOf(FacetSet)
Check whether every facet in this set is also in another set.
public bool IsSubsetOf(FacetSet other)
Parameters
Returns
- bool
True when this set is a subset of the other, false when not.
ToString()
public override string ToString()
Returns
ValueOf(FacetName)
Gets the value of a specific facet.
public FacetValue ValueOf(FacetName name)
Parameters
Returns
- FacetValue
The FacetValue, or Unspecified when the set does not constrain it.
With(FacetName, FacetValue)
Creates a copy of the set with a facet added or replaced.
public FacetSet With(FacetName name, FacetValue value)
Parameters
nameFacetNameThe FacetName to set.
valueFacetValueThe FacetValue to set it to.
Returns
Remarks
Replacing rather than adding: a set holds at most one value per facet, and silently keeping whichever one arrived first would make a context built up in steps depend on the order it was written in.
WithoutActions()
Creates a copy of the set with every action facet removed, leaving the context the action was taken in.
public FacetSet WithoutActions()
Returns
Remarks
This is the half of a pattern a caller can actually describe. Comparing it against an asked context is what lets a pattern answer a question instead of restating it - see IsAction.
Operators
operator ==(FacetSet?, FacetSet?)
public static bool operator ==(FacetSet? left, FacetSet? right)
Parameters
Returns
operator !=(FacetSet?, FacetSet?)
public static bool operator !=(FacetSet? left, FacetSet? right)