Add topic filter

This commit is contained in:
Thomas Nordquist
2019-01-21 15:07:53 +01:00
parent 4d21c63da9
commit 4c438bd00b
16 changed files with 286 additions and 53 deletions

View File

@@ -10,9 +10,19 @@ export class RingBuffer<T extends Lengthwise> {
private start: number = 0
private end: number = 0
constructor(capacity: number, maxItems = Infinity) {
constructor(capacity: number, maxItems = Infinity, ringBuffer?: RingBuffer<T>) {
this.capacity = capacity
this.maxItems = maxItems
if (ringBuffer) {
this.items = ringBuffer.toArray()
this.end = this.items.length
this.usage = this.items.length
}
}
public clone(): RingBuffer<T> {
return new RingBuffer(this.capacity, this.maxItems, this)
}
public toArray() {

View File

@@ -16,6 +16,17 @@ export class TreeNode {
private cachedLeafes?: TreeNode[]
private cachedLeafMessageCount?: number
public unconnectedClone() {
const node = new TreeNode()
node.message = this.message
node.mqttMessage = this.mqttMessage
node.messageHistory = this.messageHistory.clone()
node.messages = this.messages
node.lastUpdate = this.lastUpdate
return node
}
constructor(sourceEdge?: Edge, message?: Message) {
if (sourceEdge) {
this.sourceEdge = sourceEdge

View File

@@ -5,21 +5,29 @@ interface HasLength {
}
export abstract class TreeNodeFactory {
public static fromEdgesAndValue<T extends HasLength>(edgeNames: string[], value?: T): TreeNode {
public static insertNodeAtPosition(edgeNames: string[], node: TreeNode) {
let currentNode: TreeNode = new Tree()
let edge
for (const edgeName of edgeNames) {
const edge = new Edge(edgeName)
const newNode = new TreeNode(edge)
edge.target = newNode
edge = new Edge(edgeName)
currentNode.addEdge(edge)
currentNode = newNode
currentNode = new TreeNode(edge)
edge.target = currentNode
}
node.sourceEdge = edge
node.sourceEdge!.target = node
}
currentNode.setMessage({
public static fromEdgesAndValue<T extends HasLength>(edgeNames: string[], value?: T): TreeNode {
const node = new TreeNode()
node.setMessage({
value,
length: value ? value.length : 0,
received: new Date(),
})
return currentNode
this.insertNodeAtPosition(edgeNames, node)
return node
}
}