optimize array and negated codestyle
This commit is contained in:
parent
cca2ca9752
commit
8d74ac90aa
@ -105,7 +105,7 @@ public class Chooser<K, T> {
|
|||||||
|
|
||||||
double weight = item.weight();
|
double weight = item.weight();
|
||||||
//ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest
|
//ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest
|
||||||
if (!(weight > 0)) {
|
if (weight <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ public class Chooser<K, T> {
|
|||||||
for (Pair<T> item : itemsWithWeight) {
|
for (Pair<T> item : itemsWithWeight) {
|
||||||
double singleWeight = item.weight();
|
double singleWeight = item.weight();
|
||||||
//ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest
|
//ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest
|
||||||
if (!(singleWeight > 0)) {
|
if (singleWeight <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
exactWeights[index++] = singleWeight / originWeightSum;
|
exactWeights[index++] = singleWeight / originWeightSum;
|
||||||
@ -138,7 +138,7 @@ public class Chooser<K, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double doublePrecisionDelta = 0.0001;
|
double doublePrecisionDelta = 0.0001;
|
||||||
if (index != 0 && !(Math.abs(weights[index - 1] - 1) < doublePrecisionDelta)) {
|
if (index != 0 && (Math.abs(weights[index - 1] - 1) >= doublePrecisionDelta)) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Cumulative Weight caculate wrong , the sum of probabilities does not equals 1.");
|
"Cumulative Weight caculate wrong , the sum of probabilities does not equals 1.");
|
||||||
}
|
}
|
||||||
|
@ -27,12 +27,12 @@ public class Md5Utils {
|
|||||||
private static final int HEX_VALUE_COUNT = 16;
|
private static final int HEX_VALUE_COUNT = 16;
|
||||||
|
|
||||||
public static String getMD5(byte[] bytes) {
|
public static String getMD5(byte[] bytes) {
|
||||||
char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
char str[] = new char[16 * 2];
|
char[] str = new char[16 * 2];
|
||||||
try {
|
try {
|
||||||
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
|
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
|
||||||
md.update(bytes);
|
md.update(bytes);
|
||||||
byte tmp[] = md.digest();
|
byte[] tmp = md.digest();
|
||||||
int k = 0;
|
int k = 0;
|
||||||
for (int i = 0; i < HEX_VALUE_COUNT; i++) {
|
for (int i = 0; i < HEX_VALUE_COUNT; i++) {
|
||||||
byte byte0 = tmp[i];
|
byte byte0 = tmp[i];
|
||||||
|
@ -46,12 +46,12 @@ public class PaginationHelper<E> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Page<E> fetchPage(final JdbcTemplate jt, final String sqlCountRows, final String sqlFetchRows,
|
public Page<E> fetchPage(final JdbcTemplate jt, final String sqlCountRows, final String sqlFetchRows,
|
||||||
final Object args[], final int pageNo, final int pageSize, final RowMapper<E> rowMapper) {
|
final Object[] args, final int pageNo, final int pageSize, final RowMapper<E> rowMapper) {
|
||||||
return fetchPage(jt, sqlCountRows, sqlFetchRows, args, pageNo, pageSize, null, rowMapper);
|
return fetchPage(jt, sqlCountRows, sqlFetchRows, args, pageNo, pageSize, null, rowMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<E> fetchPage(final JdbcTemplate jt, final String sqlCountRows, final String sqlFetchRows,
|
public Page<E> fetchPage(final JdbcTemplate jt, final String sqlCountRows, final String sqlFetchRows,
|
||||||
final Object args[], final int pageNo, final int pageSize, final Long lastMaxId,
|
final Object[] args, final int pageNo, final int pageSize, final Long lastMaxId,
|
||||||
final RowMapper<E> rowMapper) {
|
final RowMapper<E> rowMapper) {
|
||||||
if (pageNo <= 0 || pageSize <= 0) {
|
if (pageNo <= 0 || pageSize <= 0) {
|
||||||
throw new IllegalArgumentException("pageNo and pageSize must be greater than zero");
|
throw new IllegalArgumentException("pageNo and pageSize must be greater than zero");
|
||||||
@ -98,7 +98,7 @@ public class PaginationHelper<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Page<E> fetchPageLimit(final JdbcTemplate jt, final String sqlCountRows, final String sqlFetchRows,
|
public Page<E> fetchPageLimit(final JdbcTemplate jt, final String sqlCountRows, final String sqlFetchRows,
|
||||||
final Object args[], final int pageNo, final int pageSize,
|
final Object[] args, final int pageNo, final int pageSize,
|
||||||
final RowMapper<E> rowMapper) {
|
final RowMapper<E> rowMapper) {
|
||||||
if (pageNo <= 0 || pageSize <= 0) {
|
if (pageNo <= 0 || pageSize <= 0) {
|
||||||
throw new IllegalArgumentException("pageNo and pageSize must be greater than zero");
|
throw new IllegalArgumentException("pageNo and pageSize must be greater than zero");
|
||||||
@ -138,9 +138,9 @@ public class PaginationHelper<E> {
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<E> fetchPageLimit(final JdbcTemplate jt, final String sqlCountRows, final Object args1[],
|
public Page<E> fetchPageLimit(final JdbcTemplate jt, final String sqlCountRows, final Object[] args1,
|
||||||
final String sqlFetchRows,
|
final String sqlFetchRows,
|
||||||
final Object args2[], final int pageNo, final int pageSize,
|
final Object[] args2, final int pageNo, final int pageSize,
|
||||||
final RowMapper<E> rowMapper) {
|
final RowMapper<E> rowMapper) {
|
||||||
if (pageNo <= 0 || pageSize <= 0) {
|
if (pageNo <= 0 || pageSize <= 0) {
|
||||||
throw new IllegalArgumentException("pageNo and pageSize must be greater than zero");
|
throw new IllegalArgumentException("pageNo and pageSize must be greater than zero");
|
||||||
@ -181,7 +181,7 @@ public class PaginationHelper<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Page<E> fetchPageLimit(final JdbcTemplate jt, final String sqlFetchRows,
|
public Page<E> fetchPageLimit(final JdbcTemplate jt, final String sqlFetchRows,
|
||||||
final Object args[], final int pageNo, final int pageSize,
|
final Object[] args, final int pageNo, final int pageSize,
|
||||||
final RowMapper<E> rowMapper) {
|
final RowMapper<E> rowMapper) {
|
||||||
if (pageNo <= 0 || pageSize <= 0) {
|
if (pageNo <= 0 || pageSize <= 0) {
|
||||||
throw new IllegalArgumentException("pageNo and pageSize must be greater than zero");
|
throw new IllegalArgumentException("pageNo and pageSize must be greater than zero");
|
||||||
@ -201,7 +201,7 @@ public class PaginationHelper<E> {
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLimit(final JdbcTemplate jt, final String sql, final Object args[]) {
|
public void updateLimit(final JdbcTemplate jt, final String sql, final Object[] args) {
|
||||||
String sqlUpdate = sql;
|
String sqlUpdate = sql;
|
||||||
|
|
||||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user