source: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/misc/Identifier.java @ 1573

Last change on this file since 1573 was 1573, checked in by rkrimmel, 10 years ago

Now really adding PAL Library

File size: 2.1 KB
Line 
1// Identifier.java
2//
3// (c) 1999-2000 PAL Development Core Team
4//
5// This package may be distributed under the
6// terms of the Lesser GNU General Public License (LGPL)
7
8package de.ugoe.cs.autoquest.tasktrees.alignment.pal.misc;
9
10import java.io.Serializable;
11import de.ugoe.cs.autoquest.tasktrees.alignment.pal.util.Comparable;
12
13/**
14 * An identifier for some sampled data. This will most often be
15 * for example, the accession number of a DNA sequence, or the
16 * taxonomic name that the sequence represents, et cetera.
17 *
18 * @version $Id: Identifier.java,v 1.6 2001/12/02 22:32:18 matt Exp $
19 *
20 * @author Alexei Drummond
21 */
22
23
24public class Identifier implements
25                                         Comparable, Nameable {
26
27        private String name = null;
28
29       
30        public static Identifier ANONYMOUS = new Identifier("");
31
32                public Identifier() {}
33
34                public Identifier(String name) {
35        setName(name);
36                }
37
38                public String toString() {
39        return getName();
40                }
41
42                // implements Comparable interface
43
44                public int compareTo(Object c) {
45
46        return getName().compareTo(((Identifier)c).getName());
47                }
48
49                public boolean equals(Object c) {
50
51        if (c instanceof Identifier) {
52                        return getName().equals(((Identifier)c).getName());
53        } else return false;
54                }
55
56                // implements Nameable interface
57
58                public String getName() {
59        return name;
60                }
61
62                public void setName(String s) {
63        name = s;
64                }
65        /**
66         * Translates an array of identifiers into an array of strings
67         */
68        public final static String[] getNames(Identifier[] ids) {
69                String[] names = new String[ids.length];
70                for(int i = 0 ; i < names.length ; i++) {
71                        names[i] = ids[i].getName();
72                }
73                return names;
74        }
75        /**
76         * Translates an array of identifiers into an array of strings, with optional removal of particular identifier
77         * @param toIgnoreIndex the index of an idetifier to ignore, if <0 no element is ignored
78         */
79        public final static String[] getNames(Identifier[] ids, int toIgnore) {
80                if(toIgnore<0||toIgnore>=ids.length) {
81                        return getNames(ids);
82                }
83                String[] names = new String[ids.length-1];
84                int index = 0;
85                for(int i = 0 ; i < names.length ; i++) {
86                        if(i!=toIgnore) {
87                                names[index] = ids[i].getName();
88                                index++;
89                        }
90                }
91                return names;
92        }
93
94}
95
Note: See TracBrowser for help on using the repository browser.