- 1
- 2
- 3
- 4
- 5
if (("/dir/" + TXT_FILE_NAME).equals(fileName))
processTxtFiles(TXT_FILE_NAME);
else if (fileName.endsWith(TXT_FILE_NAME))
processTxtFiles(TXT_FILE_NAME);
else if ...
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+319
if (("/dir/" + TXT_FILE_NAME).equals(fileName))
processTxtFiles(TXT_FILE_NAME);
else if (fileName.endsWith(TXT_FILE_NAME))
processTxtFiles(TXT_FILE_NAME);
else if ...
Зачем первые две строки?
+317
/**
* 连接指定的手环
*
* @param callback
*/
public void connect(BluetoothDevice device, final ActionCallback callback) {
this.io.connect(context, device, callback);
}
public void setDisconnectedListener(NotifyListener disconnectedListener) {
this.io.setDisconnectedListener(disconnectedListener);
}
/**
* 和手环配对, 实际用途未知, 不配对也可以做其他的操作
*
* @return data = null
*/
public void pair(final ActionCallback callback) {
ActionCallback ioCallback = new ActionCallback() {
@Override
public void onSuccess(Object data) {
BluetoothGattCharacteristic characteristic = (BluetoothGattCharacteristic) data;
Log.d(TAG, "pair result " + Arrays.toString(characteristic.getValue()));
if (characteristic.getValue().length == 1 && characteristic.getValue()[0] == 2) {
callback.onSuccess(null);
} else {
callback.onFail(-1, "respone values no succ!");
}
}
@Override
public void onFail(int errorCode, String msg) {
callback.onFail(errorCode, msg);
}
};
this.io.writeAndRead(Profile.UUID_CHAR_PAIR, Protocol.PAIR, ioCallback);
}
public BluetoothDevice getDevice() {
return this.io.getDevice();
}
/**
* 读取和连接设备的信号强度RSSI值
*
* @param callback
* @return data : int, rssi值
*/
public void readRssi(ActionCallback callback) {
this.io.readRssi(callback);
}
/**
* 读取手环电池信息
*
* @return {@link BatteryInfo}
*/
public void getBatteryInfo(final ActionCallback callback) {
ActionCallback ioCallback = new ActionCallback() {
@Override
public void onSuccess(Object data) {
BluetoothGattCharacteristic characteristic = (BluetoothGattCharacteristic) data;
Log.d(TAG, "getBatteryInfo result " + Arrays.toString(characteristic.getValue()));
if (characteristic.getValue().length == 10) {
BatteryInfo info = BatteryInfo.fromByteData(characteristic.getValue());
callback.onSuccess(info);
} else {
callback.onFail(-1, "result format wrong!");
}
}
@Override
public void onFail(int errorCode, String msg) {
callback.onFail(errorCode, msg);
}
};
this.io.readCharacteristic(Profile.UUID_CHAR_BATTERY, ioCallback);
}
/**
* 让手环震动
*/
public void startVibration(VibrationMode mode) {
byte[] protocal;
switch (mode) {
case VIBRATION_WITH_LED:
protocal = Protocol.VIBRATION_WITH_LED;
break;
case VIBRATION_10_TIMES_WITH_LED:
protocal = Protocol.VIBRATION_10_TIMES_WITH_LED;
break;
case VIBRATION_WITHOUT_LED:
protocal = Protocol.VIBRATION_WITHOUT_LED;
break;
default:
return;
}
@chineesedoc
+111
@AutoValidated
public void remove(
@NotNull PaymentProviderConfiguration paymentProviderConfiguration
) {
paymentProviderConfiguration.setDeleted(true);
paymentProviderConfiguration.setDisabled(true);
paymentProviderConfiguration.setEditable(false);
paymentProviderConfigurationDAO.update(paymentProviderConfiguration);
context.getHibernate().evict(paymentProviderConfiguration);
context.getHibernate().flush();
}
интересно еще и то, что внутри paymentProviderConfigurationDAO.update(p aymentProviderConfiguration); есть еще один flush
+4
public class LoadingActivity extends AppCompatActivity{
if (LoadActivity.this != null && delayFlag) {
//do something
}
}
+4
import java.util.Scanner;
import java.io.*;
public class Multiply {
public static int multiplyNumbers(int n, int m)
{
int i = 0, result = 0;
for(i = 0; i < m; i ++)
result += n;
return result;
}
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
int n,m,ans;
n = sc.nextInt();
m = sc.nextInt();
ans = multiplyNumbers(n,m);
System.out.println(ans);
}
}
+6
import java.io.*;
public class ascii {
private static String readString() {
//TODO not implemented yet
return null;
}
private static void writeString(String s) {
try
{ try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output.txt"), "ascii"))) { writer.write(s); }
}
catch (IOException ex) { }
}
public static void main(String[] args) {
String s;
//s = readString();
String xs = "";
try
{
java.util.Scanner sc = new java.util.Scanner(new File("input.txt"));
while (sc.hasNextLine()) xs += sc.nextLine() + "\n";
} catch (FileNotFoundException ex) { }
s = xs;
int c = 0; int x; x = s.length(); String result = "";
while (c < x) {
char ch = s.charAt(c);
if (ch == 'o') { result += "X";
} else if (ch == 'O') {
result += "X";
} else if (ch == '.')
result += "X";
else if (ch == '`') { result += "X";
} else if (ch == '\'') {
result += "X";
} else if (ch == ' ')
result += " ";
else if (ch == '\n') {
result += "\n";
} c++; }
writeString(result);
}}
+1
import java.lang.*;
public class Password {
static char[] ch = {'a', 'b'};
static byte length = 2;
static int m = ch.length;
static int n = length;
static int l = (int) (Math.pow(ch.length, length));
static String[] arr = new String[l];
public static void main(String[] args) {
for (int xyu = 0; xyu < l; xyu++) {
arr[xyu] = "";
}
String[] output = generator(ch, length);
for (String password : output) {
System.out.println(password);
}
}
public static String[] generator(char[] ch, byte length) {
for (int i = 0; i < l; i++) {
arr[i] = M(i);
}
return arr;
}
public static String M(int i) {
String a = Perevod(i, m);
for (int j = 0; j < n; j++) {
arr[i] += ch[Character.getNumericValue(a.charAt(j))];
}
return arr[i];
}
//FIXME
public static String Perevod(int i, int base) {
String r = "";
if (i == 0) {
for (int counter = 0; counter < n; counter++) {
r += "0";
}
}
boolean f = false;
while (i > 0) {
r = r + (i % base);
int q = i % base;
i = (i - q) / base;
if (q == 1) {
f = true;
}
}
if (i == 0 & f == true) {
for (int counter = 0; counter < n - 1; counter++) {
r += "0";
}
}
String res = "";
for (int k = 0; k < r.length(); k++) {
res += r.charAt(r.length() - 1 - k);
}
return res;
}
}
Должен генерировать всевозможные пароли заданной длины из заданного алфавита. Не работает перевод в другую систему счисления
+2
public CustomCollection<T> wherePropertyIs(String propertyName, Object value) {
CustomCollection<T> lstTemp = new CustomCollection <T>();
if (this.size() > 0) {
Field foundField = null;
for (Field f : this.get(0).getClass().getDeclaredFields()){
if (f.getName().equals(propertyName)){
foundField = f;
break;
}
}
if (foundField != null) {
foundField.setAccessible(true);
try {
for(T obj : this){
if (foundField.get(obj).equals(value)){
lstTemp.add(obj);
}
}
}catch (IllegalAccessException e){
System.out.println(e.getMessage());
}
}
}
return lstTemp;
}
братишка, я тебе Linq на джаве принёс
+1
public Object [][] getResults (String query){
Object oArray [][] = {};
try (Connection con = Connector.getNewConnection()) {
Statement st = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
try (ResultSet rs = st.executeQuery(query)){
int rows = 0;
int cells = 0;
List<Object> lstObjX = new ArrayList<Object> (64);
while (rs.next()){
rows ++;
int x = 1;
while (true){
try {
lstObjX.add(rs.getObject(x));
x++;
}catch (Exception e) {
cells = (x != 1) ? x-1 : 0;
break;
}
}
for (; x-1 < cells; x++){
lstObjX.add(rs.getObject(x));
}
}
oArray = new Object [rows][cells];
int z = 0;
for (int y = 0; y < rows; y++){
for (int x = 0; x < cells; x++){
oArray[y][x] = lstObjX.get(z);
z++;
}
}
}
}
catch (SQLException e) {
System.err.println(e.getMessage());
}
return oArray;
}
Превращаем Resultset в 2-мерную таблицу [y][x], где [y] - индекс строки, а [x] - индекс значений полей
+3
@PostLoad
protected void initStatus() {
anState status = null;
if (isDeleted()) {
status = anState.S_DELETED;
} else if (actState != null) {
if (actState.equals(anState.S_NOT_FILLED)) {
status = anState.S_NOT_FILLED;
} else if (actState.equals(anState.S_FORMED)) {
status = anState.S_FORMED;
} else if (actState.equals(anState.S_SENT) &&
(Document != null && Document.getState().equals(DocumentState.SENT))) {
status = anState.S_SENT;
} else if (actState.equals(anState.S_SENT) &&
(Document == null ||
(Document != null && !Document.getState().equals(DocumentState.SENT)))) {
status = anState.S_SENDING;
} else if (actState.equals(anState.S_CANCELLATION_REQUEST)) {
status = anState.S_CANCELLATION_REQUEST;
} else if (actState.equals(anState.S_CANCELED)) {
status = anState.S_CANCELED;
}
}
this.status = status;
}
> кстати, валится же в методе
private boolean isReadonly(anState status) {
return !status.equals(anState.ACT_FORMED) &&
!status.equals(anState.ACT_NOT_FILLED);
}
> но мы же не знаем, что енумы можно сравнивать и по == (т.к. поля енума - константы), и привычки сравнивать equals на константном выражении тем более не имеем :)
> facepalm.jpg, словом :)