1 18 package org.apache.tools.ant.types.resources.selectors; 19 20 import java.util.Iterator ; 21 22 import org.apache.tools.ant.types.Resource; 23 24 28 public class Majority 29 extends ResourceSelectorContainer implements ResourceSelector { 30 31 private boolean tie = true; 32 33 36 public Majority() { 37 } 38 39 43 public Majority(ResourceSelector[] r) { 44 super(r); 45 } 46 47 51 public synchronized void setAllowtie(boolean b) { 52 tie = b; 53 } 54 55 60 public synchronized boolean isSelected(Resource r) { 61 int passed = 0; 62 int failed = 0; 63 int count = selectorCount(); 64 boolean even = count % 2 == 0; 65 int threshold = count / 2; 66 67 for (Iterator i = getSelectors(); i.hasNext();) { 68 if (((ResourceSelector) i.next()).isSelected(r)) { 69 ++passed; 70 if (passed > threshold || (even && tie && passed == threshold)) { 71 return true; 72 } 73 } else { 74 ++failed; 75 if (failed > threshold || (even && !tie && failed == threshold)) { 76 return false; 77 } 78 } 79 } 80 return false; 82 } 83 84 } 85 | Popular Tags |