001 /* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016 package org.opengion.fukurou.model; 017 018 import java.util.regex.Pattern ; 019 020 /** 021 * Native Type(int型やlong型?を管?るEnum型です? 022 * 023 * @og.group 画面表示 024 * 025 * @version 4.0 026 * @author Hiroki Nakamura 027 * @since JDK5.0, 028 */ 029 public enum NativeType { 030 031 /** NATIVEの?[int] の識別コー?(INT) */ 032 INT , 033 034 /** NATIVEの?[long] の識別コー?(LONG) */ 035 LONG , 036 037 /** NATIVEの?[double] の識別コー?(DOUBLE) */ 038 DOUBLE , 039 040 /** NATIVEの?[String] の識別コー?(STRING) */ 041 STRING , 042 043 /** NATIVEの?[Calendar] の識別コー?(CALENDAR) */ 044 CALENDAR ; 045 046 private static final Pattern P_INT = Pattern.compile("-?[0-9]{1,9}"); 047 private static final Pattern P_LONG = Pattern.compile("-?[0-9]+"); 048 private static final Pattern P_DOUBLE = Pattern.compile("-?[0-9]+\\.?[0-9]+"); 049 private static final Pattern P_CALENDAR = Pattern.compile("[0-9]{4}/[01]{1}[0-9]{1}/[0-3]{1}[0-9]{1}"); 050 051 /** 052 * ????が?どの、NativeType なのか?判定します? 053 * 054 * 判定ロジ?は、以下?様にして?す? 055 * <pre> 056 * INT = Pattern.compile("-?[0-9]{1,9}"); 057 * LONG = Pattern.compile("-?[0-9]+"); 058 * DOUBLE = Pattern.compile("-?[0-9]+\\.?[0-9]+"); 059 * CALENDAR = Pattern.compile("[0-9]{4}/[01]{1}[0-9]{1}/[0-3]{1}[0-9]{1}"); 060 * </pre> 061 * 062 * @og.rev 5.1.8.0 (2010/07/01) 新規追? 063 * 064 * @param str 判定する文字? 065 * 066 * @return 判定結果 067 */ 068 public static NativeType getType( final String str ) { 069 if( str == null ) { return STRING ; } 070 else if( P_INT.matcher( str ).matches() ) { return INT ; } 071 else if( P_LONG.matcher( str ).matches() ) { return LONG ; } 072 else if( P_DOUBLE.matcher( str ).matches() ) { return DOUBLE ; } 073 else if( P_CALENDAR.matcher( str ).matches() ) { return CALENDAR ; } 074 else { return STRING ; } 075 } 076 }