| Line | Hits | Source |
|---|---|---|
| 1 | /* | |
| 2 | ||
| 3 | Copyright 2004, Martian Software, Inc. | |
| 4 | ||
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | you may not use this file except in compliance with the License. | |
| 7 | You may obtain a copy of the License at | |
| 8 | ||
| 9 | http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | ||
| 11 | Unless required by applicable law or agreed to in writing, software | |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | See the License for the specific language governing permissions and | |
| 15 | limitations under the License. | |
| 16 | ||
| 17 | */ | |
| 18 | ||
| 19 | package com.martiansoftware.nailgun; | |
| 20 | ||
| 21 | /** | |
| 22 | * Provides a means to map memorable, short names to classes in order | |
| 23 | * to make the issuing of commands more convenient. For example, an | |
| 24 | * Alias can map the "<code>mycommand</code>" command to the <code>com.yourdomain.yourpackage.YourClass</code> | |
| 25 | * class. Obviously, it's a lot easier to type "<code>ng mycommand</code>" than the fully | |
| 26 | * qualified class name. | |
| 27 | * | |
| 28 | * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a> | |
| 29 | */ | |
| 30 | public class Alias implements Comparable { | |
| 31 | ||
| 32 | /** | |
| 33 | * The alias name | |
| 34 | */ | |
| 35 | private String name; | |
| 36 | ||
| 37 | /** | |
| 38 | * The alias description (may be used to provide help to users) | |
| 39 | */ | |
| 40 | private String description; | |
| 41 | ||
| 42 | /** | |
| 43 | * The class providing a <code>main()</code> or <code>nailMain()</code> method | |
| 44 | */ | |
| 45 | private Class clazz; | |
| 46 | ||
| 47 | /** | |
| 48 | * Creates a new Alias with the specified properties. | |
| 49 | * @param name the alias name (short command) | |
| 50 | * @param description a description of the command | |
| 51 | * @param clazz the class implementing the command | |
| 52 | */ | |
| 53 | 12 | public Alias(String name, String description, Class clazz) { |
| 54 | 12 | if (name == null) throw (new IllegalArgumentException("Alias must have a name.")); |
| 55 | 12 | this.name = name.trim(); |
| 56 | 12 | if (this.name.length() == 0) throw (new IllegalArgumentException("Alias must have a name.")); |
| 57 | ||
| 58 | 12 | if (clazz == null) throw (new IllegalArgumentException("Alias must have an associated class.")); |
| 59 | 12 | this.description = description; |
| 60 | 12 | this.clazz = clazz; |
| 61 | 12 | } |
| 62 | ||
| 63 | /** | |
| 64 | * Returns the <code>Class</code> object providing a static <code>main()</code> or <code>nailMain()</code> method | |
| 65 | * for this command. | |
| 66 | * @return the <code>Class</code> object providing a static <code>main()</code> or <code>nailMain()</code> method | |
| 67 | * for this command. | |
| 68 | */ | |
| 69 | public Class getAliasedClass() { | |
| 70 | 1 | return(clazz); |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Returns the name of the aliased command | |
| 75 | * @return the name of the aliased command | |
| 76 | */ | |
| 77 | public String getName() { | |
| 78 | 40 | return (name); |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Returns a description for the aliased command | |
| 83 | * @return a description for the aliased command | |
| 84 | */ | |
| 85 | public String getDescription() { | |
| 86 | 1 | return (description); |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * @see Object#hashCode() | |
| 91 | */ | |
| 92 | public int hashCode() { | |
| 93 | 0 | return (name.hashCode()); |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * Checks whether two Aliases have the same name. Does <b>not</b> | |
| 98 | * compare any other fields. | |
| 99 | * @param o the other Alias to check | |
| 100 | * @return true if the specified Alias has the same name as this Alias. | |
| 101 | */ | |
| 102 | public boolean equals(Object o) { | |
| 103 | 6 | return (compareTo(o) == 0); |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Compares Alias <b>names</b> - no other fields are compared. | |
| 108 | * @see Comparable#compareTo(Object) | |
| 109 | */ | |
| 110 | public int compareTo(Object o) { | |
| 111 | 14 | return (name.compareTo(((Alias) o).getName())); |
| 112 | } | |
| 113 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |