/** * Returns a summary statistics object for the given attribute * * @param generalization * @param dataType * @param baseDataType * @param hierarchy * @return */ private <U, V> StatisticsSummaryOrdinal getSummaryStatisticsOrdinal( final int generalization, final DataType<U> dataType, final DataType<V> baseDataType, final Hierarchy hierarchy) { // TODO: It would be cleaner to return an ARXOrderedString for generalized variables // TODO: that have a suitable data type directly from the DataHandle if (generalization == 0 || !(dataType instanceof ARXString)) { return new StatisticsSummaryOrdinal(dataType); } else if (baseDataType instanceof ARXString) { return new StatisticsSummaryOrdinal(dataType); } else if (hierarchy == null) { return new StatisticsSummaryOrdinal(dataType); } else { final String[][] array = hierarchy.getHierarchy(); final Map<String, String> map = new HashMap<String, String>(); for (int i = 0; i < array.length; i++) { map.put(array[i][generalization], array[i][0]); } return new StatisticsSummaryOrdinal( new Comparator<String>() { public int compare(String o1, String o2) { V _o1 = null; try { _o1 = baseDataType.parse(map.get(o1)); } catch (Exception e) { // Nothing to do } V _o2 = null; try { _o2 = baseDataType.parse(map.get(o2)); } catch (Exception e) { // Nothing to do } try { return baseDataType.compare(_o1, _o2); } catch (Exception e) { return 0; } } }); } }
/** * Returns an ordered list of the distinct set of data items from the given column. This method * assumes that the order of string data items can (and should) be derived from the provided * hierarchy * * @param column The column * @param hierarchy The hierarchy, may be null * @return */ public String[] getDistinctValuesOrdered(int column, Hierarchy hierarchy) { // Reset stop flag interrupt = false; // Obtain list and data type final String[] list = getDistinctValues(column); final String attribute = handle.getAttributeName(column); final DataType<?> datatype = handle.getDataType(attribute); final int level = handle.getGeneralization(attribute); final String[][] _hierarchy = hierarchy != null ? hierarchy.getHierarchy() : null; // Sort by data type if (_hierarchy == null || level == 0) { sort(list, datatype, handle.getSuppressionString()); // Sort by hierarchy and data type } else { // Build order directly from the hierarchy final Map<String, Integer> order = new HashMap<String, Integer>(); int max = 0; // The order to use for the suppression string // Create base order Set<String> baseSet = new HashSet<String>(); DataType<?> baseType = handle.getBaseDataType(attribute); for (int i = 0; i < _hierarchy.length; i++) { String element = _hierarchy[i][0]; checkInterrupt(); // Make sure that only elements from the hierarchy // are added that are included in the data // TODO: Calling isValid is only a work-around if (baseType.isValid(element)) baseSet.add(element); } String[] baseArray = baseSet.toArray(new String[baseSet.size()]); sort(baseArray, handle.getBaseDataType(attribute), handle.getSuppressionString()); Map<String, Integer> baseOrder = new HashMap<String, Integer>(); for (int i = 0; i < baseArray.length; i++) { checkInterrupt(); baseOrder.put(baseArray[i], i); } // Build higher level order from base order for (int i = 0; i < _hierarchy.length; i++) { checkInterrupt(); if (!order.containsKey(_hierarchy[i][level])) { Integer position = baseOrder.get(_hierarchy[i][0]); if (position != null) { order.put(_hierarchy[i][level], position); max = Math.max(position, max) + 1; } } } // Add suppression string String supp = handle.getSuppressionString(); if (supp != null) order.put(supp, max); // Sort sort(list, order); } // Done return list; }