- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
public static int activeThreadsCount(List<Thread> threadList)
{
int i = 0;
for (Thread thread : threadList)
{
i += thread.isAlive() ? 1 : 0;
}
return i;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+71
public static int activeThreadsCount(List<Thread> threadList)
{
int i = 0;
for (Thread thread : threadList)
{
i += thread.isAlive() ? 1 : 0;
}
return i;
}
+71
public static void main(String[] args) {
Map<String, ClassLink<?>> children = new HashMap<String, ClassLink<?>>();
children.put("test1", new ClassLink<Dall>());
children.put("test2", new ClassLink<Son>());
String test = children.get("test1").classObjectGenerator().getName();
test.toString();
}
static class ClassLink<X extends ChildBase> {
public X classObjectGenerator() {
return (X) new Dall();
};
}
static class Dall implements ChildBase {
public String getName() {
return "Ivan";
}
}
static class Son implements ChildBase {
public String getName() {
return "Vera";
}
}
interface ChildBase {
String getName();
}
Фабрика. Загнать в map легковесный класс - создатель, а когда понадобится - создать объект.
+72
private String shutdown = "SHUTDOWN";
........
// Read a set of characters from the socket
int expected = 1024; // Cut off to avoid DoS attack
<--Зачем это тут?-->
while (expected < shutdown.length()) {
if (random == null)
random = new Random();
expected += (random.nextInt() % 1024);
}
while (expected > 0) {
int ch = -1;
try {
ch = stream.read();
} catch (IOException e) {
log.warn("StandardServer.await: read: ", e);
ch = -1;
}
if (ch < 32) // Control character or EOF terminates loop
break;
command.append((char) ch);
expected--;
}
Не понимаю зачем тут while. Авторы Apache Tomcat расскажите...
+74
if (convertView == null || convertView != null) {
if (Position2.get(position)) {
t.setVisibility(0);
b.setVisibility(4);
mlp.setMargins(15, 0, 60, 0);
y.setBackgroundColor(getResources().getColor(R.color.app_text_white));
} else {
mlp.setMargins(60, 0, 15, 0);
t.setVisibility(4);
b.setVisibility(0);
y.setBackgroundColor(getResources().getColor(R.color.app_text_white));
}
} else {
view = convertView;
}
Индусы
+73
public MyVirtualMachine(URL uri, String name, String username,
String password) throws RemoteException, MalformedURLException {
...
if (!name.equalsIgnoreCase(name)) {
continue;
}
}
Использование одного и того же поля name при сравнении.
http://wernerstrydom.com/2013/04/14/a-helper-class-to-manage-a-virtual-machine-in-vmware-vsphere-hypervisor-5-1/
+83
private static boolean[][] set = {
{T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, G, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x, x, T, x, x, x, x, x, x, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x, x, T, x, T, x, x, x, x, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, T, T, T, T, T, T, T, T, x, x, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, T, T, T, T, T, T, T, T, x, x, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x},
{T, x, x, x, x, x, T, T, T, T, T, x, T, x, T, T, x, T, T, T, T, x, x, T, T, T, T, T, T, T, T, x, x, x, T, T, x, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, T, x, T, T, T, T, T, x, x, x, T, T, T, T, T, x, x, T, T, x, x, x, x, x, x, x, x, x, x, T, x, x, x, T, x, x, x, x, x, x, x, T, x, x, T, x, T, x, x, T, T, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{T, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, x, T, T, T, T, T, T, T, T, T, T, T, T, T, x, x, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, T, x, x, x, x, x, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x},
{x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, T, x, x, T, x, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, T, x, T, x, x, x, x, x, x}
};
Источник: http://sourceforge.net/p/squirrel-sql/code/HEAD/tree/tags/squirrelsql-3.4.0/app/src/main/java/net/sourceforge/squirrel_sql/client/session/parser/kernel/Parser.javа
+74
public static void main(String[] args) throws Exception {
...
try {
Signature.getInstance("NONEwithRSA", "SUN");
throw new Exception("call succeeded");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
System.out.println("OK");
}
http://jdk.openjdk-rt.googlecode.com/hg/test/java/security/Signature/NONEwithRSA.java
+76
package ololo.cdn.util;
/**
*
*/
public interface AnswerCodes
{
public static final int CODE_OK = 0;
public static final int CODE_NO_AUTH = 1;
public static final int CODE_NO_ACTION_DONE = 2;
public static final int CODE_ERROR_PARAMETERS = 4;
public static final int CODE_NO_RIGHTS = 8;
public static final int CODE_NOT_UNIQ_PARENT = 16;
public static final int CODE_NOT_EXIST_COLUMNS = 32;
public static final String ANSWER_NO_AUTH = "{\"result\":\"error\",\"code\":\"" + CODE_NO_AUTH + "\"}";
public static final String ANSWER_NO_RIGHTS = "{\"result\":\"error\",\"code\":\"" + CODE_NO_RIGHTS + "\"}";
public static final String ANSWER_NOT_UNIQ_PARENT = "{\"result\":\"error\",\"code\":\"" + CODE_NOT_UNIQ_PARENT + "\"}";
public static final String ANSWER_NOT_EXIST_COLUMNS = "{\"result\":\"error\",\"code\":\"" + CODE_NOT_EXIST_COLUMNS + "\"}";
public static final String ANSWER_OK = "{\"result\":\"ok\",\"code\":\"" + CODE_OK + "\"}";
public static final String ANSWER_NOTHING_DONE = "{\"result\":\"ok\",\"code\":\"" + CODE_NO_ACTION_DONE + "\"}";
}
+86
public interface ArchitectureUnit<T> {
public T release(Object... params);
}
максимальная гибкость
+73
@GET
@Path("/store")
void getStoreSummary(@QueryParam("id") final String id, final MethodCallback<StoreSummary> callback);
@GET
@Path("/store")
void getStoreDetails(@QueryParam("id") final String id, @QueryParam("detailed") final boolean mustBeTrue, final MethodCallback<StoreInfo> callback);
Есть API-вызов HTTP GET, который по ?detailed=true возвращает расширенный JSON с дополнительными полями.
И вот в RestyGWT, оказывается, по-другому никак. То есть если бы других параметров запроса не было, можно было бы просто написать
@Path("/store?detailed=true")
. Но он не умеет добавлять динамические параметры запроса к захардкоженным. Если попытаться - получается два вопросительных знака: [/code]/store?detailed=true?id=[id][/code].