0

I have following code in java which is causing error in sonar.

The code is as :

 private Table sliceTable(Table table, String[] columns, Map<DependencyKey, List<F>> reportFields) {
    TableSliceGroup tableSlices = table.splitOn(columns);
    ListMultimap map = ArrayListMultimap.create();
    reportFields
            .entrySet()
            .stream()
            .filter(entry -> !entry.getKey().getDependencyType().equals(ReportingDependency.SELF) ||
                    !entry.getKey().getDependencyType().equals(ReportingDependency.SELF_WITH_CHECKPOINT))
            .flatMap(entry -> entry.getValue().stream().map(it -> Pair.of(entry.getKey().getDependencyType(), it)))
            .flatMap(pair -> pair.getRight().getDependencyDefinitions().stream().map(depDef -> Triple.of(pair.getLeft(), pair.getRight(), depDef)))
            .filter(triple -> triple.getRight().getClientName().equals(triple.getLeft()))
            .flatMap(triple -> triple.getRight().getFields().stream().map(it -> Triple.of(triple.getMiddle(), triple.getRight(), it)))
            .filter(triple -> TableUtils.containsColumn(table, triple.getMiddle().getClientName(),
                    triple.getRight()))     // This filters out the unresolved columns
            .forEach(triple -> {
                List<AggregateFunction<?, ?>> aggFuncList = map.get(TableUtils.getColumnNameFromTable(table,
                        triple.getMiddle().getClientName(), triple.getRight()));
                if (!aggFuncList.contains(
                        TableUtils.getAggregationFunction(
                                TableUtils.getColumnFromTable(table,
                                        triple.getMiddle().getClientName(),
                                        triple.getRight()).type(),
                                triple.getRight().getAggregation()))) {
                    map.put(TableUtils.getColumnNameFromTable(table, triple.getMiddle().getClientName(),
                            triple.getRight()),
                            TableUtils.getAggregationFunction(
                                    TableUtils.getColumnFromTable(table,
                                            triple.getMiddle().getClientName(),
                                            triple.getRight()).type(),
                                    triple.getRight().getAggregation()));
                }
            });

    Table slicedTable = TableSummarizer.aggregate(tableSlices, map, columns);
    return slicedTable;
}

sonar is giving error in this as on following line:

 if (!aggFuncList.contains(
                        TableUtils.getAggregationFunction(

A "List<AggregateFunction>" cannot contain a "SummarizingFunction".

can anyone please suggest whats missing in wrong here .

public abstract class SummarizingFunction<INCOL extends Column<?>, OUT>  {

private final String functionName;

/** Constructs a function with the given name */
public SummarizingFunction(String functionName) {
    this.functionName = functionName;
}

/** Returns this function's name */
public String functionName() {
    return functionName;
}

/** Apply this function to the column argument */
public abstract OUT summarize(INCOL column, int[] indices);

public String toString() {
    return functionName();
}

/** Returns the {@link ColumnType} to be used for the values returned by this function */
public abstract ColumnType returnType();

}

Thanks

Scientist
  • 1,458
  • 2
  • 15
  • 31
  • 2
    A [mcve] would be helpful – Robert Mar 17 '23 at 16:56
  • There could be a possibility that the result of method in contains returns something other than the AggregateFunction class hierarchy. Can you tell what is the relation between AggregateFunction and SummarizingFunction classes?? – Viki Jain Mar 17 '23 at 17:00
  • It's complaining that `aggFuncList` can't possibly contain what is returned from `getAggregationFunction()`. What are the definitions of `AggregateFunction` and `SummarizingFunction`? – Bohemian Mar 17 '23 at 22:10
  • @bohemian both of them are of table saw library – Scientist Mar 18 '23 at 10:36
  • @bohemian both of them are of table saw library https://github.com/jtablesaw/tablesaw/blob/master/core/src/main/java/tech/tablesaw/aggregate/AggregateFunction.java SummarizingFunction is a custom class made in which i will attach in above – Scientist Mar 18 '23 at 10:44
  • You need to make `SummarizingFunction` extend `AggregateFunction` – Bohemian Mar 18 '23 at 20:20

0 Answers0