1212import ai .timefold .solver .core .impl .util .ElementAwareListEntry ;
1313
1414final class ComparisonIndexer <T , Key_ extends Comparable <Key_ >>
15- implements ai . timefold . solver . core . impl . score . stream . bavet . common . index . Indexer <T > {
15+ implements Indexer <T > {
1616
1717 private final int propertyIndex ;
18- private final Supplier <ai . timefold . solver . core . impl . score . stream . bavet . common . index . Indexer <T >> downstreamIndexerSupplier ;
18+ private final Supplier <Indexer <T >> downstreamIndexerSupplier ;
1919 private final Comparator <Key_ > keyComparator ;
2020 private final boolean hasOrEquals ;
21- private final NavigableMap <Key_ , ai . timefold . solver . core . impl . score . stream . bavet . common . index . Indexer <T >> comparisonMap ;
21+ private final NavigableMap <Key_ , Indexer <T >> comparisonMap ;
2222
23- public ComparisonIndexer (JoinerType comparisonJoinerType ,
24- Supplier <ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T >> downstreamIndexerSupplier ) {
23+ public ComparisonIndexer (JoinerType comparisonJoinerType , Supplier <Indexer <T >> downstreamIndexerSupplier ) {
2524 this (comparisonJoinerType , 0 , downstreamIndexerSupplier );
2625 }
2726
2827 public ComparisonIndexer (JoinerType comparisonJoinerType , int propertyIndex ,
29- Supplier <ai . timefold . solver . core . impl . score . stream . bavet . common . index . Indexer <T >> downstreamIndexerSupplier ) {
28+ Supplier <Indexer <T >> downstreamIndexerSupplier ) {
3029 this .propertyIndex = propertyIndex ;
3130 this .downstreamIndexerSupplier = Objects .requireNonNull (downstreamIndexerSupplier );
3231 /*
@@ -44,11 +43,10 @@ public ComparisonIndexer(JoinerType comparisonJoinerType, int propertyIndex,
4443 }
4544
4645 @ Override
47- public ElementAwareListEntry <T >
48- put (ai .timefold .solver .core .impl .score .stream .bavet .common .index .IndexProperties indexProperties , T tuple ) {
46+ public ElementAwareListEntry <T > put (IndexProperties indexProperties , T tuple ) {
4947 Key_ indexKey = indexProperties .toKey (propertyIndex );
5048 // Avoids computeIfAbsent in order to not create lambdas on the hot path.
51- ai . timefold . solver . core . impl . score . stream . bavet . common . index . Indexer < T > downstreamIndexer = comparisonMap .get (indexKey );
49+ var downstreamIndexer = comparisonMap .get (indexKey );
5250 if (downstreamIndexer == null ) {
5351 downstreamIndexer = downstreamIndexerSupplier .get ();
5452 comparisonMap .put (indexKey , downstreamIndexer );
@@ -57,22 +55,17 @@ public ComparisonIndexer(JoinerType comparisonJoinerType, int propertyIndex,
5755 }
5856
5957 @ Override
60- public void remove (ai .timefold .solver .core .impl .score .stream .bavet .common .index .IndexProperties indexProperties ,
61- ElementAwareListEntry <T > entry ) {
58+ public void remove (IndexProperties indexProperties , ElementAwareListEntry <T > entry ) {
6259 Key_ indexKey = indexProperties .toKey (propertyIndex );
63- ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T > downstreamIndexer =
64- getDownstreamIndexer (indexProperties , indexKey , entry );
60+ var downstreamIndexer = getDownstreamIndexer (indexProperties , indexKey , entry );
6561 downstreamIndexer .remove (indexProperties , entry );
6662 if (downstreamIndexer .isEmpty ()) {
6763 comparisonMap .remove (indexKey );
6864 }
6965 }
7066
71- private ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T > getDownstreamIndexer (
72- ai .timefold .solver .core .impl .score .stream .bavet .common .index .IndexProperties indexProperties , Key_ indexerKey ,
73- ElementAwareListEntry <T > entry ) {
74- ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T > downstreamIndexer =
75- comparisonMap .get (indexerKey );
67+ private Indexer <T > getDownstreamIndexer (IndexProperties indexProperties , Key_ indexerKey , ElementAwareListEntry <T > entry ) {
68+ var downstreamIndexer = comparisonMap .get (indexerKey );
7669 if (downstreamIndexer == null ) {
7770 throw new IllegalStateException ("Impossible state: the tuple (" + entry .getElement ()
7871 + ") with indexProperties (" + indexProperties
@@ -83,16 +76,15 @@ private ai.timefold.solver.core.impl.score.stream.bavet.common.index.Indexer<T>
8376
8477 // TODO clean up DRY
8578 @ Override
86- public int size (ai . timefold . solver . core . impl . score . stream . bavet . common . index . IndexProperties indexProperties ) {
87- int mapSize = comparisonMap .size ();
79+ public int size (IndexProperties indexProperties ) {
80+ var mapSize = comparisonMap .size ();
8881 if (mapSize == 0 ) {
8982 return 0 ;
9083 }
9184 Key_ indexKey = indexProperties .toKey (propertyIndex );
9285 if (mapSize == 1 ) { // Avoid creation of the entry set and iterator.
93- Map .Entry <Key_ , ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T >> entry =
94- comparisonMap .firstEntry ();
95- int comparison = keyComparator .compare (entry .getKey (), indexKey );
86+ var entry = comparisonMap .firstEntry ();
87+ var comparison = keyComparator .compare (entry .getKey (), indexKey );
9688 if (comparison >= 0 ) { // Possibility of reaching the boundary condition.
9789 if (comparison > 0 || !hasOrEquals ) {
9890 // Boundary condition reached when we're out of bounds entirely, or when GTE/LTE is not allowed.
@@ -101,10 +93,9 @@ public int size(ai.timefold.solver.core.impl.score.stream.bavet.common.index.Ind
10193 }
10294 return entry .getValue ().size (indexProperties );
10395 } else {
104- int size = 0 ;
105- for (Map .Entry <Key_ , ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T >> entry : comparisonMap
106- .entrySet ()) {
107- int comparison = keyComparator .compare (entry .getKey (), indexKey );
96+ var size = 0 ;
97+ for (var entry : comparisonMap .entrySet ()) {
98+ var comparison = keyComparator .compare (entry .getKey (), indexKey );
10899 if (comparison >= 0 ) { // Possibility of reaching the boundary condition.
109100 if (comparison > 0 || !hasOrEquals ) {
110101 // Boundary condition reached when we're out of bounds entirely, or when GTE/LTE is not allowed.
@@ -119,33 +110,29 @@ public int size(ai.timefold.solver.core.impl.score.stream.bavet.common.index.Ind
119110 }
120111
121112 @ Override
122- public void forEach (ai .timefold .solver .core .impl .score .stream .bavet .common .index .IndexProperties indexProperties ,
123- Consumer <T > tupleConsumer ) {
124- int size = comparisonMap .size ();
113+ public void forEach (IndexProperties indexProperties , Consumer <T > tupleConsumer ) {
114+ var size = comparisonMap .size ();
125115 if (size == 0 ) {
126116 return ;
127117 }
128118 Key_ indexKey = indexProperties .toKey (propertyIndex );
129119 if (size == 1 ) { // Avoid creation of the entry set and iterator.
130- Map .Entry <Key_ , ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T >> entry =
131- comparisonMap .firstEntry ();
120+ var entry = comparisonMap .firstEntry ();
132121 visitEntry (indexProperties , tupleConsumer , indexKey , entry );
133122 } else {
134- for (Map .Entry <Key_ , ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T >> entry : comparisonMap
135- .entrySet ()) {
136- boolean boundaryReached = visitEntry (indexProperties , tupleConsumer , indexKey , entry );
123+ for (var entry : comparisonMap .entrySet ()) {
124+ var boundaryReached = visitEntry (indexProperties , tupleConsumer , indexKey , entry );
137125 if (boundaryReached ) {
138126 return ;
139127 }
140128 }
141129 }
142130 }
143131
144- private boolean visitEntry (ai .timefold .solver .core .impl .score .stream .bavet .common .index .IndexProperties indexProperties ,
145- Consumer <T > tupleConsumer ,
146- Key_ indexKey , Map .Entry <Key_ , ai .timefold .solver .core .impl .score .stream .bavet .common .index .Indexer <T >> entry ) {
132+ private boolean visitEntry (IndexProperties indexProperties , Consumer <T > tupleConsumer , Key_ indexKey ,
133+ Map .Entry <Key_ , Indexer <T >> entry ) {
147134 // Comparator matches the order of iteration of the map, so the boundary is always found from the bottom up.
148- int comparison = keyComparator .compare (entry .getKey (), indexKey );
135+ var comparison = keyComparator .compare (entry .getKey (), indexKey );
149136 if (comparison >= 0 ) { // Possibility of reaching the boundary condition.
150137 if (comparison > 0 || !hasOrEquals ) {
151138 // Boundary condition reached when we're out of bounds entirely, or when GTE/LTE is not allowed.
0 commit comments