Example usage for java.lang Integer compare

List of usage examples for java.lang Integer compare

Introduction

In this page you can find the example usage for java.lang Integer compare.

Prototype

public static int compare(int x, int y) 

Source Link

Document

Compares two int values numerically.

Usage

From source file:blusunrize.immersiveengineering.api.shader.ShaderRegistry.java

public static void compileWeight() {
    totalWeight.clear();//w w w .j  a  va  2  s  . co  m
    chestLootShaders.clear();
    for (ShaderRegistryEntry entry : shaderRegistry.values()) {
        if (entry.getIsBagLoot()) {
            int entryRarityWeight = rarityWeightMap.get(entry.getRarity());
            for (Map.Entry<EnumRarity, Integer> weightedRarity : rarityWeightMap.entrySet())
                if (entry.getIsInLowerBags() ? (weightedRarity.getValue() >= entryRarityWeight)
                        : (weightedRarity.getValue() == entryRarityWeight)) {
                    int i = totalWeight.containsKey(weightedRarity.getKey())
                            ? totalWeight.get(weightedRarity.getKey())
                            : 0;
                    totalWeight.put(weightedRarity.getKey(), i + entry.getWeight());
                }
        }
        if (entry.getIsCrateLoot())
            for (int i = 0; i < entry.getWeight(); i++)
                chestLootShaders.add(entry.getName());
    }

    sortedRarityMap.clear();
    sortedRarityMap.addAll(ShaderRegistry.rarityWeightMap.keySet());
    Collections.sort(sortedRarityMap, new Comparator<EnumRarity>() {
        @Override
        public int compare(EnumRarity enum0, EnumRarity enum1) {
            return Integer.compare(ShaderRegistry.rarityWeightMap.get(enum0),
                    ShaderRegistry.rarityWeightMap.get(enum1));
        }
    });

    if (manualEntry != null) {
        ArrayList<PositionedItemStack[]> recipes = new ArrayList();
        NonNullList<ItemStack> shaderBags = NonNullList.withSize(ShaderRegistry.sortedRarityMap.size(),
                ItemStack.EMPTY);
        recipes = new ArrayList();
        for (int i = 0; i < ShaderRegistry.sortedRarityMap.size(); i++) {
            EnumRarity outputRarity = ShaderRegistry.sortedRarityMap.get(i);
            shaderBags.set(i, new ItemStack(itemShaderBag));
            shaderBags.get(i).setTagCompound(new NBTTagCompound());
            shaderBags.get(i).getTagCompound().setString("rarity", outputRarity.toString());
            ArrayList<EnumRarity> upperRarities = ShaderRegistry.getHigherRarities(outputRarity);
            if (!upperRarities.isEmpty()) {
                ArrayList<ItemStack> inputList = new ArrayList();
                for (EnumRarity r : upperRarities) {
                    ItemStack bag = new ItemStack(itemShaderBag);
                    bag.setTagCompound(new NBTTagCompound());
                    bag.getTagCompound().setString("rarity", r.toString());
                    inputList.add(bag);
                }
                ItemStack s0 = new ItemStack(itemShaderBag, 2);
                s0.setTagCompound(new NBTTagCompound());
                s0.getTagCompound().setString("rarity", outputRarity.toString());
                if (!inputList.isEmpty())
                    recipes.add(new PositionedItemStack[] { new PositionedItemStack(inputList, 33, 0),
                            new PositionedItemStack(s0, 69, 0) });
                //               inputList = new ArrayList();
                //               for(ShaderRegistryEntry entry : ShaderRegistry.shaderRegistry.values())
                //                  if(upperRarities.contains(entry.getRarity()))
                //                  {
                //                     ItemStack shader = new ItemStack(itemShader);
                //                     shader.setTagCompound(new NBTTagCompound());
                //                     shader.getTagCompound().setString("shader_name",  entry.getName());
                //                     inputList.add(shader);
                //                  }
                //               ItemStack s1 = new ItemStack(itemShaderBag);
                //               s1.setTagCompound(new NBTTagCompound());
                //               s1.getTagCompound().setString("rarity", outputRarity.toString());
                //               if(!inputList.isEmpty())
                //                  recipes.add(new PositionedItemStack[]{ new PositionedItemStack(inputList, 33, 0), new PositionedItemStack(s1, 69, 0)});
            }
        }
        manualEntry.getPages()[2] = new ManualPages.ItemDisplay(ManualHelper.getManual(), "shader2",
                shaderBags);
        manualEntry.getPages()[3] = new ManualPages.CraftingMulti(ManualHelper.getManual(), "shader3",
                (Object[]) recipes.toArray(new PositionedItemStack[recipes.size()][3]));
    }
}

