Add ColorUtil#fromObject to generate color from object

Add utility method that can generate color based on object hashCode.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2019-02-04 09:50:39 +00:00
parent 6609cc063f
commit e9881dd540

View File

@@ -27,6 +27,7 @@ package net.runelite.client.util;
import com.google.common.primitives.Ints;
import java.awt.Color;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
public class ColorUtil
{
@@ -226,4 +227,20 @@ public class ColorUtil
return null;
}
}
/**
* Creates color from passed object hash code
* @param object object with hashCode
* @param skipAlpha skips alpha
* @return color
*/
public static Color fromObject(@Nonnull final Object object, boolean skipAlpha)
{
int i = object.hashCode();
int r = (i >> 24) & 0xFF;
int g = (i >> 16) & 0xFF;
int b = (i >> 8) & 0xFF;
int a = i & 0xFF;
return new Color(r, g, b, skipAlpha ? 255 : a);
}
}