KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > resources > selectors > Size


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.types.resources.selectors;
19
20 import org.apache.tools.ant.types.Resource;
21 import org.apache.tools.ant.types.Comparison;
22
23 /**
24  * Size ResourceSelector.
25  * @since Ant 1.7
26  */

27 public class Size implements ResourceSelector {
28     private long size = -1;
29     private Comparison when = Comparison.EQUAL;
30
31     /**
32      * Set the size to compare against.
33      * @param l the long resource size.
34      */

35     public void setSize(long l) {
36         size = l;
37     }
38
39     /**
40      * Get the size compared to by this Size ResourceSelector.
41      * @return the long resource size.
42      */

43     public long getSize() {
44         return size;
45     }
46
47     /**
48      * Set the comparison mode.
49      * @param c a Comparison object.
50      */

51     public void setWhen(Comparison c) {
52         when = c;
53     }
54
55     /**
56      * Get the comparison mode.
57      * @return a Comparison object.
58      */

59     public Comparison getWhen() {
60         return when;
61     }
62
63     /**
64      * Return true if this Resource is selected.
65      * @param r the Resource to check.
66      * @return whether the Resource was selected.
67      */

68     public boolean isSelected(Resource r) {
69         long diff = r.getSize() - size;
70         return when.evaluate(diff == 0 ? 0 : (int) (diff / Math.abs(diff)));
71     }
72
73 }
74
Popular Tags