001 package edu.nrao.sss.model.parameter; 002 003 import java.util.ArrayList; 004 import java.util.Collections; 005 import java.util.Comparator; 006 import java.util.HashMap; 007 import java.util.List; 008 009 import edu.nrao.sss.util.StringUtil; 010 011 /** 012 * Wraps the Band enum in a hash for quick lookups on band. 013 * <p> 014 * <b>Version Info:</b> <table style="margin-left:2em"> 015 * <tr> 016 * <td>$Revision: 329 $</td> 017 * </tr> 018 * <tr> 019 * <td>$Date: 2007-02-06 11:43:05 -0700 (Tue, 06 Feb 2007) $</td> 020 * </tr> 021 * <tr> 022 * <td>$Author: switz $</td> 023 * </tr> 024 * </table> 025 * </p> 026 * 027 * @author Stephan Witz 028 * @since 2007-09-10 029 */ 030 public class Bands { 031 private static HashMap<String, Band> map; 032 033 private static Bands SINGLETON; 034 035 private Bands() { 036 map = new HashMap<String, Band>(); 037 // The pad parameters, no bands required 038 for (Band band : Band.values()) 039 map.put(band.getName(), band); 040 } 041 042 /** 043 * Returns an instance of this Bands utility. 044 * 045 * @return bands. 046 */ 047 public static Bands getInstance() { 048 // Just-in-time creation 049 if (SINGLETON == null) 050 SINGLETON = new Bands(); 051 return SINGLETON; 052 } 053 054 public Band getBand(String name) { 055 return map.get(name); 056 } 057 058 public String getBandNames() { 059 List<String> names = new ArrayList<String>(); 060 for (Band band : map.values()) 061 names.add(band.getName()); 062 return StringUtil.getInstance().fromCollection(names, ", "); 063 } 064 065 @SuppressWarnings("unchecked") 066 public List<String> getBandNamesList() { 067 List<String> result = new ArrayList<String>(); 068 List<Band> bandList = new ArrayList<Band>(); 069 for (Band band : map.values()) 070 bandList.add(band); 071 Comparator comparator = new Comparator() { 072 public int compare(Object o1, Object o2) { 073 Band c1 = (Band) o1; 074 Band c2 = (Band) o2; 075 Integer mHz1 = new Integer(c1.getMegaHertz()); 076 Integer mHz2 = new Integer(c2.getMegaHertz()); 077 return mHz1.compareTo(mHz2); 078 } 079 }; 080 Collections.sort(bandList, comparator); 081 for (Band band: bandList) 082 result.add(band.getName()); 083 return result; 084 } 085 }