<commit_before>package charts.builder;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import charts.spreadsheet.DataSource;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

public class ChartBuilder {

    private static List<ChartTypeBuilder> BUILDERS = new ImmutableList.Builder<ChartTypeBuilder>()
            .add(new MarineSpreadsheetChartBuilder())
            .add(new CotsOutbreakSpreadsheetBuilder())
            .add(new AnnualRainfallChartBuilder())
            .build();

    private List<DataSource> datasources;

    public ChartBuilder() {
    }

    public ChartBuilder(List<DataSource> datasources) {
        this.datasources = datasources;
    }

    public List<Chart> getCharts(ChartType type, Map<String, String[]> query) {
        List<Chart> result = Lists.newArrayList();
        for(ChartTypeBuilder builder : BUILDERS) {
            if(builder.canHandle(type, datasources)) {
                result.addAll(builder.build(datasources, query));
            }
        }
        // make sure charts are sorted by region 
        // https://github.com/uq-eresearch/aorra/issues/44
        Collections.sort(result, new Comparator<Chart>() {
            @Override
            public int compare(Chart c1, Chart c2) {
                Region r1 = null;
                Region r2 = null;
                if(c1.getDescription()!=null) {
                    r1 = c1.getDescription().getRegion();
                }
                if(c2.getDescription()!=null) {
                    r2 = c2.getDescription().getRegion();
                }
                if(r1 != null) {
                    return r1.compareTo(r2);
                } else if(r2 == null){
                    return 0;
                } else {
                    return -1;
                }
            }});
        return result;
    }

    public List<Chart> getCharts(Map<String, String[]> query) {
        return getCharts(null, query);
    }

}
<commit_msg>Tinkering with ChartBuilder prior to refactor.<commit_after>package charts.builder;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import charts.spreadsheet.DataSource;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

public class ChartBuilder {

  private static List<ChartTypeBuilder> BUILDERS =
    new ImmutableList.Builder<ChartTypeBuilder>()
      .add(new MarineSpreadsheetChartBuilder())
      .add(new CotsOutbreakSpreadsheetBuilder())
      .add(new AnnualRainfallChartBuilder())
      .build();

  private final List<DataSource> datasources;

  public ChartBuilder(List<DataSource> datasources) {
    this.datasources = datasources;
  }

  public List<Chart> getCharts(ChartType type, Map<String, String[]> query) {
    final List<Chart> result = Lists.newLinkedList();
    for (final ChartTypeBuilder builder : BUILDERS) {
      if (builder.canHandle(type, datasources)) {
        result.addAll(builder.build(datasources, query));
      }
    }
    // make sure charts are sorted by region
    // https://github.com/uq-eresearch/aorra/issues/44
    Collections.sort(result, new Comparator<Chart>() {
      @Override
      public int compare(Chart c1, Chart c2) {
        if (getRegion(c1) == null) {
          if (getRegion(c2) == null)
            return 0;
          return -1;
        } else {
          return getRegion(c1).compareTo(getRegion(c2));
        }
      }
      private Region getRegion(Chart c) {
        if (c.getDescription() == null)
          return null;
        return c.getDescription().getRegion();
      }
    });
    return result;
  }

  public List<Chart> getCharts(Map<String, String[]> query) {
    return getCharts(null, query);
  }

}

{'fraction_non_alphanumeric': 0.11090766413811143, 'fraction_numerical': 0.0073240910279884905, 'mean_word_length': 2.3485113835376534, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3381324', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1073, 'n_words': 230}