001package com.hfg.javascript.ext; 002 003 004 005import com.hfg.util.DataType; 006 007import java.util.Collection; 008import java.util.HashMap; 009import java.util.Map; 010 011//------------------------------------------------------------------------------ 012/** 013 Enumeration ExtJs field types. 014 <div> 015 @author J. Alex Taylor, hairyfatguy.com 016 </div> 017 */ 018//------------------------------------------------------------------------------ 019// com.hfg Library 020// 021// This library is free software; you can redistribute it and/or 022// modify it under the terms of the GNU Lesser General Public 023// License as published by the Free Software Foundation; either 024// version 2.1 of the License, or (at your option) any later version. 025// 026// This library is distributed in the hope that it will be useful, 027// but WITHOUT ANY WARRANTY; without even the implied warranty of 028// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 029// Lesser General Public License for more details. 030// 031// You should have received a copy of the GNU Lesser General Public 032// License along with this library; if not, write to the Free Software 033// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 034// 035// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 036// jataylor@hairyfatguy.com 037//------------------------------------------------------------------------------ 038 039public class ExtFieldType 040{ 041 private static Map<String, ExtFieldType> sUniqueValueMap = new HashMap<>(); 042 043 public static final ExtFieldType AUTO = new ExtFieldType("auto"); 044 public static final ExtFieldType BOOLEAN = new ExtFieldType("boolean"); 045 public static final ExtFieldType DATE = new ExtFieldType("date"); 046 public static final ExtFieldType FLOAT = new ExtFieldType("float"); 047 public static final ExtFieldType INT = new ExtFieldType("int"); 048 public static final ExtFieldType NUMBER = new ExtFieldType("number"); 049 public static final ExtFieldType STRING = new ExtFieldType("string"); 050 051 052 private String mName; 053 054 055 //-------------------------------------------------------------------------- 056 private ExtFieldType(String inName) 057 { 058 mName = inName; 059 sUniqueValueMap.put(mName, this); 060 } 061 062 //-------------------------------------------------------------------------- 063 public static ExtFieldType valueOf(String inString) 064 { 065 return sUniqueValueMap.get(inString); 066 } 067 068 //-------------------------------------------------------------------------- 069 public static ExtFieldType valueOf(DataType inDataType) 070 { 071 ExtFieldType fieldType = null; 072 switch (inDataType) 073 { 074 case BOOLEAN: 075 fieldType = BOOLEAN; 076 break; 077 case INTEGER: 078 case BIGINT: 079 fieldType = INT; 080 break; 081 case DOUBLE: 082 case FLOAT: 083 fieldType = NUMBER; 084 break; 085 case STRING: 086 case CHARACTER: 087 fieldType = STRING; 088 break; 089 case DATE: 090 fieldType = DATE; 091 } 092 093 return fieldType; 094 } 095 096 //-------------------------------------------------------------------------- 097 public static Collection<ExtFieldType> values() 098 { 099 return sUniqueValueMap.values(); 100 } 101 102 //-------------------------------------------------------------------------- 103 @Override 104 public String toString() 105 { 106 return name(); 107 } 108 109 //-------------------------------------------------------------------------- 110 public String name() 111 { 112 return mName; 113 } 114 115 //-------------------------------------------------------------------------- 116 public DataType toDataType() 117 { 118 DataType dataType = null; 119 120 if (name().equalsIgnoreCase("string")) 121 { 122 dataType = DataType.STRING; 123 } 124 else if (name().equalsIgnoreCase("int")) 125 { 126 dataType = DataType.INTEGER; 127 } 128 else if (name().equalsIgnoreCase("number")) 129 { 130 dataType = DataType.DOUBLE; 131 } 132 else if (name().equalsIgnoreCase("date")) 133 { 134 dataType = DataType.DATE; 135 } 136 else if (name().equalsIgnoreCase("boolean")) 137 { 138 dataType = DataType.BOOLEAN; 139 } 140 141 return dataType; 142 } 143}