Gridarta Editor
Node.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.textedit.textarea.tokenmarker;
21 
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
25 
30 public class Node {
31 
35  private static final char MIN = 'A';
36 
40  private static final char MAX = 'z';
41 
46  private byte id = Token.NULL;
47 
52  @Nullable
53  private final Node @NotNull [] nodes = new Node[MAX - MIN + 1];
54 
62  @NotNull
63  public Node define(final char ch) {
64  final int index = ch - MIN;
65  if (nodes[index] == null) {
66  nodes[index] = new Node();
67  }
68  return nodes[index];
69  }
70 
76  @Nullable
77  public Node lookup(final char ch) {
78  return MIN <= ch && ch <= MAX ? nodes[ch - MIN] : null;
79  }
80 
85  public void setId(final byte id) {
86  this.id = id;
87  }
88 
93  public byte getId() {
94  return id;
95  }
96 
97 }
net.sf.gridarta.textedit.textarea
This package contains the other part of the script editor.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.textedit.textarea.Token.NULL
static final byte NULL
Normal text token id.
Definition: Token.java:26
net.sf
net.sf.gridarta.textedit.textarea.tokenmarker.Node.nodes
final Node[] nodes
The next nodes, or.
Definition: Node.java:53
net.sf.gridarta.textedit.textarea.tokenmarker.Node.MIN
static final char MIN
The minimal character code usable in keys.
Definition: Node.java:35
net.sf.gridarta.textedit
net.sf.gridarta.textedit.textarea.Token
A linked list of tokens.
Definition: Token.java:21
net
net.sf.gridarta.textedit.textarea.tokenmarker.Node.MAX
static final char MAX
The maximal character code usable in keys.
Definition: Node.java:40
net.sf.gridarta.textedit.textarea.tokenmarker.Node.setId
void setId(final byte id)
Sets the id to return for this node.
Definition: Node.java:85
net.sf.gridarta.textedit.textarea.tokenmarker.Node
A node in the tree that is used to store all key-value pairs.
Definition: Node.java:30
net.sf.gridarta.textedit.textarea.tokenmarker.Node.getId
byte getId()
Returns the id for this node.
Definition: Node.java:93
net.sf.gridarta.textedit.textarea.tokenmarker.Node.define
Node define(final char ch)
Looks up or defines the next node for a given character.
Definition: Node.java:63
net.sf.gridarta.textedit.textarea.tokenmarker.Node.id
byte id
The id for the key matching the path between the root node and this node.
Definition: Node.java:46
net.sf.gridarta.textedit.textarea.tokenmarker.Node.lookup
Node lookup(final char ch)
Looks up the next node for a given character.
Definition: Node.java:77