- 1
FORMAT.format(Calendar.getInstance().getTime())
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+70
FORMAT.format(Calendar.getInstance().getTime())
Ну в календаре-то явно точнее время.
+70
public boolean getSuccessSubmitted() {
for (ReportDto report : getReports()) {
if (!(report.getOrder().getReceiptDate() != null && report.getReportReceived())) {
return false;
}
}
return !(getReports().isEmpty());
}
public boolean getUnSuccessSubmitted(){
for (ReportDto report : getReports()) {
if (!(report.getOrder().getOrderDate() != null && !(report.getReportReceived()))) {
return false;
}
}
return !(getReports().isEmpty());
}
для классического трио нехватает лишь getFailSubmitted()
+70
public static void getUsers(User[] users)
{
boolean b,bb;
for(int x=0;x<users.length;x++)
{
b=users[x].getNick().equals("------");
bb=users[x].getPassword().equals("------");
if (b==false && bb==false) {System.out.println("ник : "+users[x].getNick()+", пароль: "+users[x].getPassword()+", id: "+users[x].id+", " +"репутация: "+users[x].reputation);}
else {System.out.println(" НЕТ ДАННЫХ. ");}
}
}
http://programmersforum.ru/showthread.php?t=185055
Как по мне так забавно
+70
public class Brakets {
public static void main(String args[]) {
String sample;
if (args.length > 0 && args[0] != "")
sample = args[0];
else
sample = "asdf(sd{sd}sdfgs[sdfg{}]_)){}sdfg[sdfg{sdfg}]";
// init handler and add patterns
BracketHandler b = new BracketHandler();
b.add("[", "]");
b.add("{", "}");
b.add("[", "]");
b.add("(", ")");
// init input stack
CommonStack<BracketTemplate> result = new CommonStack<BracketTemplate>();
for (int i = 0; i < sample.length(); i++) {
// Assert that pattern is one characted length
String subString = sample.substring(i, i + 1);
BracketTemplate tmp = b.getTemplate(subString);
if (tmp != null) {
if (tmp.isStartPattern(subString)) {
result.push(tmp);
} else {
BracketTemplate t = result.pop();
if (t == null || !t.isEndPAttern(subString)) {
System.out.print("Check failed");
return;
}
}
}
}
System.out.print("Check passed");
}
}
Ещё одна реализация Brackets, теперь и на Java (от автора предыдущего класса стека)
+70
@Override protected void finalize()
{
Runtime.addShutdownHook();
}
Здесь без комментариев...
+70
for (AllResponseCache actionResponse : allResponses) {
if (null != actionResponse.getResponseStatus() && actionResponse.getResponseStatus().length() > 0) {
for (ResponseSubjectCache subj : actionResponse.getSubjects()) {
// find needed element
if (subj.getClaims() != null) {
for (ClaimCache claimCache : subj.getClaims()) {
Seller seller = getSellerByPersonMatched(pool, claimCache);
if (seller != null) {
if (mapToSyncronize.get(seller) == null) {
mapToSyncronize.put((SellerrEntity) seller, new LinkedList<ReportResponseCache>());
}
mapToSyncronize.get(seller).add(actionResponse);
}
}
}
}
}
}
Индусы и "for-if"-ы.
Я уж думал будет хронология как в России с "президентами" - "лысый, волосатый, лысый, волосатый" и так далее.
А тут "for, if, for, if" но в конце всё-таки 2 иф-а!
+70
//обработка поведения кнопки копировать
if(tni.isTreeStruct()) {
copyDocuments.setEnabled(false);
}
else {
copyDocuments.setEnabled(true);
if(jTree.getSelectionCount() > 1) {
copyDocuments.setEnabled(false);
}
else {
copyDocuments.setEnabled(true);
}
}
//-----------------------------------------------------------
//обработка поведения кнопки копировать c файлами
if(tni.isTreeStruct()) {
copyDocsWithFile.setEnabled(false);
}
else {
copyDocsWithFile.setEnabled(true);
if(jTree.getSelectionCount() > 1) {
copyDocsWithFile.setEnabled(false);
}
else {
copyDocsWithFile.setEnabled(true);
}
}
//-----------------------------------------------------------
Это - "Гребаный копипаст"
+70
import java.util.Random;
public class A {
public static void main(String args[]) {
int minimalSuccessTime = Integer.MAX_VALUE;
int maximalSuccessTime = Integer.MIN_VALUE;
for(int i = 0; i < 10000; i++) {
Random rnd = new Random();
boolean state = rnd.nextBoolean();
final byte prisonersCount = 100;
boolean prisoners[] = new boolean[prisonersCount];
byte prisonersCounted = 1;
int daysPassed = 0;
while(true) {
daysPassed++;
int tmp = rnd.nextInt(prisonersCount);
if(tmp == 0) {
if(state) {
state = false;
prisonersCounted++;
if(prisonersCounted == prisonersCount) {
break;
}
}
} else {
if(!state && !prisoners[tmp]) {
state = true;
prisoners[tmp] = true;
}
}
}
if(daysPassed < minimalSuccessTime) {
minimalSuccessTime = daysPassed;
}
if(daysPassed > maximalSuccessTime) {
maximalSuccessTime = daysPassed;
}
}
System.out.println("Minimal success time ~= " + minimalSuccessTime/365 + " years!");
System.out.println("Maximal success time ~= " + maximalSuccessTime/365 + " years!");
}
}
One hundred prisoners have been newly ushered into prison. The warden tells
them that starting tomorrow, each of them will be placed in an isolated cell,
unable to communicate amongst each other. Each day, the warden will choose
one of the prisoners uniformly at random with replacement, and place him in
a central interrogation room containing only a light bulb with a toggle switch.
The prisoner will be able to observe the current state of the light bulb. If he
wishes, he can toggle the light bulb. He also has the option of announcing that
he believes all prisoners have visited the interrogation room at some point in
time. If this announcement is true, then all prisoners are set free, but if it is
false, all prisoners are executed.
The warden leaves, and the prisoners huddle together to discuss their fate.
Can they agree on a protocol that will guarantee their freedom?
+70
public static void m()
{
cO = cO + "3659";
RecordStore recordstore;
if((recordstore = RecordStore.openRecordStore("saves", true)) != null)
{
if(recordstore.getNumRecords() == 20)
recordstore.closeRecordStore();
for(; recordstore.getNumRecords() < 20; recordstore.addRecord(null, 0, 0));
byte abyte0[] = recordstore.getRecord(6);
recordstore.setRecord(20, abyte0, 0, abyte0 == null ? 0 : abyte0.length);
recordstore.closeRecordStore();
}
return;
JVM INSTR dup ;
Exception exception;
exception;
printStackTrace();
cQ.concat("fuck ur hax, nigers :) muahaha :D");
cQ + "x";
return;
}
Не поверите, но это было найдено в недрах java игрушки :)
+70
public class HttpServer {
public static void main(String[] args) throws Throwable {
ServerSocket ss = new ServerSocket(8080);
while (true) {
Socket s = ss.accept();
System.err.println("Client accepted");
new Thread(new SocketProcessor(s)).start();
}
}
private static class SocketProcessor implements Runnable {
private Socket s;
private InputStream is;
private OutputStream os;
private SocketProcessor(Socket s) throws Throwable {
this.s = s;
this.is = s.getInputStream();
this.os = s.getOutputStream();
}
public void run() {
try {
readInputHeaders();
writeResponse("<html><body><h1>Hello from Habrahabr</h1></body></html>");
} catch (Throwable t) {
/*do nothing*/
} finally {
try {
s.close();
} catch (Throwable t) {
/*do nothing*/
}
}
System.err.println("Client processing finished");
}
private void writeResponse(String s) throws Throwable {
String response = "HTTP/1.1 200 OK\r\n" +
"Server: YarServer/2009-09-09\r\n" +
"Content-Type: text/html\r\n" +
"Content-Length: " + s.length() + "\r\n" +
"Connection: close\r\n\r\n";
String result = response + s;
os.write(result.getBytes());
os.flush();
}
private void readInputHeaders() throws Throwable {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while(true) {
String s = br.readLine();
if(s == null || s.trim().length() == 0) {
break;
}
}
}
}
}
Это весь код вебсервера.
К слову сказать, это от сюда:
http://habrahabr.ru/blogs/java/69136/