Example usage for java.util Arrays sort

List of usage examples for java.util Arrays sort

Introduction

In this page you can find the example usage for java.util Arrays sort.

Prototype

public static void sort(Object[] a) 

Source Link

Document

Sorts the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

Usage

From source file:Main.java

public static String collectStats(CharSequence flattenedParams) {
    StringBuilder result = new StringBuilder(1000);

    result.append("BOARD=").append(Build.BOARD).append('\n');
    result.append("BRAND=").append(Build.BRAND).append('\n');
    result.append("CPU_ABI=").append(Build.CPU_ABI).append('\n');
    result.append("DEVICE=").append(Build.DEVICE).append('\n');
    result.append("DISPLAY=").append(Build.DISPLAY).append('\n');
    result.append("FINGERPRINT=").append(Build.FINGERPRINT).append('\n');
    result.append("HOST=").append(Build.HOST).append('\n');
    result.append("ID=").append(Build.ID).append('\n');
    result.append("MANUFACTURER=").append(Build.MANUFACTURER).append('\n');
    result.append("MODEL=").append(Build.MODEL).append('\n');
    result.append("PRODUCT=").append(Build.PRODUCT).append('\n');
    result.append("TAGS=").append(Build.TAGS).append('\n');
    result.append("TIME=").append(Build.TIME).append('\n');
    result.append("TYPE=").append(Build.TYPE).append('\n');
    result.append("USER=").append(Build.USER).append('\n');
    result.append("VERSION.CODENAME=").append(Build.VERSION.CODENAME).append('\n');
    result.append("VERSION.INCREMENTAL=").append(Build.VERSION.INCREMENTAL).append('\n');
    result.append("VERSION.RELEASE=").append(Build.VERSION.RELEASE).append('\n');
    result.append("VERSION.SDK_INT=").append(Build.VERSION.SDK_INT).append('\n');

    if (flattenedParams != null) {
        String[] params = SEMICOLON.split(flattenedParams);
        Arrays.sort(params);
        for (String param : params) {
            result.append(param).append('\n');
        }/*from  w  ww . j a  va  2s  .  c om*/
    }

    return result.toString();
}

From source file:br.com.Summoner.core.base.cartas.monk.MonkCard.java

@Override
public long CalculaBonus(Jogada jogada, List<Card> listaMonstrosAdversarios) {
    List<Card> cartasUtilizadasCombo = jogada.CartasUtilizadas.stream()
            .filter(carta -> carta.TipoCarta == TipoCarta.Item && carta.TipoMonstro == TipoMonstro.Monk)
            .collect(Collectors.toList());
    MonkComboResult comboResult = new MonkComboResult();
    long forcaBonus = 0;

    if (cartasUtilizadasCombo.size() > 0) {
        String[] golpesCombo = cartasUtilizadasCombo
                .stream().map(carta -> ((MonkItemCard) carta).Golpes.stream()
                        .map(golpe -> golpe.tipoGolpe.toString()).collect(Collectors.joining()))
                .collect(Collectors.joining()).split("");
        Arrays.sort(golpesCombo);
        String comboRealizado = StringUtils.join(Arrays.asList(golpesCombo), "");
        comboResult.ComboRealizado = comboRealizado;
        //          comboResult.CombosCarta.addAll(this.Combos);

        for (int i = 0; i < this.Combos.size(); i++) {
            MonkMonsterCombo combo = this.Combos.get(i);

            char[] criaturaCombo = combo.CombinacaoCombo.toCharArray();
            Arrays.sort(criaturaCombo);
            String comboDaCriatura = new String(criaturaCombo);

            boolean encontrou = comboRealizado.contains(comboDaCriatura);

            if (encontrou && forcaBonus < combo.DanoCombo) {

                forcaBonus = combo.DanoCombo;
                comboResult.ValorComboRealizado = forcaBonus;
                comboResult.ComboCriatura = comboDaCriatura;

            }/*from w  w  w .  j a v a 2 s . c o m*/
        }

        CombosRealizados.add(comboResult);
    }

    return forcaBonus;
}

From source file:com.alibaba.sample.petstore.dal.dao.CategoryDaoTests.java

private void assertCategoryList(List<Category> cats, String... ids) {
    String[] result = new String[cats.size()];

    int i = 0;//from w w  w. j  a  v  a2 s. co  m
    for (Category cat : cats) {
        result[i++] = cat.getCategoryId();
    }

    Arrays.sort(result);
    Arrays.sort(ids);

    assertArrayEquals(ids, result);
}

From source file:io.warp10.continuum.gts.GTSOutliersHelper.java

protected static double median(GeoTimeSerie gts) {
    // FIXME(JCV): if size of gts too big, we should better work inplace by making a quickSortByValue and sort by ticks after
    double[] copy = Arrays.copyOf(gts.doubleValues, gts.values);
    Arrays.sort(copy);

    return gts.values % 2 == 0 ? (copy[gts.values / 2] + copy[gts.values / 2 - 1]) / 2 : copy[gts.values / 2];
}

From source file:gedi.util.math.stat.distributions.PoissonBinomial.java

