1 11 package org.eclipse.ui.internal.intro.universal.util; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 21 public class PreferenceArbiter { 22 23 private Map references; 24 private Object leader; 25 26 public void consider(Object obj) { 27 if (obj != null) { 28 if (references == null) { 29 references = new HashMap (); 30 } 31 int[] count = (int[])references.get(obj); 32 if (count == null) { 33 count = new int[] { 0 }; 34 references.put(obj, count); 35 } 36 ++count[0]; 37 if (obj != leader) { 38 if (leader == null) { 39 leader = obj; 40 } 41 else if (count[0] > ((int[])references.get(leader))[0]) { 42 leader = obj; 43 } 44 } 45 } 46 } 47 48 public Object getWinner() { 49 return leader; 50 } 51 } 52 | Popular Tags |