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) 1998-1999 Sun Microsystems, Inc.
  26  * All rights reserved.
  27  */
  28 
  29 package com.sun.dhcpmgr.data;
  30 
  31 import java.io.Serializable;
  32 
  33 /**
  34  * DhcpResource represents a record in the /etc/defaults/dhcp file.  Each
  35  * record is either an option setting for the DHCP daemon or a comment.
  36  */
  37 public class DhcpResource implements Serializable {
  38     private String key;
  39     private String value;
  40     private boolean comment;
  41 
  42     public DhcpResource() {
  43         this("", "", false);
  44     }
  45 
  46     public DhcpResource(String key, String value) {
  47         this(key, value, false);
  48     }
  49 
  50     public DhcpResource(String key, String value, boolean comment) {
  51         this.key = key;
  52         this.value = value;
  53         this.comment = comment;
  54     }
  55     
  56     public boolean isComment() {
  57         return comment;
  58     }
  59 
  60     public void setComment(boolean comment) {
  61         this.comment = comment;
  62     }
  63 
  64     public String getKey() {
  65         return key;
  66     }
  67     
  68     public void setKey(String key) {
  69         this.key = key;
  70     }
  71     
  72     public String getValue() {
  73         return value;
  74     }
  75     
  76     public void setValue(String value) {
  77         this.value = value;
  78     }
  79     
  80     /**
  81      * Compare for equality against another object.
  82      * @return true if the object is another DhcpResource instance and
  83      * they are both comments or normal resources and the key value is
  84      * identical.  The value of 'value' is irrelevant.  This is primarily
  85      * used by the indexOf method of the ArrayList used to store the options
  86      * in DhcpdOptions.
  87      */
  88     public boolean equals(Object o) {
  89         if (o instanceof DhcpResource) {
  90             DhcpResource r = (DhcpResource)o;
  91             return (comment == r.isComment()) && key.equals(r.getKey());
  92         } else {
  93             return false;
  94         }
  95     }
  96 
  97     public String toString() {
  98         if (comment) {
  99             return "#" + key;
 100         } else {
 101             return key + "=" + value;
 102         }
 103     }
 104 }