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-2015 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.Nullable;
24 
29 public class Node {
30 
34  private static final char MIN = 'A';
35 
39  private static final char MAX = 'z';
40 
45  @SuppressWarnings("RedundantFieldInitialization")
46  private byte id = Token.NULL;
47 
52  private final Node[] nodes = new Node[(int) MAX - (int) MIN + 1];
53 
61  public Node define(final char ch) {
62  final int index = (int) ch - (int) MIN;
63  if (nodes[index] == null) {
64  nodes[index] = new Node();
65  }
66  return nodes[index];
67  }
68 
74  @Nullable
75  public Node lookup(final char ch) {
76  return MIN <= ch && ch <= MAX ? nodes[(int) ch - (int) MIN] : null;
77  }
78 
83  public void setId(final byte id) {
84  this.id = id;
85  }
86 
91  public byte getId() {
92  return id;
93  }
94 
95 }
static final char MAX
The maximal character code usable in keys.
Definition: Node.java:39
byte getId()
Returns the id for this node.
Definition: Node.java:91
void setId(final byte id)
Sets the id to return for this node.
Definition: Node.java:83
Node define(final char ch)
Looks up or defines the next node for a given character.
Definition: Node.java:61
byte id
The id for the key matching the path between the root node and this node.
Definition: Node.java:46
Base package of all Gridarta classes.
Node lookup(final char ch)
Looks up the next node for a given character.
Definition: Node.java:75
static final char MIN
The minimal character code usable in keys.
Definition: Node.java:34
A linked list of tokens.
Definition: Token.java:21
This package contains the other part of the script editor.
final Node [] nodes
The next nodes, or.
Definition: Node.java:52
A node in the tree that is used to store all key-value pairs.
Definition: Node.java:29