From 5f3240adef49e4c45cb86b37e0a1faab39698bfc Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Mon, 23 Sep 2013 15:03:29 -0400 Subject: [PATCH] Moved some classes to a non minecraft package These are not directly related to minecraft and i might plan to use them in a future project --- src/com/builtbroken/common/Pair.java | 45 +++++++++++ src/com/builtbroken/common/TextHelper.java | 93 ++++++++++++++++++++++ src/com/builtbroken/common/Triple.java | 48 +++++++++++ 3 files changed, 186 insertions(+) create mode 100644 src/com/builtbroken/common/Pair.java create mode 100644 src/com/builtbroken/common/TextHelper.java create mode 100644 src/com/builtbroken/common/Triple.java diff --git a/src/com/builtbroken/common/Pair.java b/src/com/builtbroken/common/Pair.java new file mode 100644 index 000000000..73423d0b5 --- /dev/null +++ b/src/com/builtbroken/common/Pair.java @@ -0,0 +1,45 @@ +package com.builtbroken.common; + +public class Pair +{ + private final L left; + private final R right; + + public Pair(L left, R right) + { + this.left = left; + this.right = right; + } + + public L left() + { + return left; + } + + public R right() + { + return right; + } + + @Override + public int hashCode() + { + if (left == null || right == null) + { + super.hashCode(); + } + return left.hashCode() ^ right.hashCode(); + } + + @Override + public boolean equals(Object o) + { + if (o == null) + return false; + if (!(o instanceof Pair)) + return false; + Pair pairo = (Pair) o; + return this.left.equals(pairo.left()) && this.right.equals(pairo.right()); + } + +} \ No newline at end of file diff --git a/src/com/builtbroken/common/TextHelper.java b/src/com/builtbroken/common/TextHelper.java new file mode 100644 index 000000000..7cc3eb7c7 --- /dev/null +++ b/src/com/builtbroken/common/TextHelper.java @@ -0,0 +1,93 @@ +package com.builtbroken.common; + +import java.awt.Color; + +public final class TextHelper +{ + public enum TextColor + { + BLACK("\u00a70", 0x000000, 0, 0, 0), + DARKBLUE("\u00a71", 0x0000AA, 0, 0, 170), + DARKGREEN("\u00a72", 0x00AA00, 0, 170, 0), + DARKAQUA("\u00a73", 0x00AAAA, 0, 170, 170), + DARKRED("\u00a74", 0xAA0000, 170, 0, 0), + PURPLE("\u00a75", 0xAA00AA, 170, 0, 170), + GOLD("\u00a76", 0xFFAA00, 255, 170, 0), + GREY("\u00a77", 0xAAAAAA, 170, 170, 170), + DARKGREY("\u00a78", 0x555555, 85, 85, 85), + INDIGO("\u00a79", 0x5555FF, 85, 85, 255), + BRIGHTGREEN("\u00a7a", 0x55FF55, 85, 255, 85), + AQUA("\u00a7b", 0x55FFFF, 85, 255, 255), + RED("\u00a7c", 0xFF5555, 255, 85, 85), + PINK("\u00a7d", 0xFF55FF, 255, 85, 255), + YELLOW("\u00a7e", 0xFFFF55, 255, 255, 85), + WHITE("\u00a7f", 0xFFFFFF, 255, 255, 255); + + private String colorString; + private int hexadecimal; + private Color colorInstance; + + TextColor(String color, int hexadecimalColor, int red, int green, int blue) + { + colorString = color; + hexadecimal = hexadecimalColor; + colorInstance = new Color(red, green, blue); + } + + /** Retrieves the Hexadecimal integer value for the specified Color + * + * @return The Hexadecimal int for the Color **/ + public int getHexValue() + { + return hexadecimal; + } + + /** Retrieves the java.awt.Color instance for the Color + * + * @return the java.awt.Color instance for this color ***/ + public Color getColor() + { + return colorInstance; + } + + /** Retrieves the String that specifies the color of Text within Minecraft + * + * @return String that can be added to the beginning of another String to specify coloration + * in Minecraft **/ + public String getColorString() + { + return colorString; + } + + /** Retrieves an int Array to retrieve the RGB values for the specified Color. Index 0 is the + * Red value, Index 1 is the Green value, and Index 2 is the Blue value. + * + * @return Array of the primitive type int containing the RGB values for the specified color **/ + public int[] getRGBIntArray() + { + return new int[] { colorInstance.getRed(), colorInstance.getGreen(), colorInstance.getBlue() }; + } + } + + public enum TextFormat + { + RANDOMCHARS("\247k"), + BOLD("\247l"), + STRIKE("\247m"), + UNDERLINE("\247n"), + ITALICS("\247o"), + RESETFORMAT("\247r"); + + private final String formatString; + + TextFormat(String format) + { + this.formatString = format; + } + + public final String getFormatString() + { + return formatString; + } + } +} \ No newline at end of file diff --git a/src/com/builtbroken/common/Triple.java b/src/com/builtbroken/common/Triple.java new file mode 100644 index 000000000..a240b7d7c --- /dev/null +++ b/src/com/builtbroken/common/Triple.java @@ -0,0 +1,48 @@ +package com.builtbroken.common; + +public class Triple +{ + private final A aaa; + private final B bbb; + private final C ccc; + + public Triple(A left, B right, C ccc) + { + this.aaa = left; + this.bbb = right; + this.ccc = ccc; + } + + public A getA() + { + return aaa; + } + + public B getB() + { + return bbb; + } + + public C getC() + { + return ccc; + } + + @Override + public int hashCode() + { + return aaa.hashCode() ^ bbb.hashCode() ^ ccc.hashCode(); + } + + @Override + public boolean equals(Object o) + { + if (o == null) + return false; + if (!(o instanceof Triple)) + return false; + Triple pairo = (Triple) o; + return this.aaa.equals(pairo.getA()) && this.bbb.equals(pairo.getB()) && this.ccc.equals(pairo.getC()); + } + +} \ No newline at end of file