From source file:us.parr.animl.data.DataTable.java

public void sortBy(int colIndex) {
    switch (colTypes[colIndex]) {
    case CATEGORICAL_INT:
    case NUMERICAL_INT:
    case CATEGORICAL_STRING: // strings are encoded as ints
    case TARGET_CATEGORICAL_STRING:
    case TARGET_CATEGORICAL_INT:
    case UNUSED_INT:
    case UNUSED_STRING:
        Collections.sort(rows, (ra, rb) -> {
            return Integer.compare(ra[colIndex], rb[colIndex]);
        });/* www  . ja va  2  s.c o  m*/
        break;
    case NUMERICAL_FLOAT:
    case UNUSED_FLOAT:
        Collections.sort(rows, (ra, rb) -> {
            return Float.compare(Float.intBitsToFloat(ra[colIndex]), Float.intBitsToFloat(rb[colIndex]));
        });
        break;
    }
}

From source file:jef.database.DbMetaData.java

/**
 * //ww  w . j a  v a 2 s  .  co m
 * 
 * @param tableName
 *            ??
 * @return  A collection of columns.
 * @throws SQLException
 * @see Column
 */
public List<Column> getColumns(String tableName, boolean needRemark) throws SQLException {
    tableName = info.profile.getObjectNameToUse(tableName);

    Connection conn = getConnection(needRemark);
    DatabaseMetaData databaseMetaData = conn.getMetaData();
    String schema = this.schema;
    int n = tableName.indexOf('.');
    if (n > 0) {// ???schema
        schema = tableName.substring(0, n);
        tableName = tableName.substring(n + 1);
    }
    ResultSet rs = null;
    List<Column> list = new ArrayList<Column>();
    Collection<Index> indexes = null;
    try {
        rs = databaseMetaData.getColumns(null, schema, tableName, "%");
        while (rs.next()) {
            if (indexes == null) {
                // ?Oracle?getIndexInfo()???????
                // ????
                indexes = getIndexes(tableName);
            }
            Column column = new Column();
            populateColumn(column, rs, tableName, indexes);
            list.add(column);
        }
    } finally {
        DbUtils.close(rs);
        releaseConnection(conn);
    }
    Collections.sort(list, (a, b) -> Integer.compare(a.getOrdinal(), b.getOrdinal()));
    return list;
}

From source file:org.apache.carbondata.scan.executor.util.QueryUtil.java

/**
 * Below method will be used to create a mapping of column group columns
 * this mapping will have column group id to all the dimension ordinal
 * present in the column group This mapping will be used during query
 * execution, to create a mask key for the column group dimension which will
 * be used in aggregation and filter query as column group dimension will be
 * stored in bit level//from   w ww  .  j  ava2s.  c  om
 */
