1 package org.metricshub.jawk.intermediate;
2
3 /*-
4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5 * Jawk
6 * ჻჻჻჻჻჻
7 * Copyright (C) 2006 - 2025 MetricsHub
8 * ჻჻჻჻჻჻
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23 */
24
25 /**
26 * A pointer to a tuple within the list of tuples.
27 * Addresses are used for jumps, especially in reaction to
28 * conditional checks (i.e., if false, jump to else block, etc.).
29 * <p>
30 * Addresses have the following properties:
31 * <ul>
32 * <li>A name (label).
33 * <li>An index into the tuple queue.
34 * </ul>
35 * An address may not necessarily have an index assigned upon creation.
36 * However, upon tuple traversal, all address indexes must
37 * point to a valid tuple.
38 * <p>
39 * All addresses should have a meaningful label.
40 *
41 * @author Danny Daglas
42 */
43 public class Address implements java.io.Serializable {
44
45 private static final long serialVersionUID = 109610985341478678L;
46
47 private final String lbl;
48 private int idx = -1;
49
50 public Address(String lbl) {
51 this.lbl = lbl;
52 }
53
54 /**
55 * The label of the address.
56 * It is particularly useful when dumping tuples to an output stream.
57 *
58 * @return The label of the tuple.
59 */
60 public String label() {
61 return lbl;
62 }
63
64 /**
65 * Set the tuple index of this address.
66 * This can be deferred anytime after creation of the address,
67 * but the index must be assigned prior to traversing the tuples.
68 *
69 * @param index The tuple location within the tuple list (queue)
70 * for this address.
71 */
72 public void assignIndex(int index) {
73 this.idx = index;
74 }
75
76 /**
77 * <p>
78 * index.
79 * </p>
80 *
81 * @return The index into the tuple queue/array.
82 */
83 public int index() {
84 return idx;
85 }
86
87 @Override
88 public String toString() {
89 return label();
90 }
91 }