- 1
- 2
- 3
- 4
List<SomeType> list = ...;
...
if (list.size() < 0)
return true;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+79
List<SomeType> list = ...;
...
if (list.size() < 0)
return true;
а вдруг?
+68
public String getCurrentUrl() {
if (webview == null) {
throw new SelendroidException("No open web view.");
}
long end = System.currentTimeMillis() + UI_TIMEOUT;
final String[] url = new String[1];
done = false;
Runnable r = new Runnable() {
public void run() {
url[0] = webview.getUrl();
synchronized (this) {
this.notify();
}
}
};
runSynchronously(r, UI_TIMEOUT);
return url[0];
}
final String[] url = new String[1];
url[0] = webview.getUrl();
return url[0];
Вы чо? Серьёзно?
+73
int a = 1;
int b = 2;
int c = 2;
String d = " ";
System.out.print(a+d);
System.out.print(b+d);
System.out.print(b+a+d);
System.out.print(4+d);
System.out.print(5+d);
System.out.print(6+d);
System.out.print(7+d);
System.out.print(8+d);
System.out.print(9+d);
System.out.println(10+d);
System.out.print(2+d);
System.out.print(4+d);
System.out.print(6+d);
System.out.print(8+d);
System.out.print(10+d);
System.out.print(12+d);
System.out.print(14+d);
System.out.print(16+d);
System.out.print(18+d);
System.out.println(20+d);
System.out.print(3+d);
System.out.print(6+d);
System.out.print(9+d);
System.out.print(12+d);
System.out.print(15+d);
System.out.print(18+d);
System.out.print(21+d);
System.out.print(24+d);
System.out.print(27+d);
System.out.println(30+d);
System.out.print(4+d);
System.out.print(8+d);
System.out.print(12+d);
System.out.print(16+d);
System.out.print(20+d);
System.out.print(24+d);
System.out.print(28+d);
System.out.print(32+d);
System.out.print(36+d);
System.out.println(40+d);
System.out.print(5+d);
System.out.print(10+d);
System.out.print(15+d);
System.out.print(20+d);
System.out.print(25);
System.out.print(30+d);
System.out.print(35+d);
System.out.print(40+d);
System.out.print(45+d);
System.out.println(50+d);
System.out.print(6+d);
System.out.print(12+d);
System.out.print(18+d);
System.out.print(24+d);
System.out.print(30+d);
System.out.print(36+d);
System.out.print(42+d);
System.out.print(48+d);
System.out.print(54+d);
System.out.println(60+d);
System.out.print(7+d);
System.out.print(14+d);
System.out.print(21+d);
System.out.print(28+d);
System.out.print(35+d);
System.out.print(42+d);
System.out.print(49+d);
System.out.print(56+d);
System.out.print(63+d);
System.out.println(70+d);
System.out.print(8+d);
System.out.print(16+d);
System.out.print(24+d);
System.out.print(32+d);
System.out.print(40+d);
System.out.print(48+d);
System.out.print(56+d);
System.out.print(64+d);
System.out.print(72+d);
System.out.println(80+d);
System.out.print(9+d);
System.out.print(18+d);
System.out.print(27+d);
System.out.print(36+d);
System.out.print(45+d);
System.out.print(54+d);
System.out.print(63+d);
System.out.print(72+d);
System.out.print(81+d);
System.out.println(90+d);
System.out.print(10+d);
System.out.print(20+d);
System.out.print(30+d);
System.out.print(40+d);
System.out.print(50+d);
System.out.print(60+d);
Пытался таблицу умножения сделать в детстве...
+72
public class PLock {
private Map<Thread, Integer> readLocks = new HashMap<Thread, Integer>();
private Thread writeLock = null;
private int writeLockCount = 0;
public synchronized void getReadLock() {
Thread currentThread = Thread.currentThread();
long startTimeMillis = System.currentTimeMillis();
boolean gotStuck = false;
while (canClaimReadLock(currentThread) == false) {
gotStuck = true;
try {
wait();
} catch (InterruptedException ex) {
Log.warn("Interrupted while attempting to get read lock.", ex);
}
}
report(gotStuck, startTimeMillis, "read");
if (readLocks.containsKey(currentThread)) {
readLocks.put(currentThread, 1 + readLocks.get(currentThread));
} else {
readLocks.put(currentThread, 1);
}
}
...
public synchronized void relinquishReadLock() {
Thread currentThread = Thread.currentThread();
if (readLocks.containsKey(currentThread) == false) {
throw new RuntimeException("Cannot relinquish read lock on thread " + currentThread + " because it does not hold a lock.");
}
int newLockCount = readLocks.get(currentThread) - 1;
if (newLockCount == 0) {
readLocks.remove(currentThread);
notifyAll(); // IMPORTANT: allow other threads to wake up and check if they can get locks now.
} else {
readLocks.put(currentThread, newLockCount);
}
}
public synchronized void getWriteLock() {
//Log.warn("getWriteLock() in thread " + Thread.currentThread());
//dumpLocks();
Thread currentThread = Thread.currentThread();
long startTimeMillis = System.currentTimeMillis();
boolean gotStuck = false;
while (canClaimWriteLock(currentThread) == false) {
gotStuck = true;
try {
wait();
} catch (InterruptedException ex) {
Log.warn("Interrupted while attempting to get write lock.", ex);
}
}
report(gotStuck, startTimeMillis, "write");
writeLock = currentThread;
writeLockCount++;
}
...
public synchronized void relinquishWriteLock() {
//Log.warn("relinquishWriteLock() in thread " + Thread.currentThread());
Thread currentThread = Thread.currentThread();
if (writeLock != currentThread) {
throw new RuntimeException("Cannot relinquish write lock on thread " + currentThread + " because it does not hold the lock.");
}
if (writeLockCount <= 0) {
throw new RuntimeException("Tried to relinquish write lock on thread " + currentThread + " while write lock count is " + writeLockCount);
}
writeLockCount--;
if (writeLockCount == 0) {
writeLock = null;
notifyAll(); // IMPORTANT: allow other threads to wake up and check if they can get locks now.
}
}
...
}
А у вас уже есть свой теплый ламповый ReentrantReadWriteLock?
Нет? Тогда https://github.com/orph/jujitsu/blob/master/src/e/ptextarea/PLock.java идет к вам...
+75
cooldownTime.add(14, (int)(cooldown * 1000.0D % 1000.0D));
...
+68
class CircuitBreaker
{
boolean broken = false;
CircuitBreaker() {}
private void breakCircuit()
{
this.broken = true;
}
private boolean isBroken()
{
return this.broken;
}
}
private boolean writeAssetsToDisk()
{
CircuitBreaker breaker = new CircuitBreaker();
writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
return !breaker.isBroken();
}
private void writeBase64EncodedAssetToDisk(CircuitBreaker breaker, String base64String, String filename)
{
if (breaker.isBroken()) {
return;
}
...
try
{
...
}
catch (IOException e)
{
breaker.breakCircuit(); return;
}
...
}
Используй исключения, Люк. Фрагмент из Amazon Mobile Ads SDK.
+76
class Matrix {
ArrayList<ArrayList<Double>> arrayList = new ArrayList<ArrayList<Double>>();
...
}
Вот такая у нас реализация sparsed-матриц.
+78
public static String[] Filtr( String[] mas )
{
for(int i=0;i<mas.length;i++)
{
if ("А".equals(mas[i])){
mas[i] = "а";
}
if ("Б".equals(mas[i])){
mas[i] = "б";
}
if ("В".equals(mas[i])){
mas[i] = "в";
}
if ("Г".equals(mas[i])){
mas[i] = "г";
}
if ("Д".equals(mas[i])){
mas[i] = "д";
}
if ("Е".equals(mas[i])){
mas[i] = "е";
}
if ("Ё".equals(mas[i])){
.....//и т.д.
if ("Э".equals(mas[i])){
mas[i] = "э";
}
if ("Ю".equals(mas[i])){
mas[i] = "ю";
}
if ("Я".equals(mas[i])){
mas[i] = "я";
}
if ("Й".equals(mas[i])){
mas[i] = "й";
}
}
for(int i=0;i<mas.length;i++)
{
if(
(mas[i].equals("а") == false) &&
(mas[i].equals("б") == false) &&
(mas[i].equals("в") == false) &&
(mas[i].equals("г") == false) &&
(mas[i].equals("д") == false) &&
(mas[i].equals("е") == false) &&
(mas[i].equals("ё") == false) &&
(mas[i].equals("ж") == false) &&
(mas[i].equals("з") == false) &&
(mas[i].equals("и") == false) &&
(mas[i].equals("к") == false) &&
(mas[i].equals("л") == false) &&
(mas[i].equals("м") == false) &&
(mas[i].equals("н") == false) &&
(mas[i].equals("о") == false) &&
(mas[i].equals("п") == false) &&
(mas[i].equals("р") == false) &&
(mas[i].equals("с") == false) &&
(mas[i].equals("т") == false) &&
(mas[i].equals("у") == false) &&
(mas[i].equals("ф") == false) &&
(mas[i].equals("х") == false) &&
(mas[i].equals("ц") == false) &&
(mas[i].equals("ч") == false) &&
(mas[i].equals("ш") == false) &&
(mas[i].equals("щ") == false) &&
(mas[i].equals("э") == false) &&
(mas[i].equals("ю") == false) &&
(mas[i].equals("я") == false) &&
(mas[i].equals("ъ") == false) &&
(mas[i].equals("ь") == false) &&
(mas[i].equals("ы") == false) &&
(mas[i].equals("й") == false) &&
(mas[i].equals(" ") == false))
{
mas = Del(mas, i);
i--;
} ;
for(int k=0;(k+1)<mas.length;k++)
{
if(mas[k].equals(" ") && mas[k+1].equals(" "))
{
mas = Del(mas, k);
k--;
}
}
}
return mas;
}
+78
public static SomeHandler getInstance(int... initValue){
if (initValue == null || initValue.length == 0) {
initValue = new int[1];
initValue[0] = 1;
}
if (initValue != null && initValue.length != 1) {
throw new IllegalArgumentException("You should pass exactly one value");
}
if (instance == null){
instance = new SomeHandler();
}
return instance;
}
+69
package com.javarush.test.level06.lesson11.bonus02;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/* Нужно добавить в программу новую функциональность
Задача: У каждой кошки есть имя и кошка-мама. Создать класс, который бы описывал данную ситуацию. Создать два объекта: кошку-дочь и кошку-маму. Вывести их на экран.
Новая задача: У каждой кошки есть имя, кошка-папа и кошка-мама. Изменить класс Cat так, чтобы он мог описать данную ситуацию.
Создать 6 объектов: маму, папу, сына, дочь, бабушку(мамина мама) и дедушку(папин папа).
Вывести их всех на экран в порядке: дедушка, бабушка, папа, мама, сын, дочь.
Пример ввода:
дедушка Вася
бабушка Мурка
папа Котофей
мама Василиса
сын Мурчик
дочь Пушинка
Пример вывода:
Cat name is дедушка Вася, no mother, no father
Cat name is бабушка Мурка, no mother, no father
Cat name is папа Котофей, no mother, father is дедушка Вася
Cat name is мама Василиса, mother is бабушка Мурка, no father
Cat name is сын Мурчик, mother is мама Василиса, father is папа Котофей
Cat name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
*/
public class Solution
{
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grfatherName = reader.readLine();
Cat catGrfather = new Cat(grfatherName);
String grmotherName = reader.readLine();
Cat catGrmother = new Cat(grmotherName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName, catGrfather, null);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, null, catGrmother);
String sonName = reader.readLine();
Cat catSon = new Cat(sonName, catFather, catMother);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catFather, catMother);
System.out.println(catGrfather);
System.out.println(catGrmother);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catSon);
System.out.println(catDaughter);
}
public static class Cat
{
private String name;
private Cat father;
private Cat mother;
Cat(String name)
{
this.name = name;
}
Cat (String name, Cat father, Cat mother){
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString()
{
if ((mother == null) && (father == null))
return "Cat name is " + name + ", no mother, no father ";
else if (father == null)
return "Cat name is " + name + ", mother is " + mother.name + " , no father";
else if (mother == null)
return "Cat name is " + name + ", no mather " + ", father is " + father.name;
else
return "Cat name is " + name + ", mother is " + mother.name + ", father is " + father.name;
}
}
}
Да лаба, точнее задание. Но меня так умиляет решение задачи :) Просто немного хардкода :)