• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.timezone.location.storage.table.reader;
18 
19 /**
20  * A type for tables where the value can be expressed as a Java int; i.e. not long, but perhaps
21  * where the value is actually smaller than int.
22  */
23 public interface IntValueTable extends Table<IntValueTable.TableEntry> {
24 
25     /**
26      * Finds an entry using the supplied matcher via a binary search. If multiple entries match, an
27      * arbitrary matching entry is returned. Returns {@code null} if no entries match.
28      */
findEntry(IntValueEntryMatcher matcher)29     TableEntry findEntry(IntValueEntryMatcher matcher);
30 
31     /**
32      * A type for entries in {@link IntValueTable}.
33      */
34     interface TableEntry extends Table.TableEntry<TableEntry> {
35 
36         /**
37          * Returns the entry's value.
38          */
getValue()39         int getValue();
40 
41         /**
42          * Finds an entry using the supplied matcher via a binary search. If multiple entries match,
43          * an arbitrary matching entry is returned. Returns {@code null} if no entry matches.
44          * Like {@link IntValueTable#findEntry(IntValueEntryMatcher)} but uses this entry as a
45          * starting point.
46          */
findNearbyEntry(IntValueEntryMatcher matcher)47         TableEntry findNearbyEntry(IntValueEntryMatcher matcher);
48 
49         /** A helper method for implementing {@link TableEntry#equals(Object)}. */
equal(TableEntry one, Object two)50         static boolean equal(TableEntry one, Object two) {
51             if (one == null && two == null) {
52                 return true;
53             }
54             if (!(two instanceof TableEntry) || one == null || one.getClass() != two.getClass()) {
55                 return false;
56             }
57             TableEntry other = (TableEntry) two;
58             return (one.getKey() == other.getKey() && one.getValue() == other.getValue());
59         }
60 
61         /** A helper method for implementing {@link TableEntry#toString()}. */
toString(TableEntry entry)62         static String toString(TableEntry entry) {
63             return "TableEntry{key=" + entry.getKey() + ", value=" + entry.getValue() + "}";
64         }
65     }
66 
67     /**
68      * A matcher that can be used with {@link IntValueTable}s to find entries in the table.
69      */
70     interface IntValueEntryMatcher {
71 
72         /**
73          * Returns &lt; 0 if the entry sought is lower than one with the values provided, &gt; 0
74          * if the entry sought is higher than one with the values provided, and exactly zero if it
75          * is the entry sought.
76          */
compare(int key, int value)77         int compare(int key, int value);
78     }
79 }
80