RuneHive-Game
Loading...
Searching...
No Matches
ObjectDirection.java
Go to the documentation of this file.
1package com.runehive.game.world.object;
2
3import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
4import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
5
6import java.util.Map;
7import java.util.Optional;
8
9/**
10 * The enumerated type whose elements represent the directions for objects.
11 *
12 * @author lare96 <http://github.com/lare96>
13 * @author Artem Batutin <artembatutin@gmail.com>
14 */
15public enum ObjectDirection {
16
17 /**
18 * The north orientation.
19 */
21
22 /**
23 * The south orientation.
24 */
26
27 /**
28 * The east orientation.
29 */
30 EAST(2),
31
32 /**
33 * The west orientation.
34 */
35 WEST(0);
36
37 /**
38 * The identification of this direction.
39 */
40 private final int id;
41
42 /**
43 * Creates a new {@link ObjectDirection}.
44 */
46 this.id = id;
47 }
48
49 /**
50 * Gets the identification of this direction.
51 *
52 * @return the identification of this direction.
53 */
54 public final int getId() {
55 return id;
56 }
57
58 private static final ObjectDirection[] values = values();
59
60 /**
61 * A mutable {@link Map} of {@code int} keys to {@link
62 * ObjectDirection} values.
63 */
64 private static final Int2ObjectMap<ObjectDirection> idToDirection = new Int2ObjectOpenHashMap<>(values.length);
65
66 /* Populates the {@link #values} cache. */
67 static {
68 for (ObjectDirection orientation : values) {
69 idToDirection.put(orientation.getId(), orientation);
70 }
71 }
72
73 /**
74 * Returns a {@link ObjectDirection} wrapped in an {@link Optional} for the
75 * specified {@code id}.
76 *
77 * @param id The game object orientation id.
78 * @return The optional game object orientation.
79 */
80 public static Optional<ObjectDirection> valueOf(final int id) {
81 return Optional.ofNullable(idToDirection.get(id));
82 }
83
84}
final int id
The identification of this direction.
static Optional< ObjectDirection > valueOf(final int id)
Returns a ObjectDirection wrapped in an Optional for the specified id.
static final Int2ObjectMap< ObjectDirection > idToDirection
A mutable Map of int keys to ObjectDirection values.
ObjectDirection(int id)
Creates a new ObjectDirection.
final int getId()
Gets the identification of this direction.