1 18 19 package org.apache.tools.ant.types.selectors; 20 21 import java.io.File ; 22 import java.util.Enumeration ; 23 24 35 public class MajoritySelector extends BaseSelectorContainer { 36 37 private boolean allowtie = true; 38 39 42 public MajoritySelector() { 43 } 44 45 48 public String toString() { 49 StringBuffer buf = new StringBuffer (); 50 if (hasSelectors()) { 51 buf.append("{majorityselect: "); 52 buf.append(super.toString()); 53 buf.append("}"); 54 } 55 return buf.toString(); 56 } 57 58 65 public void setAllowtie(boolean tiebreaker) { 66 allowtie = tiebreaker; 67 } 68 69 80 public boolean isSelected(File basedir, String filename, File file) { 81 validate(); 82 int yesvotes = 0; 83 int novotes = 0; 84 Enumeration e = selectorElements(); 85 boolean result; 86 87 while (e.hasMoreElements()) { 88 result = ((FileSelector) e.nextElement()).isSelected(basedir, 89 filename, file); 90 if (result) { 91 yesvotes = yesvotes + 1; 92 } else { 93 novotes = novotes + 1; 94 } 95 } 96 if (yesvotes > novotes) { 97 return true; 98 } else if (novotes > yesvotes) { 99 return false; 100 } 101 return allowtie; 103 } 104 } 105 106 | Popular Tags |