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

facets IEnumerable<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

facets IReadOnlyList<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

FacetSet

Properties

Action

Gets the action the set names, or Unspecified when it names none.

public FacetValue Action { get; }

Property Value

FacetValue

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

bool

Facets

Gets the facets the set is made of, ordered canonically.

public IReadOnlyList<Facet> Facets { get; }

Property Value

IReadOnlyList<Facet>

IsEmpty

Gets a value indicating whether the set constrains nothing.

public bool IsEmpty { get; }

Property Value

bool

Key

Gets the canonical FacetSetKey identifying the set.

public FacetSetKey Key { get; }

Property Value

FacetSetKey

Specificity

Gets how specific the set is - the number of facets it constrains.

public int Specificity { get; }

Property Value

int

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

name FacetName

The FacetName to check for.

Returns

bool

True when the set constrains it, false when not.

Equals(FacetSet?)

public bool Equals(FacetSet? other)

Parameters

other FacetSet

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

From(IEnumerable<KeyValuePair<FacetName, FacetValue>>)

Creates a FacetSet from name and value pairs.

public static FacetSet From(IEnumerable<KeyValuePair<FacetName, FacetValue>> facets)

Parameters

facets IEnumerable<KeyValuePair<FacetName, FacetValue>>

The pairs to create from.

Returns

FacetSet

A new FacetSet.

GetHashCode()

public override int GetHashCode()

Returns

int

IsSubsetOf(FacetSet)

Check whether every facet in this set is also in another set.

public bool IsSubsetOf(FacetSet other)

Parameters

other FacetSet

The FacetSet to check against.

Returns

bool

True when this set is a subset of the other, false when not.

ToString()

public override string ToString()

Returns

string

ValueOf(FacetName)

Gets the value of a specific facet.

public FacetValue ValueOf(FacetName name)

Parameters

name FacetName

The FacetName to get the value for.

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

name FacetName

The FacetName to set.

value FacetValue

The FacetValue to set it to.

Returns

FacetSet

A new FacetSet.

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

FacetSet

A new FacetSet holding only the context facets.

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

left FacetSet
right FacetSet

Returns

bool

operator !=(FacetSet?, FacetSet?)

public static bool operator !=(FacetSet? left, FacetSet? right)

Parameters

left FacetSet
right FacetSet

Returns

bool