FileDocCategorySizeDatePackage
Majority.javaAPI DocApache Ant 1.702442Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types.resources.selectors

Majority

public class Majority extends ResourceSelectorContainer implements ResourceSelector
Majority ResourceSelector.
since
Ant 1.7

Fields Summary
private boolean
tie
Constructors Summary
public Majority()
Default constructor.


           
      
    
public Majority(ResourceSelector[] r)
Convenience constructor.

param
r the ResourceSelector[] to add.

        super(r);
    
Methods Summary
public synchronized booleanisSelected(org.apache.tools.ant.types.Resource r)
Return true if this Resource is selected.

param
r the Resource to check.
return
whether the Resource was selected.

        int passed = 0;
        int failed = 0;
        int count = selectorCount();
        boolean even = count % 2 == 0;
        int threshold = count / 2;

        for (Iterator i = getSelectors(); i.hasNext();) {
            if (((ResourceSelector) i.next()).isSelected(r)) {
                ++passed;
                if (passed > threshold || (even && tie && passed == threshold)) {
                    return true;
                }
            } else {
                ++failed;
                if (failed > threshold || (even && !tie && failed == threshold)) {
                    return false;
                }
            }
        }
        //dummy
        return false;
    
public synchronized voidsetAllowtie(boolean b)
Set whether ties are allowed.

param
b whether a tie is a pass.

        tie = b;