なんの変哲もない POJO アプリ
package com.snail.exam;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ColorSuggestionWebService {
private static final String[][] X11Colors = {
{ "000000", "black" },
{ "000080", "navy" },
{ "00008B", "darkblue" },
{ "0000CD", "mediumblue" },
{ "0000FF", "blue" },
{ "006400", "darkgreen" },
{ "008000", "green" },
{ "008080", "teal" },
{ "008B8B", "darkcyan" },
{ "00BFFF", "deepskyblue" },
{ "00CED1", "darkturquoise" },
{ "00FA9A", "mediumspringgreen" },
{ "00FF00", "lime" },
{ "00FF7F", "springgreen" },
{ "00FFFF", "aqua" },
{ "00FFFF", "cyan" },
{ "191970", "midnightblue" },
{ "1E90FF", "dodgerblue" },
{ "20B2AA", "lightseagreen" },
{ "228B22", "forestgreen" },
{ "2E8B57", "seagreen" },
{ "2F4F4F", "darkslategray" },
{ "32CD32", "limegreen" },
{ "3CB371", "mediumseagreen" },
{ "40E0D0", "turquoise" },
{ "4169E1", "royalblue" },
{ "4682B4", "steelblue" },
{ "483D8B", "darkslateblue" },
{ "48D1CC", "mediumturquoise" },
{ "4B0082", "indigo" },
{ "556B2F", "darkolivegreen" },
{ "5F9EA0", "cadetblue" },
{ "6495ED", "cornflowerblue" },
{ "655ACD", "slateblue" },
{ "66CDAA", "mediumaquamarine" },
{ "696969", "dimgray" },
{ "6B8E23", "olivedrab" },
{ "708090", "slategray" },
{ "778899", "lightslategray" },
{ "7B68EE", "mediumslateblue" },
{ "7CFC00", "lawngreen" },
{ "7FFF00", "chartreuse" },
{ "7FFFD4", "aquamarine" },
{ "800000", "maroon" },
{ "800080", "purple" },
{ "808000", "olive" },
{ "808080", "gray" },
{ "87CEEB", "skyblue" },
{ "87CEFA", "lightskyblue" },
{ "8A2BE2", "blueviolet" },
{ "8B0000", "darkred" },
{ "8B008B", "darkmagenta" },
{ "8B4513", "saddlebrown" },
{ "8FBC8F", "darkseagreen" },
{ "90EE90", "lightgreen" },
{ "9370DB", "mediumpurple" },
{ "9400D3", "darkviolet" },
{ "98FB98", "palegreen" },
{ "9932CC", "darkorchid" },
{ "9ACD32", "yellowgreen" },
{ "A0522D", "sienna" },
{ "A52A2A", "brown" },
{ "A9A9A9", "darkgray" },
{ "ADD8E6", "lightblue" },
{ "ADFF2F", "greenyellow" },
{ "AFEEEE", "paleturquoise" },
{ "B0C4DE", "lightsteelblue" },
{ "B0E0E6", "powderblue" },
{ "B22222", "firebrick" },
{ "B886CD", "darkgoldenrod" },
{ "BA55D3", "mediumorchid" },
{ "BC8F8F", "rosybrown" },
{ "BDB76B", "darkkhaki" },
{ "C0C0C0", "silver" },
{ "C71585", "mediumvioletred" },
{ "CD5C5C", "indianred" },
{ "CD853F", "peru" },
{ "D2691E", "chocolate" },
{ "D2B48C", "tan" },
{ "D3D3D3", "lightgrey" },
{ "D8BFD8", "thistle" },
{ "DA70D6", "orchid" },
{ "DAA520", "goldenrod" },
{ "DB7093", "palevioletred" },
{ "DC143C", "crimson" },
{ "DCDCDC", "gainsboro" },
{ "DDA0DD", "plum" },
{ "DEB887", "burlywood" },
{ "E0FFFF", "lightcyan" },
{ "E6E6FA", "lavender" },
{ "E9967A", "darksalmon" },
{ "EE82EE", "violet" },
{ "EEE8AA", "palegoldenrod" },
{ "F08080", "lightcoral" },
{ "F0E68C", "khaki" },
{ "F0F8FF", "aliceblue" },
{ "F0FFF0", "honeydew" },
{ "F0FFFF", "azure" },
{ "F4A460", "sandybrown" },
{ "F5DEB3", "wheat" },
{ "F5F5DC", "beige" },
{ "F5F5F5", "whitesmoke" },
{ "F5FFFA", "mintcream" },
{ "F8F8FF", "ghostwhite" },
{ "FA8072", "salmon" },
{ "FAEBD7", "antiquewhite" },
{ "FAF0E6", "linen" },
{ "FAFAD2", "lightgoldenrodyellow" },
{ "FDF5E6", "oldlace" },
{ "FF0000", "red" },
{ "FF00FF", "fuchsia" },
{ "FF00FF", "magenta" },
{ "FF1493", "deeppink" },
{ "FF4500", "orangered" },
{ "FF6347", "tomato" },
{ "FF69B4", "hotpink" },
{ "FF7F50", "coral" },
{ "FF8C00", "darkorange" },
{ "FFA07A", "lightsalmon" },
{ "FFA500", "orange" },
{ "FFB6C1", "lightpink" },
{ "FFC0CB", "pink" },
{ "FFD700", "gold" },
{ "FFDAB9", "peachpuff" },
{ "FFDEAD", "navajowhite" },
{ "FFE4B5", "moccasin" },
{ "FFE4C4", "bisque" },
{ "FFE4E1", "mistyrose" },
{ "FFEBCD", "blanchedalmond" },
{ "FFEFD5", "papayawhip" },
{ "FFF0F5", "lavenderblush" },
{ "FFF5EE", "seashell" },
{ "FFF8DC", "cornsilk" },
{ "FFFACD", "lemonchiffon" },
{ "FFFAF0", "floralwhite" },
{ "FFFAFA", "snow" },
{ "FFFF00", "yellow" },
{ "FFFFE0", "lightyellow" },
{ "FFFFF0", "ivory" },
{ "FFFFFF", "white" }
};
public ColorSuggestionWebService() {
super();
}
/**
* 引数で指定された色に似ている X11 Color を 10 個返します
* @param red RED
* @param green GREEN
* @param blue BLUE
* @return 引数で指定された色に似ている X11 Color の配列
*/
public ColorBean[] suggestColor(final int red, final int green, final int blue) throws Exception {
if (red < 0 || 255 < red || green < 0 || 255 < green || blue < 0 || 255 < blue) {
throw new Exception("Color value must be greater than -1 and less than 256.");
}
List<ColorBean> colorList = new ArrayList<ColorBean>();
for (String[] color : X11Colors) {
colorList.add(new ColorBean(color[0], color[1]));
}
Collections.sort(colorList,
new Comparator<ColorBean>() {
public int compare(ColorBean o1, ColorBean o2) {
return o1.distance(red, green, blue) -
o2.distance(red, green, blue);
}
});
return colorList.subList(0, 10).toArray(new ColorBean[0]);
}
}
package com.snail.exam;
public class ColorBean {
private int pRed;
private int pGreen;
private int pBlue;
private String pName;
public ColorBean(){
super();
}
public ColorBean(String rgbString,String name){
int rgb = Integer.parseInt(rgbString,16);
pRed = ( rgb & 0xff0000 ) >>> 16;
pGreen = ( rgb & 0xff00 ) >>> 8;
pBlue = rgb & 0xff;
pName = name;
}
public int getRed() {
return pRed;
}
public void setRed(int red) {
pRed = red;
}
public int getGreen() {
return pGreen;
}
public void setGreen(int green) {
pGreen = green;
}
public int getBlue() {
return pBlue;
}
public void setBlue(int blue) {
pBlue = blue;
}
public String getName() {
return pName;
}
public void setName(String name) {
pName = name;
}
public int distance(int red,int green,int blue){
return Math.abs(red-pRed)+Math.abs(green-pGreen)+Math.abs(blue-pBlue);
}
}
package com.snail.exam;
import java.rmi.RemoteException;
public class ExamClient {
/**
* @param args
*/
public static void main(String[] args) {
ColorSuggestionWebService client = new ColorSuggestionWebServiceProxy();
try {
ColorBean[] result = client.suggestColor(255, 0, 0);
for (ColorBean cb : result) {
System.out.println(cb.getName() + "(R:" + cb.getRed() + "G:"
+ cb.getGreen() + "B:" + cb.getBlue() + ")");
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
確かに、赤(FF0000)に近い色が 10 種類提示された