private static Map<Integer, List<Integer>> getColumnGroupAndItsOrdinalMapping(
        List<QueryDimension> origdimensions) {

    List<QueryDimension> dimensions = new ArrayList<QueryDimension>(origdimensions.size());
    dimensions.addAll(origdimensions);
    /**
     * sort based on column group id
     */
    Collections.sort(dimensions, new Comparator<QueryDimension>() {

        @Override
        public int compare(QueryDimension o1, QueryDimension o2) {
            return Integer.compare(o1.getDimension().columnGroupId(), o2.getDimension().columnGroupId());
        }
    });
    // list of row groups this will store all the row group column
    Map<Integer, List<Integer>> columnGroupAndItsOrdinalsMapping = new HashMap<Integer, List<Integer>>();
    // to store a column group
    List<Integer> currentColumnGroup = null;
    // current index
    int index = 0;
    // previous column group to check all the column of row id has bee
    // selected
    int prvColumnGroupId = -1;
    while (index < dimensions.size()) {
        // if dimension group id is not zero and it is same as the previous
        // column group id
        // then we need to add ordinal of that column as it belongs to same
        // column group
        if (!dimensions.get(index).getDimension().isColumnar()
                && dimensions.get(index).getDimension().columnGroupId() == prvColumnGroupId
                && null != currentColumnGroup) {
            currentColumnGroup.add(dimensions.get(index).getDimension().getOrdinal());
        }

        // if dimension is not a columnar then it is column group column
        else if (!dimensions.get(index).getDimension().isColumnar()) {
            currentColumnGroup = new ArrayList<Integer>();
            columnGroupAndItsOrdinalsMapping.put(dimensions.get(index).getDimension().columnGroupId(),
                    currentColumnGroup);
            currentColumnGroup.add(dimensions.get(index).getDimension().getOrdinal());
        }
        // update the row id every time,this is required to group the
        // columns
        // of the same row group
        prvColumnGroupId = dimensions.get(index).getDimension().columnGroupId();
        index++;
    }
    return columnGroupAndItsOrdinalsMapping;
}

From source file:com.puresoltechnologies.versioning.Version.java

