public static HierarchicalNumericIndexStrategy findHierarchicalStrategy( final NumericIndexStrategy indexStrategy, final List<CompoundIndexStrategy> parentStrategies) { if (indexStrategy instanceof HierarchicalNumericIndexStrategy) { return (HierarchicalNumericIndexStrategy) indexStrategy; } if (indexStrategy instanceof CompoundIndexStrategy) { final PartitionIndexStrategy<MultiDimensionalNumericData, MultiDimensionalNumericData> primaryIndex = ((CompoundIndexStrategy) indexStrategy).getPrimarySubStrategy(); final NumericIndexStrategy secondaryIndex = ((CompoundIndexStrategy) indexStrategy).getSecondarySubStrategy(); // warn if round robin is used if (primaryIndex instanceof RoundRobinKeyIndexStrategy) { LOGGER.warn("Round Robin partitioning won't work correctly with raster merge strategies"); } else if (secondaryIndex instanceof RoundRobinKeyIndexStrategy) { LOGGER.warn("Round Robin partitioning won't work correctly with raster merge strategies"); } final HierarchicalNumericIndexStrategy secondary = findHierarchicalStrategy(secondaryIndex); if (secondary != null) { // add it to beginning because we are recursing back from the // leaf strategy up to the parent parentStrategies.add(0, (CompoundIndexStrategy) indexStrategy); return secondary; } } return null; }
@Override public SubStrategy[] getSubStrategies() { // for these substrategies we need to replace the last parent strategy's // hierarchical index strategy with the underlying substrategy index // strategy final SubStrategy[] subStrategies = firstHierarchicalStrategy.getSubStrategies(); final SubStrategy[] retVal = new SubStrategy[subStrategies.length]; for (int i = 0; i < subStrategies.length; i++) { NumericIndexStrategy currentStrategyToBeReplaced = firstHierarchicalStrategy; NumericIndexStrategy currentStrategyReplacement = subStrategies[i].getIndexStrategy(); for (int j = parentStrategies.size() - 1; j >= 0; j--) { // traverse parents in reverse order final CompoundIndexStrategy parent = parentStrategies.get(j); if (parent.getPrimarySubStrategy().equals(currentStrategyToBeReplaced)) { // replace primary currentStrategyReplacement = new CompoundIndexStrategy( currentStrategyReplacement, parent.getSecondarySubStrategy()); } else { // replace secondary currentStrategyReplacement = new CompoundIndexStrategy(parent.getPrimarySubStrategy(), currentStrategyReplacement); } currentStrategyToBeReplaced = parent; } retVal[i] = new SubStrategy(currentStrategyReplacement, subStrategies[i].getPrefix()); } return retVal; }