From: leo Date: Tue, 10 Feb 2009 02:18:47 +0000 (+0000) Subject: git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@2953 ae02f08e... X-Git-Url: http://git.sourceforge.jp/view?a=commitdiff_plain;h=13efc29eb768ec64ef301f5c3bb320dcb6476bfe;p=xerial%2Fxerial-core.git git-svn-id: xerial.org/svn/project/XerialJ/trunk/xerial-core@2953 ae02f08e-27ec-0310-ae8c-8ba02fe2eafd --- diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 7eb424f..a00697e 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,11 +1,11 @@ -#Sat Nov 22 13:43:28 JST 2008 +#Tue Feb 10 10:50:36 GMT+09:00 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=82 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 @@ -13,14 +13,14 @@ org.eclipse.jdt.core.formatter.alignment_for_assignment=0 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=82 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=82 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 diff --git a/eclipse/code-format.xml b/eclipse/code-format.xml new file mode 100644 index 0000000..64f7d7d --- /dev/null +++ b/eclipse/code-format.xml @@ -0,0 +1,267 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/xerial/util/FileType.java b/src/main/java/org/xerial/util/FileType.java new file mode 100644 index 0000000..8053026 --- /dev/null +++ b/src/main/java/org/xerial/util/FileType.java @@ -0,0 +1,112 @@ +/*-------------------------------------------------------------------------- + * Copyright 2009 Taro L. Saito + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *--------------------------------------------------------------------------*/ +//-------------------------------------- +// XerialJ +// +// FileType.java +// Since: Feb 10, 2009 10:38:10 AM +// +// $URL$ +// $Author$ +//-------------------------------------- +package org.xerial.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * File type notation + * + * @author leo + * + */ +public enum FileType { + + // image formats + JPEG("jpeg,jpg"), + PNG("png"), + GIF("gif"), + BMP("bmp"), + TIFF("tiff"), + + // text formats + XML("xml"), + JSON("json"), + SILK("silk"), + TAB("tab"), + CSV("csv"), + FASTA("fasta"), + TEX("tex"), + TEXT("txt"), + + // HTML formats + HTML("html,htm"), + + // binary format + PDF("pdf"), + WORD("doc,docx"), + EXCEL("xls,xlsx"), + POWER_POINT("ppt,pptx"), + + // compressed format + ZIP("zip"), + GZIP("gz"), + TAR("tar"), + TAR_GZ("tar.gz"), + BZIP2("bz2") + + ; + + private static HashMap fileTypeTable = new HashMap(); + static + { + for (FileType eachType : FileType.values()) + { + for (String eachExt : eachType.getFileExtList()) + fileTypeTable.put(eachExt, eachType); + } + } + + private ArrayList fileExtList; + + private FileType(String fileExtCSV) + { + String[] fileExt = fileExtCSV.split(",\\s*"); + assert (fileExt != null); + fileExtList = new ArrayList(fileExt.length); + for (String each : fileExt) + { + fileExtList.add(each); + } + } + + public List getFileExtList() + { + return fileExtList; + } + + /** + * Retrieve file type + * + * @param fileExt + * @return + */ + public static FileType getFileType(String fileExt) + { + return fileTypeTable.get(fileExt.toLowerCase()); + } +} diff --git a/src/test/java/org/xerial/util/FileTypeTest.java b/src/test/java/org/xerial/util/FileTypeTest.java new file mode 100644 index 0000000..a854822 --- /dev/null +++ b/src/test/java/org/xerial/util/FileTypeTest.java @@ -0,0 +1,59 @@ +/*-------------------------------------------------------------------------- + * Copyright 2009 Taro L. Saito + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *--------------------------------------------------------------------------*/ +//-------------------------------------- +// XerialJ +// +// FileTypeTest.java +// Since: Feb 10, 2009 11:13:40 AM +// +// $URL$ +// $Author$ +//-------------------------------------- +package org.xerial.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class FileTypeTest +{ + + @Before + public void setUp() throws Exception + {} + + @After + public void tearDown() throws Exception + {} + + @Test + public void testGetFileType() + { + assertEquals(FileType.PNG, FileType.getFileType("png")); + assertEquals(FileType.JPEG, FileType.getFileType("jpg")); + assertEquals(FileType.JPEG, FileType.getFileType("jpeg")); + + for (FileType eachType : FileType.values()) + { + for (String eachFileExt : eachType.getFileExtList()) + assertEquals(eachType, FileType.getFileType(eachFileExt)); + } + + } + +}