KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > content > FileSpec


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.content;
12
13 import org.eclipse.core.runtime.content.IContentType;
14
15 /**
16  * Provides a uniform representation for file specifications, such
17  * as file names, file extensions and regular expressions.
18  */

19 class FileSpec {
20     final static int BASIC_TYPE = IContentType.FILE_EXTENSION_SPEC | IContentType.FILE_NAME_SPEC;
21     private String JavaDoc text;
22     private int type;
23
24     public FileSpec(String JavaDoc text, int type) {
25         this.text = text;
26         this.type = type;
27     }
28
29     public String JavaDoc getText() {
30         return text;
31     }
32
33     public int getType() {
34         return type;
35     }
36
37     public static int getBasicType(int type) {
38         return BASIC_TYPE & type;
39     }
40
41     public boolean equals(Object JavaDoc other) {
42         if (!(other instanceof FileSpec))
43             return false;
44         FileSpec otherFileSpec = (FileSpec) other;
45         return equals(text, otherFileSpec.getType(), false);
46     }
47
48     public boolean equals(final String JavaDoc text, final int otherType, final boolean strict) {
49         return ((!strict && getBasicType(type) == getBasicType(otherType)) || type == otherType) && this.text.equalsIgnoreCase(text);
50     }
51
52     public int hashCode() {
53         return text.hashCode();
54     }
55
56     public static String JavaDoc getMappingKeyFor(String JavaDoc fileSpecText) {
57         return fileSpecText.toLowerCase();
58     }
59
60     public String JavaDoc toString() {
61         return getText();
62     }
63 }
64
Popular Tags