Rename node list properties
This commit is contained in:
parent
083d4efa17
commit
4682d8116d
@ -1,6 +1,5 @@
|
|||||||
package ru.dbotthepony.mc.otm.graph
|
package ru.dbotthepony.mc.otm.graph
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
import net.minecraft.core.Direction
|
||||||
import net.minecraft.core.SectionPos
|
import net.minecraft.core.SectionPos
|
||||||
@ -14,14 +13,10 @@ import kotlin.collections.ArrayList
|
|||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
abstract class Abstract6Graph<T> : IConditionalTickable {
|
abstract class Abstract6Graph<T> : IConditionalTickable {
|
||||||
@JvmField
|
protected val nodes = ArrayList<Graph6Node<T>>()
|
||||||
protected val _nodes = ArrayList<Graph6Node<T>>()
|
fun size() = nodes.size
|
||||||
fun size() = _nodes.size
|
|
||||||
|
|
||||||
private val tickable = ArrayList<Graph6Node<T>>()
|
private val tickable = ArrayList<Graph6Node<T>>()
|
||||||
|
val nodeList: Collection<Graph6Node<T>> = Collections.unmodifiableCollection(nodes)
|
||||||
@JvmField
|
|
||||||
val nodes: Collection<Graph6Node<T>> = Collections.unmodifiableCollection(_nodes)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows storing arbitrary data by external code
|
* Allows storing arbitrary data by external code
|
||||||
@ -33,7 +28,7 @@ abstract class Abstract6Graph<T> : IConditionalTickable {
|
|||||||
abstract fun onNodeAdded(node: Graph6Node<T>)
|
abstract fun onNodeAdded(node: Graph6Node<T>)
|
||||||
|
|
||||||
override val canTick: Boolean
|
override val canTick: Boolean
|
||||||
get() = _nodes.size > 0
|
get() = nodes.size > 0
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
for (i in tickable.size - 1 downTo 0) {
|
for (i in tickable.size - 1 downTo 0) {
|
||||||
@ -48,10 +43,9 @@ abstract class Abstract6Graph<T> : IConditionalTickable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun removeNode(node: Graph6Node<T>) {
|
fun removeNode(node: Graph6Node<T>) {
|
||||||
if (!_nodes.contains(node))
|
if (!nodes.remove(node))
|
||||||
throw IllegalStateException("Not containing node $node")
|
throw IllegalStateException("Not containing node $node")
|
||||||
|
|
||||||
_nodes.remove(node)
|
|
||||||
node.graph = null
|
node.graph = null
|
||||||
onNodeRemoved(node)
|
onNodeRemoved(node)
|
||||||
|
|
||||||
@ -61,10 +55,10 @@ abstract class Abstract6Graph<T> : IConditionalTickable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addNode(node: Graph6Node<T>) {
|
fun addNode(node: Graph6Node<T>) {
|
||||||
if (_nodes.contains(node))
|
if (nodes.contains(node))
|
||||||
throw IllegalStateException("Already containing node $node")
|
throw IllegalStateException("Already containing node $node")
|
||||||
|
|
||||||
_nodes.add(node)
|
nodes.add(node)
|
||||||
node.graph = this
|
node.graph = this
|
||||||
onNodeAdded(node)
|
onNodeAdded(node)
|
||||||
|
|
||||||
@ -78,8 +72,8 @@ abstract class Abstract6Graph<T> : IConditionalTickable {
|
|||||||
return this
|
return this
|
||||||
|
|
||||||
if (size() >= other.size()) {
|
if (size() >= other.size()) {
|
||||||
for (node in other._nodes) {
|
for (node in other.nodes) {
|
||||||
_nodes.add(node)
|
nodes.add(node)
|
||||||
node.graph = this
|
node.graph = this
|
||||||
onNodeAdded(node)
|
onNodeAdded(node)
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun getMatterStorageLevel(): ImpreciseFraction {
|
fun getMatterStorageLevel(): ImpreciseFraction {
|
||||||
var level = ImpreciseFraction.ZERO
|
var level = ImpreciseFraction.ZERO
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val matter = node.value.getMatterHandler()
|
val matter = node.value.getMatterHandler()
|
||||||
|
|
||||||
if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) {
|
if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) {
|
||||||
@ -88,7 +88,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun getMatterStorageMaxLevel(): ImpreciseFraction {
|
fun getMatterStorageMaxLevel(): ImpreciseFraction {
|
||||||
var level = ImpreciseFraction.ZERO
|
var level = ImpreciseFraction.ZERO
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val matter = node.value.getMatterHandler()
|
val matter = node.value.getMatterHandler()
|
||||||
|
|
||||||
if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) {
|
if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) {
|
||||||
@ -106,7 +106,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
var howMuch = howMuch
|
var howMuch = howMuch
|
||||||
var extracted = ImpreciseFraction.ZERO
|
var extracted = ImpreciseFraction.ZERO
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val matter = node.value.getMatterHandler()
|
val matter = node.value.getMatterHandler()
|
||||||
|
|
||||||
if (matter != null) {
|
if (matter != null) {
|
||||||
@ -129,7 +129,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
var howMuch = howMuch
|
var howMuch = howMuch
|
||||||
var received = ImpreciseFraction.ZERO
|
var received = ImpreciseFraction.ZERO
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val matter = node.value.getMatterHandler()
|
val matter = node.value.getMatterHandler()
|
||||||
|
|
||||||
if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) {
|
if (matter != null && matter.direction == MatterDirection.BIDIRECTIONAL) {
|
||||||
@ -152,7 +152,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
var howMuch = howMuch
|
var howMuch = howMuch
|
||||||
var received = ImpreciseFraction.ZERO
|
var received = ImpreciseFraction.ZERO
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val matter = node.value.getMatterHandler()
|
val matter = node.value.getMatterHandler()
|
||||||
|
|
||||||
if (matter != null && matter.direction != MatterDirection.EXTRACT) {
|
if (matter != null && matter.direction != MatterDirection.EXTRACT) {
|
||||||
@ -169,7 +169,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun _insertPattern(state: PatternState, onlyUpdate: Boolean, simulate: Boolean): PatternInsertStatus {
|
private fun _insertPattern(state: PatternState, onlyUpdate: Boolean, simulate: Boolean): PatternInsertStatus {
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val storage = node.value.getPatternHandler()
|
val storage = node.value.getPatternHandler()
|
||||||
|
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
@ -194,7 +194,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun getTasks(): Collection<MatterTask> {
|
fun getTasks(): Collection<MatterTask> {
|
||||||
val list = ArrayList<MatterTask>()
|
val list = ArrayList<MatterTask>()
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val tasks = node.value.getTaskHandler()
|
val tasks = node.value.getTaskHandler()
|
||||||
|
|
||||||
if (tasks != null) {
|
if (tasks != null) {
|
||||||
@ -208,7 +208,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun getStoredPatterns(): Collection<PatternState> {
|
fun getStoredPatterns(): Collection<PatternState> {
|
||||||
val list = ArrayList<PatternState>()
|
val list = ArrayList<PatternState>()
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val storage = node.value.getPatternHandler()
|
val storage = node.value.getPatternHandler()
|
||||||
|
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
@ -222,7 +222,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun getPatternCount(): Long {
|
fun getPatternCount(): Long {
|
||||||
var value = 0L
|
var value = 0L
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val storage = node.value.getPatternHandler()
|
val storage = node.value.getPatternHandler()
|
||||||
|
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
@ -236,7 +236,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun getPatternCapacity(): Long {
|
fun getPatternCapacity(): Long {
|
||||||
var value = 0L
|
var value = 0L
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val storage = node.value.getPatternHandler()
|
val storage = node.value.getPatternHandler()
|
||||||
|
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
@ -248,7 +248,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getPattern(id: UUID): PatternState? {
|
fun getPattern(id: UUID): PatternState? {
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val storage = node.value.getPatternHandler()
|
val storage = node.value.getPatternHandler()
|
||||||
|
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
@ -268,7 +268,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun hasPattern(id: UUID) = getPattern(id) != null
|
fun hasPattern(id: UUID) = getPattern(id) != null
|
||||||
|
|
||||||
fun findPattern(predicate: (PatternState) -> Boolean): PatternState? {
|
fun findPattern(predicate: (PatternState) -> Boolean): PatternState? {
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val storage = node.value.getPatternHandler()
|
val storage = node.value.getPatternHandler()
|
||||||
|
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
@ -288,7 +288,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun findPatterns(predicate: (PatternState) -> Boolean): Collection<PatternState> {
|
fun findPatterns(predicate: (PatternState) -> Boolean): Collection<PatternState> {
|
||||||
val list = ArrayList<PatternState>()
|
val list = ArrayList<PatternState>()
|
||||||
|
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val storage = node.value.getPatternHandler()
|
val storage = node.value.getPatternHandler()
|
||||||
|
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
@ -306,7 +306,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
fun findPatterns(predicate: Item) = findPatterns { it.item == predicate }
|
fun findPatterns(predicate: Item) = findPatterns { it.item == predicate }
|
||||||
|
|
||||||
fun allocateTask(simulate: Boolean): MatterTaskAllocation? {
|
fun allocateTask(simulate: Boolean): MatterTaskAllocation? {
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val tasks = node.value.getTaskHandler()
|
val tasks = node.value.getTaskHandler()
|
||||||
|
|
||||||
if (tasks != null) {
|
if (tasks != null) {
|
||||||
@ -322,7 +322,7 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun notifyTaskCompletion(task: MatterTask): Boolean {
|
fun notifyTaskCompletion(task: MatterTask): Boolean {
|
||||||
for (node in _nodes) {
|
for (node in nodes) {
|
||||||
val tasks = node.value.getTaskHandler()
|
val tasks = node.value.getTaskHandler()
|
||||||
|
|
||||||
if (tasks != null && tasks.notifyTaskCompletion(task)) {
|
if (tasks != null && tasks.notifyTaskCompletion(task)) {
|
||||||
@ -334,37 +334,37 @@ class MatterNetworkGraph : Abstract6Graph<IMatterGraphNode>(), IMatterGraphListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPatternAdded(state: PatternState) {
|
override fun onPatternAdded(state: PatternState) {
|
||||||
for (node in _nodes) node.value.onPatternAdded(state)
|
for (node in nodes) node.value.onPatternAdded(state)
|
||||||
for (node in listeners) node.onPatternAdded(state)
|
for (node in listeners) node.onPatternAdded(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPatternRemoved(state: PatternState) {
|
override fun onPatternRemoved(state: PatternState) {
|
||||||
for (node in _nodes) node.value.onPatternRemoved(state)
|
for (node in nodes) node.value.onPatternRemoved(state)
|
||||||
for (node in listeners) node.onPatternRemoved(state)
|
for (node in listeners) node.onPatternRemoved(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPatternUpdated(new_state: PatternState, old_state: PatternState) {
|
override fun onPatternUpdated(new_state: PatternState, old_state: PatternState) {
|
||||||
for (node in _nodes) node.value.onPatternUpdated(new_state, old_state)
|
for (node in nodes) node.value.onPatternUpdated(new_state, old_state)
|
||||||
for (node in listeners) node.onPatternUpdated(new_state, old_state)
|
for (node in listeners) node.onPatternUpdated(new_state, old_state)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMatterTaskCreated(task: MatterTask) {
|
override fun onMatterTaskCreated(task: MatterTask) {
|
||||||
for (node in _nodes) node.value.onMatterTaskCreated(task)
|
for (node in nodes) node.value.onMatterTaskCreated(task)
|
||||||
for (node in listeners) node.onMatterTaskCreated(task)
|
for (node in listeners) node.onMatterTaskCreated(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMatterTaskUpdated(new_state: MatterTask, old_state: MatterTask) {
|
override fun onMatterTaskUpdated(new_state: MatterTask, old_state: MatterTask) {
|
||||||
for (node in _nodes) node.value.onMatterTaskUpdated(new_state, old_state)
|
for (node in nodes) node.value.onMatterTaskUpdated(new_state, old_state)
|
||||||
for (node in listeners) node.onMatterTaskUpdated(new_state, old_state)
|
for (node in listeners) node.onMatterTaskUpdated(new_state, old_state)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMatterTaskFinished(state: MatterTask) {
|
override fun onMatterTaskFinished(state: MatterTask) {
|
||||||
for (node in _nodes) node.value.onMatterTaskFinished(state)
|
for (node in nodes) node.value.onMatterTaskFinished(state)
|
||||||
for (node in listeners) node.onMatterTaskFinished(state)
|
for (node in listeners) node.onMatterTaskFinished(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMatterTaskRemoved(state: MatterTask) {
|
override fun onMatterTaskRemoved(state: MatterTask) {
|
||||||
for (node in _nodes) node.value.onMatterTaskRemoved(state)
|
for (node in nodes) node.value.onMatterTaskRemoved(state)
|
||||||
for (node in listeners) node.onMatterTaskRemoved(state)
|
for (node in listeners) node.onMatterTaskRemoved(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user