1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright (c) 2001 by Sun Microsystems, Inc. 26 * All rights reserved. 27 */ 28 package com.sun.dhcpmgr.cli.common; 29 30 /** 31 * This class is used to represent one command line option. 32 */ 33 public class DhcpCliOption { 34 35 /** 36 * The option key. 37 */ 38 private int option; 39 40 /** 41 * The value of the option. 42 */ 43 private String value; 44 45 /** 46 * Constructor most likely used to create a boolean option. 47 * @param option the option key value 48 */ 49 public DhcpCliOption(int option) { 50 51 this(option, null); 52 53 } // constructor 54 55 /** 56 * Constructor most likely used to create a String valued option. 57 * @param option the option key value 58 */ 59 public DhcpCliOption(int option, String value) { 60 61 this.option = option; 62 this.value = value; 63 64 } // constructor 65 66 /** 67 * Returns the option key value. 68 * @return the option key value 69 */ 70 public int getOption() { 71 72 return option; 73 74 } // getOption 75 76 /** 77 * Set the option key value. 78 * @param option the option key value 79 */ 80 public void setOption(int option) { 81 82 this.option = option; 83 84 } // setOption 85 86 /** 87 * Returns the option key value as a Character. 88 * @param option the key value which needs converting. 89 * @return the option key value as a Character. 90 */ 91 public static Character getOptionCharacter(int option) { 92 93 return (new Character((char)option)); 94 95 } // getOptionCharacter 96 97 /** 98 * Returns the option key value as a Character. 99 * @return the option key value as a Character. 100 */ 101 public Character getOptionCharacter() { 102 103 return (getOptionCharacter(option)); 104 105 } // getOptionCharacter 106 107 /** 108 * Returns the option value. 109 * @return the option value 110 */ 111 public String getValue() { 112 113 return value; 114 115 } // getValue 116 117 /** 118 * Set the option value. 119 * @param option the option value 120 */ 121 public void setValue(String value) { 122 123 this.value = value; 124 125 } // setValue 126 127 /** 128 * Compare for equality against another object. 129 * @return true if the object is another DhcpCliOption instance and 130 * they are both have the same key value. The value of 'value' is 131 * irrelevant. This is primarily used by the indexOf method of the 132 * ArrayList used to store the options in DhcpCliOptions. 133 */ 134 public boolean equals(Object o) { 135 136 if (o instanceof DhcpCliOption) { 137 DhcpCliOption op = (DhcpCliOption)o; 138 return (option == op.getOption()); 139 } else { 140 return false; 141 } 142 143 } // equals 144 145 /** 146 * The obligatory toString() method that returns a string representation 147 * of an object of this class. 148 * @return a string representation of an object of this class. 149 */ 150 public String toString() { 151 152 return option + "=" + value; 153 154 } // toString 155 156 } // DhcpCliOption