Author: peterreilly
Date: Wed Aug 22 10:09:55 2007
New Revision: 568704
URL: http://svn.apache.org/viewvc?rev=568704&view=rev
Log:
remove some magic numbers
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java
ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java
ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java?rev=568704&r1=568703&r2=568704&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SizeSelector.java Wed Aug
22 10:09:55 2007
@@ -31,6 +31,24 @@
*/
public class SizeSelector extends BaseExtendSelector {
+ /** Constants for kilo, kibi etc */
+ private static final int KILO = 1000;
+ private static final int KIBI = 1024;
+ private static final int KIBI_POS = 4;
+ private static final int MEGA = 1000000;
+ private static final int MEGA_POS = 9;
+ private static final int MEBI = 1048576;
+ private static final int MEBI_POS = 13;
+ private static final long GIGA = 1000000000L;
+ private static final int GIGA_POS = 18;
+ private static final long GIBI = 1073741824L;
+ private static final int GIBI_POS = 22;
+ private static final long TERA = 1000000000000L;
+ private static final int TERA_POS = 27;
+ private static final long TEBI = 1099511627776L;
+ private static final int TEBI_POS = 31;
+ private static final int END_POS = 36;
+
/** Used for parameterized custom selector */
public static final String SIZE_KEY = "value";
/** Used for parameterized custom selector */
@@ -107,22 +125,22 @@
public void setUnits(ByteUnits units) {
int i = units.getIndex();
multiplier = 0;
- if (i > -1 && i < 4) {
- multiplier = 1000;
- } else if (i > 3 && i < 9) {
- multiplier = 1024;
- } else if (i > 8 && i < 13) {
- multiplier = 1000000;
- } else if (i > 12 && i < 18) {
- multiplier = 1048576;
- } else if (i > 17 && i < 22) {
- multiplier = 1000000000L;
- } else if (i > 21 && i < 27) {
- multiplier = 1073741824L;
- } else if (i > 26 && i < 31) {
- multiplier = 1000000000000L;
- } else if (i > 30 && i < 36) {
- multiplier = 1099511627776L;
+ if (i > -1 && i < KIBI_POS) {
+ multiplier = KILO;
+ } else if (i < MEGA_POS) {
+ multiplier = KIBI;
+ } else if (i < MEBI_POS) {
+ multiplier = MEGA;
+ } else if (i < GIGA_POS) {
+ multiplier = MEBI;
+ } else if (i < GIBI_POS) {
+ multiplier = GIGA;
+ } else if (i < TERA_POS) {
+ multiplier = GIBI;
+ } else if (i < TEBI_POS) {
+ multiplier = TERA;
+ } else if (i < END_POS) {
+ multiplier = TEBI;
}
if (multiplier > 0 && size > -1) {
sizelimit = size * multiplier;
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java?rev=568704&r1=568703&r2=568704&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java Wed Aug 22
10:09:55 2007
@@ -71,7 +71,9 @@
testAvailability("java.util.regex.Matcher");
return createRegexpInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp");
} catch (BuildException be) {
- cause = orCause(cause, be, JavaEnvUtils.getJavaVersionNumber() < 14);
+ cause = orCause(
+ cause, be,
+ JavaEnvUtils.getJavaVersionNumber() < JavaEnvUtils.VERSION_1_4);
}
try {
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java?rev=568704&r1=568703&r2=568704&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java Wed
Aug 22 10:09:55 2007
@@ -74,7 +74,9 @@
testAvailability("java.util.regex.Matcher");
return createInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher");
} catch (BuildException be) {
- cause = orCause(cause, be, JavaEnvUtils.getJavaVersionNumber() < 14);
+ cause = orCause(
+ cause, be,
+ JavaEnvUtils.getJavaVersionNumber() < JavaEnvUtils.VERSION_1_4);
}
try {
Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java?rev=568704&r1=568703&r2=568704&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java Wed Aug 22 10:09:55
2007
@@ -54,6 +54,10 @@
*/
public class ZipOutputStream extends FilterOutputStream {
+ private static final int BYTE_MASK = 0xFF;
+ private static final int SHORT = 2;
+ private static final int WORD = 4;
+
/**
* Compression method for deflated entries.
*
@@ -500,7 +504,7 @@
*/
public void write(int b) throws IOException {
byte[] buff = new byte[1];
- buff[0] = (byte) (b & 0xff);
+ buff[0] = (byte) (b & BYTE_MASK);
write(buff, 0, 1);
}
@@ -587,7 +591,7 @@
offsets.put(ze, ZipLong.getBytes(written));
writeOut(LFH_SIG);
- written += 4;
+ written += WORD;
//store method in local variable to prevent multiple method calls
final int zipMethod = ze.getMethod();
@@ -605,15 +609,15 @@
writeOut(ZipShort.getBytes(10));
writeOut(ZERO);
}
- written += 4;
+ written += WORD;
// compression method
writeOut(ZipShort.getBytes(zipMethod));
- written += 2;
+ written += SHORT;
// last mod. time and date
writeOut(toDosTime(ze.getTime()));
- written += 4;
+ written += WORD;
// CRC
// compressed length
@@ -633,12 +637,12 @@
// file name length
byte[] name = getBytes(ze.getName());
writeOut(ZipShort.getBytes(name.length));
- written += 2;
+ written += SHORT;
// extra field length
byte[] extra = ze.getLocalFileDataExtra();
writeOut(ZipShort.getBytes(extra.length));
- written += 2;
+ written += SHORT;
// file name
writeOut(name);
@@ -678,11 +682,11 @@
*/
protected void writeCentralFileHeader(ZipEntry ze) throws IOException {
writeOut(CFH_SIG);
- written += 4;
+ written += WORD;
// version made by
writeOut(ZipShort.getBytes((ze.getPlatform() << 8) | 20));
- written += 2;
+ written += SHORT;
// version needed to extract
// general purpose bit flag
@@ -697,15 +701,15 @@
writeOut(ZipShort.getBytes(10));
writeOut(ZERO);
}
- written += 4;
+ written += WORD;
// compression method
writeOut(ZipShort.getBytes(ze.getMethod()));
- written += 2;
+ written += SHORT;
// last mod. time and date
writeOut(toDosTime(ze.getTime()));
- written += 4;
+ written += WORD;
// CRC
// compressed length
@@ -718,12 +722,12 @@
// file name length
byte[] name = getBytes(ze.getName());
writeOut(ZipShort.getBytes(name.length));
- written += 2;
+ written += SHORT;
// extra field length
byte[] extra = ze.getCentralDirectoryExtra();
writeOut(ZipShort.getBytes(extra.length));
- written += 2;
+ written += SHORT;
// file comment length
String comm = ze.getComment();
@@ -732,23 +736,23 @@
}
byte[] commentB = getBytes(comm);
writeOut(ZipShort.getBytes(commentB.length));
- written += 2;
+ written += SHORT;
// disk number start
writeOut(ZERO);
- written += 2;
+ written += SHORT;
// internal file attributes
writeOut(ZipShort.getBytes(ze.getInternalAttributes()));
- written += 2;
+ written += SHORT;
// external file attributes
writeOut(ZipLong.getBytes(ze.getExternalAttributes()));
- written += 4;
+ written += WORD;
// relative offset of LFH
writeOut((byte[]) offsets.get(ze));
- written += 4;
+ written += WORD;
// file name
writeOut(name);
@@ -818,6 +822,8 @@
*/
protected static byte[] toDosTime(long t) {
Date time = new Date(t);
+ // CheckStyle:MagicNumberCheck OFF - I do not think that using constants
+ // here will improve the readablity
int year = time.getYear() + 1900;
if (year < 1980) {
return DOS_TIME_MIN;
@@ -830,6 +836,7 @@
| (time.getMinutes() << 5)
| (time.getSeconds() >> 1);
return ZipLong.getBytes(value);
+ // CheckStyle:MagicNumberCheck ON
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
|