📄 enumcodegenerator.java
字号:
package com.cownew.enumgenerator.wizards;
import java.util.*;
public class EnumCodeGenerator
{
protected static String nl;
public static synchronized EnumCodeGenerator create(String lineSeparator)
{
nl = lineSeparator;
EnumCodeGenerator result = new EnumCodeGenerator();
nl = null;
return result;
}
protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
protected final String TEXT_1 = NL + "package ";
protected final String TEXT_2 = ";" + NL + "" + NL + "public class ";
protected final String TEXT_3 = NL + "{" + NL + "\tprivate String type;" + NL + "\t";
protected final String TEXT_4 = NL + "\tpublic \t";
protected final String TEXT_5 = " ";
protected final String TEXT_6 = " = new ";
protected final String TEXT_7 = "(\"";
protected final String TEXT_8 = "\");" + NL + "\t";
protected final String TEXT_9 = NL + "\t" + NL + "\tprivate ";
protected final String TEXT_10 = "(String type)" + NL + "\t{" + NL + "\t\tsuper();" + NL + "\t\tthis.type = type;" + NL + "\t}" + NL + "" + NL + "\tpublic int hashCode()" + NL + "\t{" + NL + "\t\tfinal int PRIME = 31;" + NL + "\t\tint result = 1;" + NL + "\t\tresult = PRIME * result + ((type == null) ? 0 : type.hashCode());" + NL + "\t\treturn result;" + NL + "\t}" + NL + "" + NL + "\tpublic boolean equals(Object obj)" + NL + "\t{" + NL + "\t\tif (this == obj)" + NL + "\t\t\treturn true;" + NL + "\t\tif (obj == null)" + NL + "\t\t\treturn false;" + NL + "\t\tif (getClass() != obj.getClass())" + NL + "\t\t\treturn false;" + NL + "\t\tfinal ";
protected final String TEXT_11 = " other = (";
protected final String TEXT_12 = ") obj;" + NL + "\t\tif (type == null)" + NL + "\t\t{" + NL + "\t\t\tif (other.type != null)" + NL + "\t\t\t\treturn false;" + NL + "\t\t} else if (!type.equals(other.type))" + NL + "\t\t\treturn false;" + NL + "\t\treturn true;" + NL + "\t}" + NL + "" + NL + "" + NL + "}";
public String generate(Object argument)
{
final StringBuffer stringBuffer = new StringBuffer();
EnumGenArgInfo argInfo = (EnumGenArgInfo)argument;
Set<String> enumItems = argInfo.getItems();
String className = argInfo.getClassName();
String packageName = argInfo.getPackageName();
stringBuffer.append(TEXT_1);
stringBuffer.append(packageName);
stringBuffer.append(TEXT_2);
stringBuffer.append(className);
stringBuffer.append(TEXT_3);
for(String item:enumItems){
stringBuffer.append(TEXT_4);
stringBuffer.append(className);
stringBuffer.append(TEXT_5);
stringBuffer.append(item);
stringBuffer.append(TEXT_6);
stringBuffer.append(className);
stringBuffer.append(TEXT_7);
stringBuffer.append(item);
stringBuffer.append(TEXT_8);
}
stringBuffer.append(TEXT_9);
stringBuffer.append(className);
stringBuffer.append(TEXT_10);
stringBuffer.append(className);
stringBuffer.append(TEXT_11);
stringBuffer.append(className);
stringBuffer.append(TEXT_12);
return stringBuffer.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -