Example usage for java.lang Integer min

List of usage examples for java.lang Integer min

Introduction

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

Prototype

public static int min(int a, int b) 

Source Link

Document

Returns the smaller of two int values as if by calling Math#min(int,int) Math.min .

Usage

From source file:ch.cyberduck.core.http.LoggingHttpRequestExecutor.java

@Override
protected HttpResponse doSendRequest(final HttpRequest request, final HttpClientConnection conn,
        final HttpContext context) throws IOException, HttpException {
    synchronized (listener) {
        listener.log(TranscriptListener.Type.request, request.getRequestLine().toString());
        for (Header header : request.getAllHeaders()) {
            switch (header.getName()) {
            case HttpHeaders.AUTHORIZATION:
            case "X-Auth-Key":
            case "X-Auth-Token":
                listener.log(TranscriptListener.Type.request, String.format("%s: %s", header.getName(),
                        StringUtils.repeat("*", Integer.min(8, StringUtils.length(header.getValue())))));
                break;
            default:
                listener.log(TranscriptListener.Type.request, header.toString());
                break;
            }//ww w  .j  a  va  2  s  .  c  o  m
        }
    }
    return super.doSendRequest(request, conn, context);
}

From source file:org.xlrnet.metadict.impl.aggregation.LevenstheinRelevanceOrderStrategy.java

double calculateEntryScore(@NotNull ResultEntry entry, @NotNull String queryString) {
    int levenstheinInput = StringUtils.getLevenshteinDistance(entry.getInput().getGeneralForm().toLowerCase(),
            queryString.toLowerCase());//from  w w w. j av  a  2 s.  co m
    int levenstheinOutput = Integer.MAX_VALUE;
    if (entry.getOutput() != null && entry.getOutput().getGeneralForm() != null)
        levenstheinOutput = StringUtils.getLevenshteinDistance(entry.getOutput().getGeneralForm().toLowerCase(),
                queryString.toLowerCase());
    int levensthein = Integer.min(levenstheinInput, levenstheinOutput);
    return 1.0 - ((double) levensthein / (1 + (double) levensthein));
}

From source file:org.xlrnet.metadict.core.aggregation.LevenstheinRelevanceOrderStrategy.java

double calculateEntryScore(@NotNull ResultEntry entry, @NotNull String queryString) {
    int levenstheinInput = StringUtils.getLevenshteinDistance(entry.getSource().getGeneralForm().toLowerCase(),
            queryString.toLowerCase());/*w ww.  jav a2  s.  c  o m*/
    int levenstheinOutput = Integer.MAX_VALUE;
    if (entry.getTarget() != null && entry.getTarget().getGeneralForm() != null)
        levenstheinOutput = StringUtils.getLevenshteinDistance(entry.getTarget().getGeneralForm().toLowerCase(),
                queryString.toLowerCase());
    int levensthein = Integer.min(levenstheinInput, levenstheinOutput);
    return 1.0 - ((double) levensthein / (1 + (double) levensthein));
}

From source file:info.archinnov.achilles.internals.statements.StatementWrapper.java

default void logReturnedResultsInternal(Logger actualLogger, UUID queryId, ResultSetWrapper resultSet) {
    final int availableWithoutFetching = resultSet.getAvailableWithoutFetching();
    StringBuilder results = new StringBuilder(format("Query ID %s results : \n", queryId));
    actualLogger.debug(resultSet.toString());
    for (int i = 0; i < Integer.min(availableWithoutFetching, RESULTS_LOG_DISPLAY_LIMIT); i++) {
        final Row row = resultSet.peek();
        appendRowDataToBuilder(row, row.getColumnDefinitions().asList(), results);
    }//  w w  w . j a  v a2s  .  c o m
    actualLogger.debug(results.toString());
}

From source file:org.ncic.bioinfo.sparkseq.algorithms.data.sam.IntervalLocusSamTraverser.java

private List<GenomeLoc> getOverlappedIntervals(GenomeLoc refLocus, List<GenomeLoc> rawTraverseIntervals) {
    // intervalsrefLocus??
    if (CollectionUtils.isEmpty(rawTraverseIntervals)) {
        List<GenomeLoc> singleGenomeLoc = new ArrayList<>(1);
        singleGenomeLoc.add(refLocus);//from  ww  w .j a  v  a  2  s  . com
        return singleGenomeLoc;
    }

    List<GenomeLoc> rawOverlappedIntervals = rawTraverseIntervals.stream()
            .filter(interval -> interval.overlapsP(refLocus))
            .map(interval -> new GenomeLoc(interval.getContig(), interval.getContigIndex(),
                    (interval.getStart() - OVERLAP_LEN) < refLocus.getStart() ? refLocus.getStart()
                            : (interval.getStart() - OVERLAP_LEN),
                    (interval.getStop() + OVERLAP_LEN) > refLocus.getStop() ? refLocus.getStop()
                            : (interval.getStop() + OVERLAP_LEN)))
            .collect(Collectors.toList());

    Collections.sort(rawOverlappedIntervals,
            (interval1, interval2) -> interval1.getStart() - interval2.getStart());

    //?intervals
    List<GenomeLoc> finalIntervals = new ArrayList<>();
    GenomeLoc tmpInterval = null;
    for (GenomeLoc interval : rawOverlappedIntervals) {
        if (tmpInterval == null) {
            tmpInterval = interval;
        } else {
            if (tmpInterval.overlapsP(interval)) {
                tmpInterval = new GenomeLoc(tmpInterval.getContig(), tmpInterval.getContigIndex(),
                        Integer.min(tmpInterval.getStart(), interval.getStart()),
                        Integer.max(tmpInterval.getStop(), interval.getStop()));
            } else {
                finalIntervals.add(tmpInterval);
                tmpInterval = interval;
            }
        }
    }
    if (tmpInterval != null) {
        finalIntervals.add(tmpInterval);
    }

    return finalIntervals;
}

From source file:org.alfresco.bm.dataload.rm.records.ScheduleInPlaceRecordLoaders.java

/**
 * Helper method that computes the number of files left to preload so that the scheduler has enough files to work with
 * @return the number of records left to preload
 *///from w  w  w. j  a v  a2s .  co  m
private int numberOfFilesLeftToPreload() {
    if (recordDeclarationLimit == 0) {
        // If number of records to declare is 0 load all the files we can find
        return FILES_TO_SCHEDULE_BUFFER_SIZE - unscheduledFilesCache.size();
    }
    return Integer.min(recordDeclarationLimit - numberOfRecordsDeclared, FILES_TO_SCHEDULE_BUFFER_SIZE)
            - unscheduledFilesCache.size();
}

From source file:king.flow.action.DefaultMsgSendAction.java

protected void showErrMsg(final int retCode, final String msg) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*from w w w. ja v a 2 s . c om*/
        public void run() {
            TLSResult result = new TLSResult();
            result.setRetCode(retCode);
            result.setErrMsg(msg);

            if (errDisplayList.size() == 1) {
                showOnComponent(getBlockMeta(errDisplayList.get(0)), result);
            } else {
                try {
                    JSONParser jsonParser = new JSONParser();
                    Object element = jsonParser.parse(result.getErrMsg());
                    if (element instanceof JSONArray) {
                        JSONArray jsonArray = (JSONArray) element;
                        int len = Integer.min(errDisplayList.size(), jsonArray.size());
                        for (int i = 0; i < len; i++) {
                            TLSResult freshResult = new TLSResult(result.getRetCode(), result.getOkMsg(),
                                    jsonArray.get(i).toString(), result.getPrtMsg());
                            showOnComponent(getBlockMeta(errDisplayList.get(i)), freshResult);
                        }
                    } else {
                        showOnComponent(getBlockMeta(errDisplayList.get(0)), result);
                    }
                } catch (Exception e) {
                    getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING,
                            "Exception encounters during failed json value parsing : \n{0}", e);
                }
            }

            panelJump(error.getNextPanel());
        }
    });
}

From source file:king.flow.action.DefaultMsgSendAction.java

protected void showDoneMsg(final TLSResult result) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//  w ww  .jav a2s . c om
        public void run() {
            if (doneDisplayList.size() == 1) {
                showOnComponent(getBlockMeta(doneDisplayList.get(0)), result);
            } else {
                try {
                    JSONParser jsonParser = new JSONParser();
                    Object element = jsonParser.parse(result.getOkMsg());
                    if (element instanceof JSONArray) {
                        JSONArray jsonArray = (JSONArray) element;
                        int len = Integer.min(doneDisplayList.size(), jsonArray.size());
                        for (int i = 0; i < len; i++) {
                            TLSResult freshResult = new TLSResult(result.getRetCode(),
                                    jsonArray.get(i).toString(), result.getErrMsg(), result.getPrtMsg());
                            showOnComponent(getBlockMeta(doneDisplayList.get(i)), freshResult);
                        }
                    } else {
                        showOnComponent(getBlockMeta(doneDisplayList.get(0)), result);
                    }
                } catch (Exception e) {
                    getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING,
                            "Exception encounters during successful json value parsing : \n{0}", e);
                }
            }

            CommonUtil.cachePrintMsg(result.getPrtMsg());
            if (result.getRedirection() != null) {
                String redirection = result.getRedirection();
                getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO,
                        "Be forced to jump to page[{0}], ignore designated page[{1}]",
                        new Object[] { redirection, String.valueOf(next.getNextPanel()) });
                int forwardPage = 0;
                try {
                    forwardPage = Integer.parseInt(redirection);
                } catch (Exception e) {
                    panelJump(next.getNextPanel());
                    return;
                }
                Object blockMeta = getBlockMeta(forwardPage);
                if (blockMeta == null || !(blockMeta instanceof Panel)) {
                    getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO,
                            "Be forced to jump to page[{0}], but page[{0}] is invalid Panel type. It is type[{1}]",
                            new Object[] { redirection,
                                    (blockMeta == null ? "NULL" : blockMeta.getClass().getSimpleName()) });
                    panelJump(next.getNextPanel());
                    return;
                }
                panelJump(forwardPage);
            } else {
                panelJump(next.getNextPanel());

                //trigger the action denoted in sendMsgAction
                Integer trigger = next.getTrigger();
                if (trigger != null && getBlockMeta(trigger) != null) {
                    final Component blockMeta = (Component) getBlockMeta(trigger);
                    switch (blockMeta.getType()) {
                    case COMBO_BOX:
                        JComboBox comboBlock = getBlock(trigger, JComboBox.class);
                        ItemListener[] itemListeners = comboBlock.getItemListeners();
                        ItemEvent e = new ItemEvent(comboBlock, ItemEvent.ITEM_STATE_CHANGED,
                                comboBlock.getItemAt(comboBlock.getItemCount() - 1).toString(),
                                ItemEvent.SELECTED);
                        for (ItemListener itemListener : itemListeners) {
                            itemListener.itemStateChanged(e);//wait and hang on util progress dialog gets to dispose
                        }
                        if (comboBlock.isEditable()) {
                            String value = comboBlock.getEditor().getItem().toString();
                            if (value.length() == 0) {
                                return;
                            }
                        }
                        break;
                    case BUTTON:
                        JButton btnBlock = getBlock(trigger, JButton.class);
                        btnBlock.doClick();
                        break;
                    default:
                        getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING,
                                "Invalid trigger component[{0}] as unsupported type[{1}]",
                                new Object[] { trigger, blockMeta.getType() });
                        break;
                    }
                } //trigger dealing 
                  //keep next cursor on correct component
                Integer nextCursor = next.getNextCursor();
                if (nextCursor != null && getBlockMeta(nextCursor) != null) {
                    JComponent block = getBlock(nextCursor, JComponent.class);
                    block.requestFocusInWindow();
                }
            } // no redirection branch
        }
    });
}