@@ -103,16 +103,59 @@ private H3Core(NativeMethods h3Api) {
103103 this .h3Api = h3Api ;
104104 }
105105
106- /** Returns true if this is a valid H3 index. */
106+ /** Returns true if this is a valid H3 cell index. */
107107 public boolean isValidCell (long h3 ) {
108108 return h3Api .isValidCell (h3 );
109109 }
110110
111- /** Returns true if this is a valid H3 index. */
111+ /** Returns true if this is a valid H3 cell index. */
112112 public boolean isValidCell (String h3Address ) {
113113 return isValidCell (stringToH3 (h3Address ));
114114 }
115115
116+ /** Returns true if this is a valid H3 index. */
117+ public boolean isValidIndex (long h3 ) {
118+ return h3Api .isValidIndex (h3 );
119+ }
120+
121+ /** Returns true if this is a valid H3 index. */
122+ public boolean isValidIndex (String h3Address ) {
123+ return isValidIndex (stringToH3 (h3Address ));
124+ }
125+
126+ /** Construct a cell index from component parts */
127+ public long constructCell (int baseCellNumber , List <Integer > digits , int res ) {
128+ int [] digitsArray = digits .stream ().mapToInt (Integer ::intValue ).toArray ();
129+ if (digitsArray .length != res ) {
130+ throw new IllegalArgumentException (
131+ String .format (
132+ "Number of provided digits is incorrect, must be %d, was %d" ,
133+ res , digitsArray .length ));
134+ }
135+ if (digitsArray .length > 15 ) {
136+ throw new IllegalArgumentException (
137+ String .format (
138+ "Additional unused digits provided, must be at most 15 but was %d" ,
139+ digitsArray .length ));
140+ }
141+ return h3Api .constructCell (res , baseCellNumber , digitsArray );
142+ }
143+
144+ /** Construct a cell index from component parts */
145+ public long constructCell (int baseCellNumber , List <Integer > digits ) {
146+ return constructCell (baseCellNumber , digits , digits .size ());
147+ }
148+
149+ /** Construct a cell index from component parts */
150+ public String constructCellAddress (int baseCellNumber , List <Integer > digits ) {
151+ return h3ToString (constructCell (baseCellNumber , digits , digits .size ()));
152+ }
153+
154+ /** Construct a cell index from component parts */
155+ public String constructCellAddress (int baseCellNumber , List <Integer > digits , int res ) {
156+ return h3ToString (constructCell (baseCellNumber , digits , res ));
157+ }
158+
116159 /** Returns the base cell number for this index. */
117160 public int getBaseCellNumber (long h3 ) {
118161 return h3Api .getBaseCellNumber (h3 );
@@ -727,11 +770,37 @@ public int getResolution(String h3Address) {
727770 return getResolution (stringToH3 (h3Address ));
728771 }
729772
730- /** Returns the resolution of the provided index */
773+ /** Returns the resolution of the provided index. */
731774 public int getResolution (long h3 ) {
732775 return (int ) ((h3 & H3_RES_MASK ) >> H3_RES_OFFSET );
733776 }
734777
778+ /**
779+ * Returns the indexing digit of the index at `res`
780+ *
781+ * @param h3 H3 index.
782+ * @param res Resolution of the digit, <code>1 <= res <= 15</code>
783+ * @throws IllegalArgumentException <code>res</code> is not between 0 and 15, inclusive.
784+ */
785+ public int getIndexDigit (String h3Address , int res ) {
786+ return getIndexDigit (stringToH3 (h3Address ), res );
787+ }
788+
789+ /**
790+ * Returns the indexing digit of the index at `res`
791+ *
792+ * @param h3 H3 index.
793+ * @param res Resolution of the digit, <code>1 <= res <= 15</code>
794+ * @throws IllegalArgumentException <code>res</code> is not between 0 and 15, inclusive.
795+ */
796+ public int getIndexDigit (long h3 , int res ) {
797+ if (res < 1 || res > 15 ) {
798+ throw new IllegalArgumentException (
799+ String .format ("resolution %d is out of range (must be 1 <= res <= 15)" , res ));
800+ }
801+ return (int ) ((h3 >> ((15 - res ) * 3 )) & 7 );
802+ }
803+
735804 /**
736805 * Returns the parent of the index at the given resolution.
737806 *
0 commit comments