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:eu.crisis_economics.abm.markets.clearing.heterogeneous.StepResponseFunction.java

/**
  * Generate a step function with discontinuities at 
  * random points in the unit interval.// w w w.j  a  v a2s.  c  o m
  */
public StepResponseFunction(final BoundedUnivariateFunction existingResponseFunction) {
    super(new SimpleDomainBounds(0., existingResponseFunction.getMaximumInDomain()));
    Random random = new Random();
    int numSteps = random.nextInt(10) + 2;
    double[] stepCoordinates = new double[numSteps];
    for (int i = 0; i < numSteps; ++i)
        stepCoordinates[i] = random.nextDouble() / existingResponseFunction.getMaximumInDomain();
    Arrays.sort(stepCoordinates);
    initCommon(existingResponseFunction, stepCoordinates);
}

From source file:eu.edisonproject.classification.prepare.controller.Text2Avro.java

@Override
public void execute() {
    File file = new File(inputFolder);
    Document davro;/*  w  w  w . java  2s.com*/
    DocumentAvroSerializer dAvroSerializer = null;
    if (file.isDirectory()) {
        File[] filesInDir = file.listFiles();
        Arrays.sort(filesInDir);
        for (File f : filesInDir) {
            if (FilenameUtils.getExtension(f.getName()).endsWith("txt")) {
                Path p = Paths.get(f.getAbsolutePath());
                BasicFileAttributes attr = null;
                try {
                    attr = Files.readAttributes(p, BasicFileAttributes.class);
                } catch (IOException ex) {
                    Logger.getLogger(Text2Avro.class.getName()).log(Level.SEVERE, null, ex);
                }
                FileTime date = attr.creationTime();

                //                    DateTimeFormatter formatter
                //                            = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
                //                    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

                //                    System.err.println(LocalDate.parse(date.toString(), formatter));
                documentObject = new DocumentObject();
                extract(this.getDocumentObject(), f.getPath());
                documentObject.setDescription(documentObject.getDescription().toLowerCase());
                clean(this.getDocumentObject().getDescription());
                if (documentObject.getDescription().equals("")) {
                    continue;
                }
                //                    documentObject.setDate(LocalDate.parse(date.toString(), formatter));
                documentObjectList.add(this.getDocumentObject());

                davro = new Document();
                davro.setDocumentId(documentObject.getDocumentId());
                davro.setTitle(documentObject.getTitle());
                davro.setDate(documentObject.getDate().toString());
                davro.setDescription(documentObject.getDescription());

                if (dAvroSerializer == null) {
                    dAvroSerializer = new DocumentAvroSerializer(
                            outputFolder + File.separator + documentObject.getTitle() + date + ".avro",
                            davro.getSchema());
                }
                dAvroSerializer.serialize(davro);
            }
        }
        if (dAvroSerializer != null) {
            dAvroSerializer.close();
            dAvroSerializer = null;
        }

    } else {
        System.out.println("NOT A DIRECTORY");
    }
}

From source file:com.rogue.regexblock.command.subcommands.HelpCommand.java

