Source Code Cross Referenced for SelectedTag.java in  » Science » weka » weka » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » weka » weka.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    This program is free software; you can redistribute it and/or modify
003:         *    it under the terms of the GNU General Public License as published by
004:         *    the Free Software Foundation; either version 2 of the License, or
005:         *    (at your option) any later version.
006:         *
007:         *    This program is distributed in the hope that it will be useful,
008:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *    GNU General Public License for more details.
011:         *
012:         *    You should have received a copy of the GNU General Public License
013:         *    along with this program; if not, write to the Free Software
014:         *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015:         */
016:
017:        /*
018:         *    SelectedTag.java
019:         *    Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
020:         *
021:         */
022:
023:        package weka.core;
024:
025:        import java.util.HashSet;
026:
027:        /**
028:         * Represents a selected value from a finite set of values, where each
029:         * value is a Tag (i.e. has some string associated with it). Primarily
030:         * used in schemes to select between alternative behaviours,
031:         * associating names with the alternative behaviours.
032:         *
033:         * @author <a href="mailto:len@reeltwo.com">Len Trigg</a> 
034:         * @version $Revision: 1.10 $
035:         */
036:        public class SelectedTag {
037:
038:            /** The index of the selected tag */
039:            protected int m_Selected;
040:
041:            /** The set of tags to choose from */
042:            protected Tag[] m_Tags;
043:
044:            /**
045:             * Creates a new <code>SelectedTag</code> instance.
046:             *
047:             * @param tagID the id of the selected tag.
048:             * @param tags an array containing the possible valid Tags.
049:             * @throws IllegalArgumentException if the selected tag isn't in the array
050:             * of valid values or the IDs/IDStrs are not unique.
051:             */
052:            public SelectedTag(int tagID, Tag[] tags) {
053:                // are IDs unique?
054:                HashSet ID = new HashSet();
055:                HashSet IDStr = new HashSet();
056:                for (int i = 0; i < tags.length; i++) {
057:                    ID.add(new Integer(tags[i].getID()));
058:                    IDStr.add(tags[i].getIDStr());
059:                }
060:                if (ID.size() != tags.length)
061:                    throw new IllegalArgumentException(
062:                            "The IDs are not unique!");
063:                if (IDStr.size() != tags.length)
064:                    throw new IllegalArgumentException(
065:                            "The ID strings are not unique!");
066:
067:                for (int i = 0; i < tags.length; i++) {
068:                    if (tags[i].getID() == tagID) {
069:                        m_Selected = i;
070:                        m_Tags = tags;
071:                        return;
072:                    }
073:                }
074:
075:                throw new IllegalArgumentException("Selected tag is not valid");
076:            }
077:
078:            /**
079:             * Creates a new <code>SelectedTag</code> instance.
080:             *
081:             * @param tagText the text of the selected tag (case-insensitive).
082:             * @param tags an array containing the possible valid Tags.
083:             * @throws IllegalArgumentException if the selected tag isn't in the array
084:             * of valid values.
085:             */
086:            public SelectedTag(String tagText, Tag[] tags) {
087:                for (int i = 0; i < tags.length; i++) {
088:                    if (tags[i].getReadable().equalsIgnoreCase(tagText)
089:                            || tags[i].getIDStr().equalsIgnoreCase(tagText)) {
090:                        m_Selected = i;
091:                        m_Tags = tags;
092:                        return;
093:                    }
094:                }
095:                throw new IllegalArgumentException("Selected tag is not valid");
096:            }
097:
098:            /**
099:             * Returns true if this SelectedTag equals another object
100:             * 
101:             * @param o the object to compare with
102:             * @return true if the tags and the selected tag are the same
103:             */
104:            public boolean equals(Object o) {
105:                if ((o == null) || !(o.getClass().equals(this .getClass()))) {
106:                    return false;
107:                }
108:                SelectedTag s = (SelectedTag) o;
109:                if ((s.getTags() == m_Tags)
110:                        && (s.getSelectedTag() == m_Tags[m_Selected])) {
111:                    return true;
112:                } else {
113:                    return false;
114:                }
115:            }
116:
117:            /**
118:             * Gets the selected Tag.
119:             *
120:             * @return the selected Tag.
121:             */
122:            public Tag getSelectedTag() {
123:                return m_Tags[m_Selected];
124:            }
125:
126:            /**
127:             * Gets the set of all valid Tags.
128:             *
129:             * @return an array containing the valid Tags.
130:             */
131:            public Tag[] getTags() {
132:                return m_Tags;
133:            }
134:
135:            /**
136:             * returns the selected tag in string representation
137:             * 
138:             * @return the selected tag as string
139:             */
140:            public String toString() {
141:                return getSelectedTag().toString();
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.