mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Rewrite javadocs for PlotId class
This commit is contained in:
parent
7c328095d7
commit
a6fb7b2358
@ -26,8 +26,8 @@ import java.util.Iterator;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plot (X,Y) tuples for plot locations
|
* The PlotId class represents a Plot's x and y coordinates within a {@link PlotArea}. PlotId x,y values do not correspond to Block locations.
|
||||||
* within a plot area
|
* A PlotId instance can be created using the {@link #of(int, int)} method or parsed from a string using the {@link #fromString(String)} method.
|
||||||
*/
|
*/
|
||||||
public final class PlotId {
|
public final class PlotId {
|
||||||
|
|
||||||
@ -36,10 +36,10 @@ public final class PlotId {
|
|||||||
private final int hash;
|
private final int hash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotId class (PlotId x,y values do not correspond to Block locations)
|
* Constructs a new PlotId with the given x and y coordinates.
|
||||||
*
|
*
|
||||||
* @param x The plot x coordinate
|
* @param x the x-coordinate of the plot
|
||||||
* @param y The plot y coordinate
|
* @param y the y-coordinate of the plot
|
||||||
*/
|
*/
|
||||||
private PlotId(final int x, final int y) {
|
private PlotId(final int x, final int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@ -48,11 +48,11 @@ public final class PlotId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new plot ID instance
|
* Returns a new PlotId instance with the specified x and y coordinates.
|
||||||
*
|
*
|
||||||
* @param x The plot x coordinate
|
* @param x the x-coordinate of the plot
|
||||||
* @param y The plot y coordinate
|
* @param y the y-coordinate of the plot
|
||||||
* @return a new PlotId at x,y
|
* @return a new PlotId instance with the specified x and y coordinates
|
||||||
*/
|
*/
|
||||||
public static @NonNull PlotId of(final int x, final int y) {
|
public static @NonNull PlotId of(final int x, final int y) {
|
||||||
return new PlotId(x, y);
|
return new PlotId(x, y);
|
||||||
@ -74,10 +74,13 @@ public final class PlotId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to parse a plot ID from a string
|
* Returns a PlotId object from the given string, or null if the string is invalid.
|
||||||
|
* The string should be in the format "x;y" where x and y are integers.
|
||||||
|
* The string can also contain any combination of the characters ";_,."
|
||||||
|
* as delimiters.
|
||||||
*
|
*
|
||||||
* @param string ID string
|
* @param string the string to parse
|
||||||
* @return Plot ID, or {@code null} if none could be parsed
|
* @return a PlotId object parsed from the given string, or null if the string is invalid
|
||||||
*/
|
*/
|
||||||
public static @Nullable PlotId fromStringOrNull(final @NonNull String string) {
|
public static @Nullable PlotId fromStringOrNull(final @NonNull String string) {
|
||||||
final String[] parts = string.split("[;_,.]");
|
final String[] parts = string.split("[;_,.]");
|
||||||
@ -95,39 +98,39 @@ public final class PlotId {
|
|||||||
return of(x, y);
|
return of(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the PlotId from the HashCode<br>
|
* Returns a new PlotId instance from the given hash.
|
||||||
* Note: Only accurate for small x,z values (short)
|
|
||||||
*
|
*
|
||||||
* @param hash ID hash
|
* @param hash the hash to unpair
|
||||||
* @return Plot ID
|
* @return a new PlotId instance
|
||||||
*/
|
*/
|
||||||
public static @NonNull PlotId unpair(final int hash) {
|
public static @NonNull PlotId unpair(final int hash) {
|
||||||
return PlotId.of(hash >> 16, hash & 0xFFFF);
|
return PlotId.of(hash >> 16, hash & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ID X component
|
* Returns the x-coordinate of this Plot ID.
|
||||||
*
|
*
|
||||||
* @return X component
|
* @return the x-coordinate of this Plot ID
|
||||||
*/
|
*/
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return this.x;
|
return this.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ID Y component
|
* Returns the y-coordinate of this Plot ID.
|
||||||
*
|
*
|
||||||
* @return Y component
|
* @return the y-coordinate of this Plot ID
|
||||||
*/
|
*/
|
||||||
public int getY() {
|
public int getY() {
|
||||||
return this.y;
|
return this.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next plot ID for claiming purposes
|
* Returns the next Plot ID for claiming purposes based on the current Plot ID.
|
||||||
*
|
*
|
||||||
* @return Next plot ID
|
* @return the next Plot ID
|
||||||
*/
|
*/
|
||||||
public @NonNull PlotId getNextId() {
|
public @NonNull PlotId getNextId() {
|
||||||
final int absX = Math.abs(x);
|
final int absX = Math.abs(x);
|
||||||
@ -159,10 +162,11 @@ public final class PlotId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the PlotId in a relative direction
|
* Returns a new Plot ID in the specified relative direction based on the
|
||||||
|
* current Plot ID.
|
||||||
*
|
*
|
||||||
* @param direction Direction
|
* @param direction the direction in which to get the relative Plot ID
|
||||||
* @return Relative plot ID
|
* @return the relative Plot ID
|
||||||
*/
|
*/
|
||||||
public @NonNull PlotId getRelative(final @NonNull Direction direction) {
|
public @NonNull PlotId getRelative(final @NonNull Direction direction) {
|
||||||
return switch (direction) {
|
return switch (direction) {
|
||||||
@ -193,10 +197,9 @@ public final class PlotId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a String representation of the plot ID where the
|
* Returns a string representation of this Plot ID in the format "x;y".
|
||||||
* components are separated by ";"
|
|
||||||
*
|
*
|
||||||
* @return {@code x + ";" + y}
|
* @return a string representation of this Plot ID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @NonNull String toString() {
|
public @NonNull String toString() {
|
||||||
@ -204,41 +207,40 @@ public final class PlotId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a String representation of the plot ID where the
|
* Returns a string representation of this Plot ID with the specified separator.
|
||||||
* components are separated by a specified string
|
* <p>
|
||||||
|
* The format is {@code x + separator + y}
|
||||||
*
|
*
|
||||||
* @param separator Separator
|
* @param separator the separator to use between the X and Y coordinates
|
||||||
* @return {@code x + separator + y}
|
* @return a string representation of this Plot ID with the specified separator
|
||||||
*/
|
*/
|
||||||
public @NonNull String toSeparatedString(String separator) {
|
public @NonNull String toSeparatedString(String separator) {
|
||||||
return this.getX() + separator + this.getY();
|
return this.getX() + separator + this.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a String representation of the plot ID where the
|
* Returns a string representation of this Plot ID in the format "x,y".
|
||||||
* components are separated by ","
|
|
||||||
*
|
*
|
||||||
* @return {@code x + "," + y}
|
* @return a string representation of this Plot ID
|
||||||
*/
|
*/
|
||||||
public @NonNull String toCommaSeparatedString() {
|
public @NonNull String toCommaSeparatedString() {
|
||||||
return this.getX() + "," + this.getY();
|
return this.getX() + "," + this.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a String representation of the plot ID where the
|
* Returns a string representation of this Plot ID in the format "x_y".
|
||||||
* components are separated by "_"
|
|
||||||
*
|
*
|
||||||
* @return {@code x + "_" + y}
|
* @return a string representation of this Plot ID
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public @NonNull String toUnderscoreSeparatedString() {
|
public @NonNull String toUnderscoreSeparatedString() {
|
||||||
return this.getX() + "_" + this.getY();
|
return this.getX() + "_" + this.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a String representation of the plot ID where the
|
* Returns a string representation of this Plot ID in the format "x-y".
|
||||||
* components are separated by "-"
|
|
||||||
*
|
*
|
||||||
* @return {@code x + "-" + y}
|
* @return a string representation of this Plot ID
|
||||||
*/
|
*/
|
||||||
public @NonNull String toDashSeparatedString() {
|
public @NonNull String toDashSeparatedString() {
|
||||||
return this.getX() + "-" + this.getY();
|
return this.getX() + "-" + this.getY();
|
||||||
@ -250,6 +252,10 @@ public final class PlotId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An iterator that iterates over a range of {@link PlotId}s.
|
||||||
|
* The range is defined by a start and end {@link PlotId}.
|
||||||
|
*/
|
||||||
public static final class PlotRangeIterator implements Iterator<PlotId>, Iterable<PlotId> {
|
public static final class PlotRangeIterator implements Iterator<PlotId>, Iterable<PlotId> {
|
||||||
|
|
||||||
private final PlotId start;
|
private final PlotId start;
|
||||||
@ -265,6 +271,13 @@ public final class PlotId {
|
|||||||
this.y = this.start.getY();
|
this.y = this.start.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link PlotRangeIterator} that iterates over the range of Plots between the specified start and end Plots (inclusive).
|
||||||
|
*
|
||||||
|
* @param start the starting Plot of the range
|
||||||
|
* @param end the ending Plot of the range
|
||||||
|
* @return a new {@link PlotRangeIterator} that iterates over the range of Plots between the specified start and end Plots (inclusive)
|
||||||
|
*/
|
||||||
public static PlotRangeIterator range(final @NonNull PlotId start, final @NonNull PlotId end) {
|
public static PlotRangeIterator range(final @NonNull PlotId start, final @NonNull PlotId end) {
|
||||||
return new PlotRangeIterator(start, end);
|
return new PlotRangeIterator(start, end);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user