private String getPage(int page, Map<String, Object> map) {
    int factor = 5;
    int index = (page - 1) * factor;
    int listSize = map.size();
    if (index > listSize) {
        return "";
    }//  www  .j  a v a  2  s. c  om
    int upper = index + factor;
    if (upper >= listSize) {
        upper = listSize;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("&e").append(this.formatTitle(RegexBlock.getPlugin().getName(), ChatColor.YELLOW, ChatColor.RED))
            .append("\n");
    sb.append("&ePage &9").append(page).append(" &eof &9")
            .append((int) Math.ceil((double) listSize / (double) factor)).append("\n").append(ChatColor.RESET);
    String[] list = map.keySet().toArray(new String[listSize]);
    Arrays.sort(list);
    for (int i = index; i < upper; i++) {
        Object test = map.get(list[i]);
        if (test != null) {
            if (test instanceof SubCommand) {
                SubCommand db = (SubCommand) map.get(list[i]);
                sb.append("&e").append(db.getHelp()[0]).append(" &9- &f").append(db.getHelp()[1]);
            }
            if (i != upper - 1) {
                sb.append("\n");
            }
        }
    }
    sb.append('\n').append("&eUse &9/regexblock <command> help &efor help with a command");
    return sb.toString();
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java

/**
 * Sorts values statelessly in order given by enumeration
 * @param v1 the values to sort (a native backed array)
 * @param d the direction in which the sorted array should be returned (based on {@link direction})
 * @return tmp the sorted values/*from  w  ww .  j  av  a2 s  .  co  m*/
 */
public static long[] stateless(long[] v1, direction d) {
    Validate.notNull(v1);
    long[] tmp = Arrays.copyOf(v1, v1.length);
    Arrays.sort(tmp);
    switch (d) {
    case ascend:
        break;
    case descend:
        Reverse.inPlace(tmp);
    }
    return tmp;
}

From source file:com.sec.ose.airs.service.protex.ProtexIdentificationInfoService.java

@Override
public boolean hasSameIdentificationInfoList(SPDXFileDTO srcFile, SPDXFileDTO tgtFile) {
    String src = this.extractIdentificationInfoStringFromComment(srcFile.getComment());
    String tgt = this.extractIdentificationInfoStringFromComment(tgtFile.getComment());

    String[] srcArr, tgtArr;/*from  w  w w  . ja  v  a  2s  .  com*/
    String srcStr = "", tgtStr = "";

    srcArr = src.split(delimiter);
    tgtArr = tgt.split(delimiter);
    Arrays.sort(srcArr);
    Arrays.sort(tgtArr);

    for (String line : srcArr)
        srcStr += new ProtexIdentificationInfo(line).toKeyStringForComparison();
    for (String line : tgtArr)
        tgtStr += new ProtexIdentificationInfo(line).toKeyStringForComparison();

    return srcStr.equals(tgtStr);
}

From source file:gedi.util.math.stat.testing.WilcoxonUnpaired.java

public double computePval(H1 h1, double[] x, double[] y) {
    double[] conc = ArrayUtils.concat(x, y);
    double[] r = naturalRanking.rank(conc);
    double[] rsort = r.clone();
    Arrays.sort(rsort);

    int nx = x.length;
    int ny = y.length;
    double w = xsum(r, nx) - nx * (nx + 1) / 2;
    double tiesSum = 0;
    int s = 0;/*  w w w  .  j av a  2 s  . com*/
    for (int i = 1; i < rsort.length; i++) {
        if (Double.compare(rsort[s], rsort[i]) < 0) {
            double d = i - s;
            if (d > 1)
                tiesSum += d * d * d - d;
            s = i;
        }
    }
    int d = r.length - s;
    if (d > 1)
        tiesSum += d * d * d * -d;
    double z = w - nx * ny / 2;
    double SIGMA = Math.sqrt((nx * ny / 12) * ((nx + ny + 1) - tiesSum / ((nx + ny) * (nx + ny - 1))));
    double CORRECTION = Math.signum(z) * 0.5;
    if (h1 == H1.GREATER_THAN)
        CORRECTION = 0.5;
    else if (h1 == H1.LESS_THAN)
        CORRECTION = 0.5;

    z = (z - CORRECTION) / SIGMA;
    double PVAL = norm.cumulativeProbability(z);
    if (h1 == H1.GREATER_THAN)
        PVAL = 1 - PVAL;
    else if (h1 == H1.NOT_EQUAL)
        PVAL = 2 * Math.min(PVAL, 1 - PVAL);

    return PVAL;
}

From source file:com.vsthost.rnd.commons.math.ext.linear.DMatrixUtils.java

/**
 * Returns the median of the vector.//from   w w w  . j av  a  2  s  . c  o  m
 *
 * @param vector The input vector as a double array
 * @return The median of the vector
 */
public static double median(double[] vector) {
    final double[] sorted = vector.clone();
    Arrays.sort(sorted);
    if (vector.length % 2 == 1) {
        return sorted[vector.length / 2];
    }
    return (sorted[vector.length / 2 - 1] + sorted[vector.length / 2]) / 2;
}

From source file:lineage2.gameserver.geodata.PathFindBuffers.java

/**
 * Method create.//from   w w  w.  j  a  v a2s. c  om
 * @param mapSize int
 * @return PathFindBuffer
 */
private static PathFindBuffer create(int mapSize) {
    lock.lock();
    try {
        PathFindBuffer buffer;
        PathFindBuffer[] buff = buffers.get(mapSize);
        if (buff != null) {
            buff = lineage2.commons.lang.ArrayUtils.add(buff, buffer = new PathFindBuffer(mapSize));
        } else {
            buff = new PathFindBuffer[] { buffer = new PathFindBuffer(mapSize) };
            sizes = org.apache.commons.lang3.ArrayUtils.add(sizes, mapSize);
            Arrays.sort(sizes);
        }
        buffers.put(mapSize, buff);
        buffer.inUse = true;
        return buffer;
    } finally {
        lock.unlock();
    }
}

From source file:edu.umn.cs.spatialHadoop.operations.Skyline.java

/**
 * Computes the skyline of a set of points using a divided and conquer
 * in-memory algorithm. The algorithm recursively splits the points into
 * half, computes the skyline of each half, and finally combines the two
 * skylines.//from w  w  w. j  a  v a2  s.co m
 * @param points
 * @param dir
 * @return
 */
public static Point[] skylineInMemory(Point[] points, Direction dir) {
    Arrays.sort(points);
    return skylineRecursive(points, 0, points.length, dir);
}

From source file:com.dotmarketing.business.MemcachedCacheAdministratorImpl.java

public MemcachedCacheAdministratorImpl() {

    // set the default for ignored regions
    if (_ignoreRegion == null || _ignoreRegion.length < 1) {
        String[] x = { "velocitymenucache", "indiciescacheinfo" };
        this._ignoreRegion = x;
    }/*from ww  w  . ja  v  a2  s  . com*/
    Arrays.sort(_ignoreRegion);

    // set default region expiry
    _expires.put("default", Config.getIntProperty("memcached.default.expires", 0));

    Iterator<String> it = Config.getKeys();

    // get the config
    while (it.hasNext()) {
        String key = it.next();
        if (key == null) {
            continue;
        }

        // allow an expirey date for each cache region
        if (key.startsWith("memcached.") && key.endsWith(".expires")) {
            String cacheName = key.split("\\.")[1];
            int exp = Config.getIntProperty(key, Config.getIntProperty("memcached.default.expires", 0));
            Map<String, Integer> m = new HashMap<String, Integer>();
            m.put(cacheName.toLowerCase(), exp);
            _expires.putAll(m);
            Logger.info(this.getClass(), "***\t Memcached Config expires: " + cacheName + ": " + exp);
            // allow an server weight for each server
        } else if (key.startsWith("memcached.server.") && key.endsWith(".address")) {

            try {
                int x = Integer.parseInt(key.split("\\.")[2]);
                String address = Config.getStringProperty(key);
                InetSocketAddress addr = AddrUtil.getOneAddress(address);
                _servers.add(addr);
            } catch (Exception ex) {
                Logger.error(this.getClass(),
                        "***\t Memcached Config server address error: " + Config.getStringProperty(key));
                Logger.error(this.getClass(),
                        "***\t Memcached Config server address error: " + ex.getMessage());

            }

            Logger.info(this.getClass(), "***\t Memcached Config server: " + Config.getStringProperty(key));
        } else if (key.startsWith("memcached.server") && key.endsWith("weight")) {
            int x = Integer.parseInt(key.split("\\.")[2]);
            _weights.add(Config.getIntProperty(key, 1));
            Logger.info(this.getClass(),
                    "***\t Memcached Config server weight: " + Config.getIntProperty(key, 1));
        }

    }

    if (_servers.size() == 0) {
        InetSocketAddress addr = AddrUtil
                .getOneAddress(Config.getStringProperty("memcached.server.address.default", "localhost:11211"));

        _servers.add(addr);
    }
    if (LicenseUtil.getLevel() < 300) {
        _allServerIds = new String[0];
    }

    _oldCache = new DotGuavaCacheAdministratorImpl();

}