/* * [MemoryType.java] * * Summary: enum constants for memory types. * * Copyright: (c) 2011-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.7+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2011-02-20 initial version. */ package com.mindprod.mother; /** * enum constants for memory types. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-02-20 initial version. * @since 2011-02-20 */ public enum MemoryType { DDR3( "DDR-3" ), DDR2( "DDR-2" ), DDR(), SDRAM(), UNKNOWN(); /** * cannot use String... here, only in parm list alternate input names for the alias */ private final String[] aliases; /** * constructor for an enum constant * * @param aliases other names for string input */ MemoryType( String... aliases ) { this.aliases = aliases; } /** * convert alias string to equivalent canonical enum constant, like valueOf but accepts aliases too, and does not * care about case. * * @param s alias as string * * @return equivalent AppCat enum constant */ public static MemoryType valueOfAlias( String s ) { s = s.trim(); try { return valueOf( s.toUpperCase() ); } catch ( IllegalArgumentException e ) { // usual method failed, try looking up alias // This seems long winded, why no HashSet? // Because Java won't let me access a static common // lookup in the enum constructors. for ( MemoryType candidateEnum : MemoryType.values() ) { for ( String candidateString : candidateEnum.aliases ) { if ( candidateString.equalsIgnoreCase( s ) ) { return candidateEnum; } } } // fell out the bottom of search over all enums and aliases // give up throw new IllegalArgumentException( "unknown MemoryType: " + s ); } } /** * ordinary toString * * @return upper and lower case name for the manufacturer. */ public String toString() { if ( aliases.length > 0 ) { return aliases[ 0 ]; } else { return name(); } } }