001package burrows.api.finance.model; 002 003/** 004 * An enumeration that represents the companies that the API supports. 005 * 006 * @author <a href="mailto:jaredsburrows@gmail.com">Jared Burrows</a> 007 * @since 0.0.1 008 */ 009public enum Company { 010 /** http://www.yahoo.com/ **/ 011 YAHOO(0, "YAHOO"), 012 // TODO no support 013 /** http://www.google.com/ **/ 014 GOOGLE(1, "GOOGLE"); 015 016 /** Integer value of the Enum. **/ 017 private final int intValue; 018 /** String value of the Enum. **/ 019 private final String stringValue; 020 021 /** 022 * Company Enum 023 * @param intValue Integer value of the Enum. 024 * @param stringValue String value of the Enum. 025 */ 026 private Company(final int intValue, final String stringValue) { 027 this.intValue = intValue; 028 this.stringValue = stringValue; 029 } 030 031 /** 032 * Returns the integer value of this enum instance. 033 * 034 * @return the integer value of this enum instance. 035 * 036 * @see #fromInt(int) 037 * @since 0.0.1 038 */ 039 public int getIntValue() { 040 return this.intValue; 041 } 042 043 /** 044 * Returns the underlying {@link #stringValue} of this instance. 045 * 046 * @return the underlying {@link #stringValue} of this instance. 047 * 048 * @see #fromString(String) 049 * @since 0.0.1 050 */ 051 public String getStringValue() { 052 return this.stringValue; 053 } 054 055 /** 056 * Returns the integer value of this enum instance. 057 * 058 * @param intValue the integer value to determine the matching enum instance for. 059 * 060 * @return the enum instance for the specified int value, or {@code null} if there is no match. 061 * 062 * @see #getIntValue() 063 * @since 0.0.1 064 */ 065 public static Company fromInt(int intValue) { 066 for (Company instance : values()) { 067 if (instance.intValue == intValue) { 068 return instance; 069 } 070 } 071 return null; 072 } 073 074 /** 075 * Returns the enum instance for the specified string. 076 * 077 * @param stringValue the string value to determine the matching enum instance for. 078 * 079 * @return the enum instance for the specified string, or {@code null} if there is no match. 080 * 081 * @see #getStringValue() 082 * @since 0.0.1 083 */ 084 public static Company fromString(String stringValue) { 085 if (stringValue == null || stringValue.length() == 0) { 086 return null; 087 } 088 089 for (Company instance : values()) { 090 if (instance.stringValue.equalsIgnoreCase(stringValue)) { 091 return instance; 092 } 093 } 094 return null; 095 } 096}