/**
 * <p>/*from   w w w . j av a2  s  .  c o m*/
 * This method is the implementation of {@link Comparable#compareTo(Object)}
 * .
 * </p>
 * <p>
 * <b>Note: this class has a natural ordering that is inconsistent with
 * {@link #equals(Object)}.</b> equals checks correctly with build metadata
 * information included, but Semantic Versioning does not include this
 * metadata for version comparison. For any version comparison, use
 * {@link #compareTo(Version)} instead of {@link #equals(Object)}.
 * </p>
 * 
 * @param other
 *            is the other version to compare to this one.
 * @return 1 is returned in case this version is greater than the other. -1
 *         is returned in case this version is smaller and 0 if both are
 *         equal.
 */
@Override
public int compareTo(Version other) {
    if (major != other.major) {
        return Integer.compare(major, other.major);
    }
    if (minor != other.minor) {
        return Integer.compare(minor, other.minor);
    }
    if (patch != other.patch) {
        return Integer.compare(patch, other.patch);
    }
    if (preReleaseInformation == null) {
        if (other.preReleaseInformation == null) {
            return 0;
        } else {
            return 1;
        }
    } else {
        if (other.preReleaseInformation == null) {
            return -1;
        }
        return comparePreReleaseInformation(other);
    }
}

From source file:edu.cmu.tetrad.search.TimeSeriesUtils.java

public static IKnowledge getKnowledge(Graph graph) {
    //        System.out.println("Entering getKnowledge ... ");
    int numLags = 1; // need to fix this!
    List<Node> variables = graph.getNodes();
    List<Integer> laglist = new ArrayList<>();
    IKnowledge knowledge = new Knowledge2();
    int lag;/*from  ww  w . j  a  v  a  2 s  .c  o m*/
    for (Node node : variables) {
        String varName = node.getName();
        String tmp;
        if (varName.indexOf(':') == -1) {
            lag = 0;
            laglist.add(lag);
        } else {
            tmp = varName.substring(varName.indexOf(':') + 1, varName.length());
            lag = Integer.parseInt(tmp);
            laglist.add(lag);
        }
    }
    numLags = Collections.max(laglist);

    //        System.out.println("Variable list before the sort = " + variables);
    Collections.sort(variables, new Comparator<Node>() {
        @Override
        public int compare(Node o1, Node o2) {
            String name1 = getNameNoLag(o1);
            String name2 = getNameNoLag(o2);

            //                System.out.println("name 1 = " + name1);
            //                System.out.println("name 2 = " + name2);

            String prefix1 = getPrefix(name1);
            String prefix2 = getPrefix(name2);

            //                System.out.println("prefix 1 = " + prefix1);
            //                System.out.println("prefix 2 = " + prefix2);

            int index1 = getIndex(name1);
            int index2 = getIndex(name2);

            //                System.out.println("index 1 = " + index1);
            //                System.out.println("index 2 = " + index2);

            if (getLag(o1.getName()) == getLag(o2.getName())) {
                if (prefix1.compareTo(prefix2) == 0) {
                    return Integer.compare(index1, index2);
                } else {
                    return prefix1.compareTo(prefix2);
                }
            } else {
                return getLag(o1.getName()) - getLag(o2.getName());
            }
        }
    });

    //        System.out.println("Variable list after the sort = " + variables);

    for (Node node : variables) {
        String varName = node.getName();
        String tmp;
        if (varName.indexOf(':') == -1) {
            lag = 0;
            //                laglist.add(lag);
        } else {
            tmp = varName.substring(varName.indexOf(':') + 1, varName.length());
            lag = Integer.parseInt(tmp);
            //                laglist.add(lag);
        }
        knowledge.addToTier(numLags - lag, node.getName());
    }

    //System.out.println("Knowledge in graph = " + knowledge);
    return knowledge;
}

From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.ui.panel.Chromatogram2DViewerPanel.java

public void setPlot(final XYPlot plot) {
    removeAxisListener();/*  w w  w  . j a  v a 2 s  .  c  om*/
    ADataset2D dataset = null;
    if (plot.getDataset() instanceof ADataset2D) {
        dataset = (ADataset2D) plot.getDataset();
    } else {
        throw new IllegalArgumentException("Requires a plot with ADataset2D!");
    }
    this.plot = plot;
    if (this.selectionOverlay != null) {
        this.content.remove(selectionOverlay);
        this.selectionOverlay = null;
    }
    if (selectionOverlay == null) {
        selectionOverlay = new SelectionOverlay(Color.BLUE, Color.RED, 1.75f, 1.75f, 0.66f);
        chartPanel.addOverlay(selectionOverlay);
        selectionOverlay.addChangeListener(chartPanel);
        this.content.add(selectionOverlay);
    } else {
        for (ISelection selection : selectionOverlay.getMouseClickSelection()) {
            selection.setDataset(dataset);
        }

        ISelection selection = selectionOverlay.getMouseHoverSelection();
        if (selection != null) {
            selection.setDataset(dataset);
        }
    }
    if (selectionHandler == null) {
        selectionHandler = new InstanceContentSelectionHandler(this.content, selectionOverlay,
                InstanceContentSelectionHandler.Mode.valueOf((String) modeSpinner.getValue()), dataset, 1);
    } else {
        selectionHandler.setDataset(dataset);
    }
    if (mouseSelectionHandler == null) {
        mouseSelectionHandler = new XYMouseSelectionHandler<>(dataset);
        mouseSelectionHandler.addSelectionChangeListener(selectionOverlay);
        mouseSelectionHandler.addSelectionChangeListener(selectionHandler);
        chartPanel.addChartMouseListener(mouseSelectionHandler);
    } else {
        mouseSelectionHandler.setDataset(dataset);
    }

    XYItemRenderer xyir = plot.getRenderer();
    if (xyir instanceof XYBlockRenderer) {
        XYBlockRenderer xybr = (XYBlockRenderer) xyir;
        boxWidthSpinner.setValue(xybr.getBlockWidth());
        boxHeightSpinner.setValue(xybr.getBlockHeight());
    }

    AxisChangeListener listener = selectionOverlay;
    ValueAxis domain = this.plot.getDomainAxis();
    ValueAxis range = this.plot.getRangeAxis();
    if (domain != null) {
        domain.addChangeListener(listener);
    }
    if (range != null) {
        range.addChangeListener(listener);
    }

    this.plot.setNoDataMessage("Loading Data...");
    chart = new JFreeChart(this.plot);
    chartPanel.setChart(chart);
    //        dmkl = new DomainMarkerKeyListener(
    //                this.plot);
    //        dmkl.setPlot(this.plot);
    //        chartPanel.addKeyListener(dmkl);
    addAxisListener();
    //add available chart overlays
    ArrayList<? extends Overlay> overlays = new ArrayList<>(getLookup().lookupAll(Overlay.class));
    Collections.sort(overlays, new Comparator<Overlay>() {

        @Override
        public int compare(Overlay o1, Overlay o2) {
            if (o1 instanceof ChartOverlay && o2 instanceof ChartOverlay) {
                ChartOverlay co1 = (ChartOverlay) o1;
                ChartOverlay co2 = (ChartOverlay) o2;
                return Integer.compare(co1.getLayerPosition(), co2.getLayerPosition());
            } else {
                return 0;
            }
        }
    });
    for (Overlay overlay : overlays) {
        if (!(overlay instanceof SelectionOverlay)) {
            chartPanel.removeOverlay(overlay);
            if (overlay instanceof AxisChangeListener) {
                AxisChangeListener axisChangeListener = (AxisChangeListener) overlay;
                if (domain != null) {
                    domain.addChangeListener(axisChangeListener);
                }
                if (range != null) {
                    range.addChangeListener(axisChangeListener);
                }
            }
            if (overlay instanceof ISelectionChangeListener) {
                ISelectionChangeListener isl = (ISelectionChangeListener) overlay;
                mouseSelectionHandler.addSelectionChangeListener(isl);
                mouseSelectionHandler.addSelectionChangeListener(selectionHandler);
                selectionOverlay.addChangeListener(chartPanel);
            }
            chartPanel.addOverlay(overlay);
            overlay.addChangeListener(chartPanel);
        }
    }
    //add selection overlay last
    chartPanel.removeOverlay(selectionOverlay);
    chartPanel.addOverlay(selectionOverlay);
    if (range != null) {
        range.setAutoRange(true);
        range.setDefaultAutoRange(DatasetUtilities.findRangeBounds(dataset));
    }
    if (domain != null) {
        domain.setAutoRange(true);
        domain.setDefaultAutoRange(DatasetUtilities.findDomainBounds(dataset));
    }
}

From source file:us.parr.animl.data.DataTable.java

public int compare(int rowi, int rowj, int colIndex) {
    VariableType colType = colTypes[colIndex];
    switch (colType) {
    case CATEGORICAL_INT:
    case NUMERICAL_INT:
    case CATEGORICAL_STRING: // strings are encoded as ints
    case TARGET_CATEGORICAL_STRING:
    case TARGET_CATEGORICAL_INT:
    case UNUSED_INT:
    case UNUSED_STRING:
        return Integer.compare(getAsInt(rowi, colIndex), getAsInt(rowj, colIndex));
    case NUMERICAL_FLOAT:
    case UNUSED_FLOAT:
        float a = getAsFloat(rowi, colIndex);
        float b = getAsFloat(rowj, colIndex);
        return Float.compare(a, b);
    default://from ww w .j  a v a 2 s.com
        throw new IllegalArgumentException(colNames[colIndex] + " has invalid type: " + colType);
    }
}

From source file:gedi.riboseq.inference.orf.OrfFinder.java

private void annotate(ImmutableReferenceGenomicRegion<Orf> r) {
    ArrayList<ImmutableReferenceGenomicRegion<Transcript>> tr = intronless.ei(r).map(i -> i.getData())
            .toCollection(new ArrayList<>());
    Comparator<ImmutableReferenceGenomicRegion<Transcript>> comp = (a, b) -> Integer
            .compare(a.getRegion().getTotalLength(), b.getRegion().getTotalLength());
    comp = comp.thenComparing((a, b) -> a.getData().getTranscriptId().compareTo(b.getData().getTranscriptId())); // just to make it stable for two different orfs
    Collections.sort(tr, comp);//  www.j av  a2 s.  co m

    for (OrfType type : OrfType.values()) {
        for (ImmutableReferenceGenomicRegion<Transcript> t : tr) {
            if (type.is(r, t)) {
                r.getData().reference = t;
                r.getData().orfType = type;
                return;
            }
        }
    }
    r.getData().orfType = OrfType.oORF;
}

From source file:org.zaproxy.zap.extension.websocket.WebSocketProxy.java

private static synchronized Comparator<WebSocketSenderListener> getSenderListenersComparator() {
    if (null == senderListenersComparator) {
        senderListenersComparator = new Comparator<WebSocketSenderListener>() {
            @Override/*www  .j  a va 2s.  c o  m*/
            public int compare(WebSocketSenderListener o1, WebSocketSenderListener o2) {
                return Integer.compare(o1.getListenerOrder(), o2.getListenerOrder());
            }
        };
    }

    return senderListenersComparator;
}