~ubuntu-branches/ubuntu/maverick/ant/maverick

« back to all changes in this revision

Viewing changes to src/main/org/apache/tools/ant/types/selectors/SizeSelector.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-09-30 14:47:45 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080930144745-0x8uzivd9t15dua3
Tags: 1.7.1-0ubuntu1
* New upstream version (bug fix release).
  - mainly a bugfix release.
  - has extended support for Java6 features.
  - <script> now has support for JavaFX.
  - release notes: http://apache.linux-mirror.org/ant/README.html
* Remove debian/patches/05_ant-bug433444.patch. Obsoleted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 */
32
32
public class SizeSelector extends BaseExtendSelector {
33
33
 
 
34
    /** Constants for kilo, kibi etc */
 
35
    private static final int  KILO = 1000;
 
36
    private static final int  KIBI = 1024;
 
37
    private static final int  KIBI_POS = 4;
 
38
    private static final int  MEGA = 1000000;
 
39
    private static final int  MEGA_POS = 9;
 
40
    private static final int  MEBI = 1048576;
 
41
    private static final int  MEBI_POS = 13;
 
42
    private static final long GIGA = 1000000000L;
 
43
    private static final int  GIGA_POS = 18;
 
44
    private static final long GIBI = 1073741824L;
 
45
    private static final int  GIBI_POS = 22;
 
46
    private static final long TERA = 1000000000000L;
 
47
    private static final int  TERA_POS = 27;
 
48
    private static final long TEBI = 1099511627776L;
 
49
    private static final int  TEBI_POS = 31;
 
50
    private static final int  END_POS = 36;
 
51
 
34
52
    /** Used for parameterized custom selector */
35
53
    public static final String SIZE_KEY = "value";
36
54
    /** Used for parameterized custom selector */
107
125
    public void setUnits(ByteUnits units) {
108
126
        int i = units.getIndex();
109
127
        multiplier = 0;
110
 
        if (i > -1 && i < 4) {
111
 
            multiplier = 1000;
112
 
        } else if (i > 3 && i < 9) {
113
 
            multiplier = 1024;
114
 
        } else if (i > 8 && i < 13) {
115
 
            multiplier = 1000000;
116
 
        } else if (i > 12 && i < 18) {
117
 
            multiplier = 1048576;
118
 
        } else if (i > 17 && i < 22) {
119
 
            multiplier = 1000000000L;
120
 
        } else if (i > 21 && i < 27) {
121
 
            multiplier = 1073741824L;
122
 
        } else if (i > 26 && i < 31) {
123
 
            multiplier = 1000000000000L;
124
 
        } else if (i > 30 && i < 36) {
125
 
            multiplier = 1099511627776L;
 
128
        if (i > -1 && i < KIBI_POS) {
 
129
            multiplier = KILO;
 
130
        } else if (i < MEGA_POS) {
 
131
            multiplier = KIBI;
 
132
        } else if (i < MEBI_POS) {
 
133
            multiplier = MEGA;
 
134
        } else if (i < GIGA_POS) {
 
135
            multiplier = MEBI;
 
136
        } else if (i < GIBI_POS) {
 
137
            multiplier = GIGA;
 
138
        } else if (i < TERA_POS) {
 
139
            multiplier = GIBI;
 
140
        } else if (i < TEBI_POS) {
 
141
            multiplier = TERA;
 
142
        } else if (i < END_POS) {
 
143
            multiplier = TEBI;
126
144
        }
127
145
        if (multiplier > 0 && size > -1) {
128
146
            sizelimit = size * multiplier;
153
171
                String paramname = parameters[i].getName();
154
172
                if (SIZE_KEY.equalsIgnoreCase(paramname)) {
155
173
                    try {
156
 
                        setValue(new Long(parameters[i].getValue()
157
 
                        ).longValue());
 
174
                        setValue(Long.parseLong(parameters[i].getValue()));
158
175
                    } catch (NumberFormatException nfe) {
159
176
                        setError("Invalid size setting "
160
177
                                + parameters[i].getValue());