1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 package org.rocksdb;
7 
8 import java.util.Arrays;
9 
10 /**
11  * <p>Describes a column family with a
12  * name and respective Options.</p>
13  */
14 public class ColumnFamilyDescriptor {
15 
16   /**
17    * <p>Creates a new Column Family using a name and default
18    * options,</p>
19    *
20    * @param columnFamilyName name of column family.
21    * @since 3.10.0
22    */
ColumnFamilyDescriptor(final byte[] columnFamilyName)23   public ColumnFamilyDescriptor(final byte[] columnFamilyName) {
24     this(columnFamilyName, new ColumnFamilyOptions());
25   }
26 
27   /**
28    * <p>Creates a new Column Family using a name and custom
29    * options.</p>
30    *
31    * @param columnFamilyName name of column family.
32    * @param columnFamilyOptions options to be used with
33    *     column family.
34    * @since 3.10.0
35    */
ColumnFamilyDescriptor(final byte[] columnFamilyName, final ColumnFamilyOptions columnFamilyOptions)36   public ColumnFamilyDescriptor(final byte[] columnFamilyName,
37                                 final ColumnFamilyOptions columnFamilyOptions) {
38     columnFamilyName_ = columnFamilyName;
39     columnFamilyOptions_ = columnFamilyOptions;
40   }
41 
42   /**
43    * Retrieve name of column family.
44    *
45    * @return column family name.
46    * @since 3.10.0
47    */
getName()48   public byte[] getName() {
49     return columnFamilyName_;
50   }
51 
52   /**
53    * Retrieve name of column family.
54    *
55    * @return column family name.
56    * @since 3.10.0
57    *
58    * @deprecated Use {@link #getName()} instead.
59    */
60   @Deprecated
columnFamilyName()61   public byte[] columnFamilyName() {
62     return getName();
63   }
64 
65   /**
66    * Retrieve assigned options instance.
67    *
68    * @return Options instance assigned to this instance.
69    */
getOptions()70   public ColumnFamilyOptions getOptions() {
71     return columnFamilyOptions_;
72   }
73 
74   /**
75    * Retrieve assigned options instance.
76    *
77    * @return Options instance assigned to this instance.
78    *
79    * @deprecated Use {@link #getOptions()} instead.
80    */
81   @Deprecated
columnFamilyOptions()82   public ColumnFamilyOptions columnFamilyOptions() {
83     return getOptions();
84   }
85 
86   @Override
equals(final Object o)87   public boolean equals(final Object o) {
88     if (this == o) {
89       return true;
90     }
91     if (o == null || getClass() != o.getClass()) {
92       return false;
93     }
94 
95     final ColumnFamilyDescriptor that = (ColumnFamilyDescriptor) o;
96     return Arrays.equals(columnFamilyName_, that.columnFamilyName_)
97             && columnFamilyOptions_.nativeHandle_ == that.columnFamilyOptions_.nativeHandle_;
98   }
99 
100   @Override
hashCode()101   public int hashCode() {
102     int result = (int) (columnFamilyOptions_.nativeHandle_ ^ (columnFamilyOptions_.nativeHandle_ >>> 32));
103     result = 31 * result + Arrays.hashCode(columnFamilyName_);
104     return result;
105   }
106 
107   private final byte[] columnFamilyName_;
108   private final ColumnFamilyOptions columnFamilyOptions_;
109 }
110