/**
 * for n>2000//from ww  w  .  j  ava  2 s.c o  m
 * @param useApprox
 */
public PoissonBinomial(double[] pp) {
    this.pp = pp.clone();
    Arrays.sort(this.pp);
    double mu = ArrayUtils.sum(pp);
    double sigma = 0;
    for (double p : pp)
        sigma += p * (1 - p);
    sigma = Math.sqrt(sigma);
    normalApprox = new Normal(mu, sigma);
    if (pp.length <= 2000)
        preprocess();
}

From source file:com.opengamma.strata.math.impl.statistics.descriptive.PercentileCalculatorTest.java

@Test
public void testExtremes() {
    final double[] y = Arrays.copyOf(X, X.length);
    Arrays.sort(y);
    CALCULATOR.setPercentile(1e-15);/*from w w  w  .j  a v a2 s. c o  m*/
    assertEquals(CALCULATOR.apply(X), y[0], 0);
    CALCULATOR.setPercentile(1 - 1e-15);
    assertEquals(CALCULATOR.apply(X), y[N - 1], 0);
}

From source file:de.uzk.hki.da.utils.FolderUtils.java

/**
 * Compares two folders for equality. Compares the folderstructure and the
 * compares the bitwise equality of the included files.
 *
 * @param lhs/*from  w w w.  j  av a2 s .c o m*/
 *            relative path to the first folder
 * @param rhs
 *            relative path to the second folder
 * @return true if lhs equals rhs
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static boolean compareFolders(File lhs, File rhs) throws IOException {

    String rhsParentPath = rhs.getAbsolutePath();
    String lhsParentPath = lhs.getAbsolutePath();

    String lhsChildren[] = lhs.list();
    String rhsChildren[] = rhs.list();

    // Sometimes the order of the listings are not equal even though the
    // files contained are
    Arrays.sort(lhsChildren);
    Arrays.sort(rhsChildren);

    boolean filesAreEqual = true;
    for (int i = 0; i < lhsChildren.length; i++) {

        File lhsf = new File(lhsParentPath + "/" + lhsChildren[i]);
        File rhsf = new File(rhsParentPath + "/" + rhsChildren[i]);

        if (lhsf.isFile()) {

            if (!FileUtils.contentEquals(lhsf, rhsf))
                filesAreEqual = false;
        }

        if (lhsf.isDirectory()) {
            if (!compareFolders(lhsf, rhsf))
                filesAreEqual = false;
        }
    }
    return filesAreEqual;
}

From source file:com.opengamma.analytics.math.FunctionUtils.java

/**
 * Same behaviour as mathlab unique//from w  ww  . java2s  .  c o  m
 * @param in input array
 * @return a sorted array with no duplicates values
 */
public static int[] unique(final int[] in) {
    Arrays.sort(in);
    final int n = in.length;
    final int[] temp = new int[n];
    temp[0] = in[0];
    int count = 1;
    for (int i = 1; i < n; i++) {
        if (in[i] != in[i - 1]) {
            temp[count++] = in[i];
        }
    }
    if (count == n) {
        return temp;
    }
    return Arrays.copyOf(in, count);
}

From source file:com.github.opensensingcity.lindt.api.ListExamples.java

@GET
public Response doGet() throws IOException, URISyntaxException {
    LOG.info("Loading list of examples");
    File examples = new File(ListExamples.class.getClassLoader().getResource("examples").toURI());

    StringBuilder sb = new StringBuilder();
    File[] files = examples.listFiles();
    Arrays.sort(files);
    for (File example : files) {
        if (example.isDirectory()) {
            sb.append(example.getName() + "\n");
        }/* w w w .j  a v a  2  s .co  m*/
    }

    Response.ResponseBuilder res = Response.ok(sb.toString(), "text/plain");
    return res.build();

}

From source file:com.linkedin.pinot.common.client.request.filter.TermsFilterQueryTreeConstructor.java

@Override
protected FilterQueryTree doConstructFilter(Object obj) throws Exception {
    final JSONObject json = (JSONObject) obj;

    final Iterator<String> iter = json.keys();
    if (!iter.hasNext()) {
        return null;
    }//from  ww w . ja v  a2 s.c  o m

    final String field = iter.next();

    final JSONObject jsonObj = json.getJSONObject(field);

    final String[] includes = RequestConverter.getStrings(jsonObj.getJSONArray("values"));
    final String[] excludes = RequestConverter.getStrings(jsonObj.getJSONArray("excludes"));

    if (includes.length > 0) {
        Arrays.sort(includes);
        final List<String> rhs = new ArrayList<String>();
        rhs.add(StringUtils.join(includes, "\t\t"));
        return new FilterQueryTree(field, rhs, FilterOperator.IN, null);
    } else {
        Arrays.sort(excludes);
        final List<String> rhs = new ArrayList<String>();
        rhs.add(StringUtils.join(excludes, "\t\t"));
        if (excludes.length == 1) {
            return new FilterQueryTree(field, rhs, FilterOperator.NOT, null);
        } else {
            return new FilterQueryTree(field, rhs, FilterOperator.NOT_IN, null);
        }
    }
}