001 package edu.nrao.sss.astronomy; 002 003 import java.util.EnumSet; 004 import java.util.Set; 005 006 import edu.nrao.sss.util.EnumerationUtility; 007 008 /** 009 * The polarizations a single receptor can detect. 010 * <p> 011 * This enumeration has the same name, and most of the elements have the same 012 * names and are in the same order, as the corresponding 013 * <a href="http://almasw.hq.eso.org/almasw/bin/view/HLA/GeneratedEnums#PolarizationType"> 014 * ALMA enumeration</a>. The one exception is the <tt>UNSPECIFIED</tt> 015 * element, which is not present in the ALMA specification.</p> 016 * <p> 017 * <b><u>References</u></b> 018 * <ul> 019 * <li><a href="http://scienceworld.wolfram.com/physics/StokesParameters.html"> 020 * World of Physics</a></li> 021 * <li><a href="http://www.atnf.csiro.au/computing/software/atca_aips/node11.html"> 022 * ATNF</a></li> 023 * <li><a href="http://en.wikipedia.org/wiki/Stokes_parameters"> 024 * Wikipedia</a></li> 025 * <li><a href="http://www.optics.arizona.edu/jcwyant/JoseDiaz/Polarization-Circular.htm"> 026 * University of Arizona</a> (there's a great 3D motion display here)</li> 027 * </ul></p> 028 * <b>Version Info:</b> 029 * <table style="margin-left:2em"> 030 * <tr><td>$Revision: 1387 $</td></tr> 031 * <tr><td>$Date: 2008-06-27 16:17:41 -0600 (Fri, 27 Jun 2008) $</td></tr> 032 * <tr><td>$Author: dharland $ (last person to modify)</td></tr> 033 * </table></p> 034 * 035 * @author David M. Harland 036 * @since 2007-09-24 037 */ 038 public enum PolarizationType 039 { 040 /** Right-handed circular polarization. */ 041 R(Dir.CIRCULAR) 042 { 043 @Override public PolarizationType getOpposite() { return L; } 044 }, 045 046 /** Left-handed circular polarization. */ 047 L(Dir.CIRCULAR) 048 { 049 @Override public PolarizationType getOpposite() { return R; } 050 }, 051 052 /** X-axis linear polarization. */ 053 X(Dir.LINEAR) 054 { 055 @Override public PolarizationType getOpposite() { return Y; } 056 }, 057 058 /** Y-axis linear polarization. */ 059 Y(Dir.LINEAR) 060 { 061 @Override public PolarizationType getOpposite() { return X; } 062 }, 063 064 /** Used when the polarization is unspecified or unknown. */ 065 UNSPECIFIED(false) 066 { 067 @Override public boolean isCircular() { return false; } 068 @Override public boolean isLinear() { return false; } 069 }; 070 071 private static interface Dir 072 { 073 static final boolean CIRCULAR = true; 074 static final boolean LINEAR = false; 075 } 076 077 private boolean circular; 078 079 /** Creates a new element. */ 080 private PolarizationType(boolean isCircular) 081 { 082 circular = isCircular; 083 } 084 085 /** 086 * Returns <i>true</i> if this is a type of <i>circular</i> polarization. 087 * @return <i>true</i> if this is a type of <i>circular</i> polarization. 088 */ 089 public boolean isCircular() 090 { 091 return circular; 092 } 093 094 /** 095 * Returns <i>true</i> if this is a type of <i>linear</i> polarization. 096 * @return <i>true</i> if this is a type of <i>linear</i> polarization. 097 */ 098 public boolean isLinear() 099 { 100 return !isCircular(); 101 } 102 103 /** 104 * Returns the opposite polarization. 105 * @return the opposite polarization. 106 */ 107 public PolarizationType getOpposite() 108 { 109 return this; //will override for all but UNSPECIFIED 110 } 111 112 /** 113 * Returns the polarization type represented by {@code text}. 114 * <p> 115 * For details about the transformation, see 116 * {@link EnumerationUtility#enumFromString(Class, String)}.</p> 117 * 118 * @param text a text representation of a polarization type. 119 * 120 * @return the polarization type represented by {@code text}. 121 */ 122 public static PolarizationType fromString(String text) 123 { 124 return EnumerationUtility.getSharedInstance() 125 .enumFromString(PolarizationType.class, text); 126 } 127 128 /** 129 * Returns the complete set of circular polarizations. 130 * @return the complete set of circular polarizations. 131 */ 132 public static Set<PolarizationType> getCircularTypes() 133 { 134 EnumSet<PolarizationType> types = EnumSet.noneOf(PolarizationType.class); 135 136 for (PolarizationType p : PolarizationType.values()) 137 if (p.isCircular()) 138 types.add(p); 139 140 return types; 141 } 142 143 /** 144 * Returns the complete set of linear polarizations. 145 * @return the complete set of linear polarizations. 146 */ 147 public static Set<PolarizationType> getLinearTypes() 148 { 149 EnumSet<PolarizationType> types = EnumSet.noneOf(PolarizationType.class); 150 151 for (PolarizationType p : PolarizationType.values()) 152 if (p.isLinear()) 153 types.add(p); 154 155 return types; 156 } 157 }