View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.registry;
17  
18  import org.fourthline.cling.model.ExpirationDetails;
19  
20  /**
21   * Internal class, required by {@link RegistryImpl}.
22   *
23   * @author Christian Bauer
24   */
25  class RegistryItem<K, I> {
26  
27      private K key;
28      private I item;
29      private ExpirationDetails expirationDetails = new ExpirationDetails();
30  
31      RegistryItem(K key) {
32          this.key = key;
33      }
34  
35      RegistryItem(K key, I item, int maxAgeSeconds) {
36          this.key = key;
37          this.item = item;
38          this.expirationDetails = new ExpirationDetails(maxAgeSeconds);
39      }
40  
41      public K getKey() {
42          return key;
43      }
44  
45      public I getItem() {
46          return item;
47      }
48  
49      public ExpirationDetails getExpirationDetails() {
50          return expirationDetails;
51      }
52  
53      public boolean equals(Object o) {
54          if (this == o) return true;
55          if (o == null || getClass() != o.getClass()) return false;
56  
57          RegistryItem that = (RegistryItem) o;
58  
59          return key.equals(that.key);
60      }
61  
62      public int hashCode() {
63          return key.hashCode();
64      }
65  
66      @Override
67      public String toString() {
68          return "("+getClass().getSimpleName()+") " + getExpirationDetails() + " KEY: " + getKey() + " ITEM: " + getItem();
69      }
70  }