<commit_before>package com.dslplatform.client;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

class Utils {
    public static <T> ArrayList<T> toArrayList(final Iterable<T> iterable) {
        final ArrayList<T> copy = new ArrayList<T>();
        for(final T t: iterable) copy.add(t);
        return copy;
    }

    private static void appendOrder(
            final StringBuilder sb,
            final Iterable<Map.Entry<String, Boolean>> order) {
        if (order != null && order.iterator().hasNext()) {
            if(sb.length() > 0)
                sb.append("&");
            else
                sb.append("?");
            sb.append("order=");
            for(final Map.Entry<String, Boolean> el: order) {
                // null Boolean object will default to true
                if(el.getValue() == Boolean.FALSE) {
                    sb.append('-');
                }
                sb.append(el.getKey()).append(',');
            }
            sb.setLength(sb.length() - 1);
        }
    }

    public static String appendLimitOffsetOrder(
            final String url,
            final Integer limit,
            final Integer offset,
            final Iterable<Map.Entry<String, Boolean>> order,
            final Boolean isFirst) {
        final StringBuilder sB = new StringBuilder(url);

        if(limit != null)
            sB.append( isFirst ? '?' : '&').append("limit=").append(limit);
        if(offset != null)
            sB.append((limit == null && isFirst) ? "?offset=" : "&offset=").append(offset);
        appendOrder(sB, order);

        return sB.toString();
    }

    public static void joinIfNonEmpty(
            final StringBuilder sB,
            final String param,
            final Iterable<String> args) {
        if (args == null) return;

        final Iterator<String> aI = args.iterator();
        if (!aI.hasNext()) return;

        sB.append(param).append(aI.next());
        while (aI.hasNext()) sB.append(',').append(aI.next());
    }

    public static String buildOlapArguments(
            final Iterable<String> dimensions,
            final Iterable<String> facts,
            final Iterable<Map.Entry<String, Boolean>> order) {
        final StringBuilder query = new StringBuilder();

        if (order != null && order.iterator().hasNext()
            && !contains(dimensions, order)
            && !contains(facts, order)) throw new IllegalArgumentException("Order must be an element of dimmensions or facts!");
        joinIfNonEmpty(query, "?dimensions=", dimensions);
        joinIfNonEmpty(query, query.length() > 0 ? "&facts=" : "?facts=", facts);

        if (query.length() == 0)
            throw new IllegalArgumentException("At least one dimension or fact is required");

        appendOrder(query, order);

        return query.toString();
    }

    private static Boolean contains(final Iterable<String> iterSource, final Iterable<Map.Entry<String, Boolean>> orders) {
      if (iterSource == null) return false;
      for(final Map.Entry<String, Boolean> ord: orders) {
        if (! contains(iterSource, ord.getKey())) return false;
      }
      return true;
    }

    private static Boolean contains(final Iterable<String> iterSource, final String orders){
      for(final String src: iterSource){
        if (orders.equals(src)) return true;
      }
      return false;
    }
}
<commit_msg>Fixed order paremeter always starting with &.<commit_after>package com.dslplatform.client;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

class Utils {
    public static <T> ArrayList<T> toArrayList(final Iterable<T> iterable) {
        final ArrayList<T> copy = new ArrayList<T>();
        for(final T t: iterable) copy.add(t);
        return copy;
    }

    private static void appendOrder(
            final StringBuilder sb,
            final Iterable<Map.Entry<String, Boolean>> order,
            final boolean isFirst) {
        if (order != null && order.iterator().hasNext()) {
            sb.append((isFirst) ? "?" : "&");
            sb.append("order=");
            for(final Map.Entry<String, Boolean> el: order) {
                // null Boolean object will default to true
                if(el.getValue() == Boolean.FALSE) {
                    sb.append('-');
                }
                sb.append(el.getKey()).append(',');
            }
            sb.setLength(sb.length() - 1);
        }
    }

    public static String appendLimitOffsetOrder(
            final String url,
            final Integer limit,
            final Integer offset,
            final Iterable<Map.Entry<String, Boolean>> order,
            final Boolean isFirst) {
        final StringBuilder sB = new StringBuilder(url);
        final boolean limitnull = limit == null;
        final boolean offsetnull = offset == null;
        final boolean orderFirst = limitnull && offsetnull && isFirst;

        if(! limitnull)
            sB.append( isFirst ? '?' : '&').append("limit=").append(limit);
        if(! offsetnull)
            sB.append((limitnull && isFirst) ? "?offset=" : "&offset=").append(offset);
        appendOrder(sB, order, orderFirst);

        return sB.toString();
    }

    public static void joinIfNonEmpty(
            final StringBuilder sB,
            final String param,
            final Iterable<String> args) {
        if (args == null) return;

        final Iterator<String> aI = args.iterator();
        if (!aI.hasNext()) return;

        sB.append(param).append(aI.next());
        while (aI.hasNext()) sB.append(',').append(aI.next());
    }

    public static String buildOlapArguments(
            final Iterable<String> dimensions,
            final Iterable<String> facts,
            final Iterable<Map.Entry<String, Boolean>> order) {
        final StringBuilder query = new StringBuilder();

        if (order != null && order.iterator().hasNext()
            && !contains(dimensions, order)
            && !contains(facts, order)) throw new IllegalArgumentException("Order must be an element of dimmensions or facts!");
        joinIfNonEmpty(query, "?dimensions=", dimensions);
        joinIfNonEmpty(query, query.length() > 0 ? "&facts=" : "?facts=", facts);

        if (query.length() == 0)
            throw new IllegalArgumentException("At least one dimension or fact is required");

        appendOrder(query, order, false);

        return query.toString();
    }

    private static Boolean contains(final Iterable<String> iterSource, final Iterable<Map.Entry<String, Boolean>> orders) {
      if (iterSource == null) return false;
      for(final Map.Entry<String, Boolean> ord: orders) {
        if (! contains(iterSource, ord.getKey())) return false;
      }
      return true;
    }

    private static Boolean contains(final Iterable<String> iterSource, final String orders){
      for(final String src: iterSource){
        if (orders.equals(src)) return true;
      }
      return false;
    }
}

{'fraction_non_alphanumeric': 0.1248212753788962, 'fraction_numerical': 0.0010008578781812983, 'mean_word_length': 2.2489549465861587, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 48, 'https://': 0, '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': '4821407', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1840, 'n_words': 516}