@SuppressWarnings("ConstantConditions") @Test void testNullRejected() { assertThrows(NullPointerException.class, () -> NamedTextColor.nearestTo(null), "color"); }
public static @NonNull NamedTextColor nearestTo(final @NonNull TextColor any) { if(any instanceof NamedTextColor) { return (NamedTextColor) any; } requireNonNull(any, "color"); int matchedDistance = Integer.MAX_VALUE; NamedTextColor match = VALUES.get(0); for(int i = 0, length = VALUES.size(); i < length; i++) { final NamedTextColor potential = VALUES.get(i); final int distance = distanceSquared(any, potential); if(distance < matchedDistance) { match = potential; matchedDistance = distance; } if(distance == 0) { break; } } return match; }
NamedTextColor implements TextColor { public static @NonNull NamedTextColor nearestTo(final @NonNull TextColor any) { if(any instanceof NamedTextColor) { return (NamedTextColor) any; } requireNonNull(any, "color"); int matchedDistance = Integer.MAX_VALUE; NamedTextColor match = VALUES.get(0); for(int i = 0, length = VALUES.size(); i < length; i++) { final NamedTextColor potential = VALUES.get(i); final int distance = distanceSquared(any, potential); if(distance < matchedDistance) { match = potential; matchedDistance = distance; } if(distance == 0) { break; } } return match; } }
NamedTextColor implements TextColor { public static @NonNull NamedTextColor nearestTo(final @NonNull TextColor any) { if(any instanceof NamedTextColor) { return (NamedTextColor) any; } requireNonNull(any, "color"); int matchedDistance = Integer.MAX_VALUE; NamedTextColor match = VALUES.get(0); for(int i = 0, length = VALUES.size(); i < length; i++) { final NamedTextColor potential = VALUES.get(i); final int distance = distanceSquared(any, potential); if(distance < matchedDistance) { match = potential; matchedDistance = distance; } if(distance == 0) { break; } } return match; } private  NamedTextColor(final String name, final int value); }
NamedTextColor implements TextColor { public static @NonNull NamedTextColor nearestTo(final @NonNull TextColor any) { if(any instanceof NamedTextColor) { return (NamedTextColor) any; } requireNonNull(any, "color"); int matchedDistance = Integer.MAX_VALUE; NamedTextColor match = VALUES.get(0); for(int i = 0, length = VALUES.size(); i < length; i++) { final NamedTextColor potential = VALUES.get(i); final int distance = distanceSquared(any, potential); if(distance < matchedDistance) { match = potential; matchedDistance = distance; } if(distance == 0) { break; } } return match; } private  NamedTextColor(final String name, final int value); static @Nullable NamedTextColor ofExact(final int value); static @NonNull NamedTextColor nearestTo(final @NonNull TextColor any); @Override int value(); @Override @NonNull String toString(); }
NamedTextColor implements TextColor { public static @NonNull NamedTextColor nearestTo(final @NonNull TextColor any) { if(any instanceof NamedTextColor) { return (NamedTextColor) any; } requireNonNull(any, "color"); int matchedDistance = Integer.MAX_VALUE; NamedTextColor match = VALUES.get(0); for(int i = 0, length = VALUES.size(); i < length; i++) { final NamedTextColor potential = VALUES.get(i); final int distance = distanceSquared(any, potential); if(distance < matchedDistance) { match = potential; matchedDistance = distance; } if(distance == 0) { break; } } return match; } private  NamedTextColor(final String name, final int value); static @Nullable NamedTextColor ofExact(final int value); static @NonNull NamedTextColor nearestTo(final @NonNull TextColor any); @Override int value(); @Override @NonNull String toString(); static final NamedTextColor BLACK; static final NamedTextColor DARK_BLUE; static final NamedTextColor DARK_GREEN; static final NamedTextColor DARK_AQUA; static final NamedTextColor DARK_RED; static final NamedTextColor DARK_PURPLE; static final NamedTextColor GOLD; static final NamedTextColor GRAY; static final NamedTextColor DARK_GRAY; static final NamedTextColor BLUE; static final NamedTextColor GREEN; static final NamedTextColor AQUA; static final NamedTextColor RED; static final NamedTextColor LIGHT_PURPLE; static final NamedTextColor YELLOW; static final NamedTextColor WHITE; static final Index<String, NamedTextColor> NAMES; }