Example usage for org.apache.commons.lang.math IntRange containsInteger

List of usage examples for org.apache.commons.lang.math IntRange containsInteger

Introduction

In this page you can find the example usage for org.apache.commons.lang.math IntRange containsInteger.

Prototype

public boolean containsInteger(int value) 

Source Link

Document

Tests whether the specified int occurs within this range using int comparison.

This implementation overrides the superclass for performance as it is the most common case.

Usage

From source file:com.linkedin.pinot.core.query.pruner.PartitionSegmentPruner.java

/**
 * Helper method that prunes the segment as follows:
 * <ul>// w w w .  j  a v  a2  s  .co m
 *   <li> For non-leaf nodes, calls base pruneNonLeaf method in the super class. </li>
 *   <li> For leaf nodes, segment is pruned if equality predicate value on column does fall within the
 *        partition range of the segment. For all other cases, segment is not pruned. </li>
 * </ul>
 * @param filterQueryTree Filter query tree
 * @param columnMetadataMap Column metadata map
 * @return True if segment can be pruned, false otherwise
 */
@Override
public boolean pruneSegment(FilterQueryTree filterQueryTree, Map<String, ColumnMetadata> columnMetadataMap) {
    List<FilterQueryTree> children = filterQueryTree.getChildren();

    // Non-leaf node
    if (children != null && !children.isEmpty()) {
        return pruneNonLeaf(filterQueryTree, columnMetadataMap);
    }

    // TODO: Enhance partition based pruning for RANGE operator.
    if (filterQueryTree.getOperator() != FilterOperator.EQUALITY) {
        return false;
    }

    // Leaf node
    String column = filterQueryTree.getColumn();
    ColumnMetadata metadata = columnMetadataMap.get(column);
    if (metadata == null) {
        return false;
    }

    List<IntRange> partitionRanges = metadata.getPartitionRanges();
    if (partitionRanges == null || partitionRanges.isEmpty()) {
        return false;
    }

    Comparable value = getValue(filterQueryTree.getValue().get(0), metadata.getDataType());
    PartitionFunction partitionFunction = metadata.getPartitionFunction();
    int partition = partitionFunction.getPartition(value);

    for (IntRange partitionRange : partitionRanges) {
        if (partitionRange.containsInteger(partition)) {
            return false;
        }
    }
    return true;
}

From source file:com.linkedin.pinot.broker.pruner.PartitionZKMetadataPruner.java

/**
 * Helper method to prune a segment based on the filter query tree and partition metadata.
 *
 * @param filterQueryTree Filter tree for the predicates in the query
 * @param columnMetadataMap Map of column name to partition metadata for the column.
 *
 * @return True if the segment can be pruned, false otherwise.
 *//*  w ww .j av a 2  s .  com*/
private boolean pruneSegment(FilterQueryTree filterQueryTree,
        Map<String, ColumnPartitionMetadata> columnMetadataMap) {
    if (filterQueryTree == null) {
        return false;
    }

    List<FilterQueryTree> children = filterQueryTree.getChildren();

    // Non-leaf node
    if (children != null && !children.isEmpty()) {
        return pruneNonLeaf(filterQueryTree, columnMetadataMap);
    }

    // TODO: Enhance partition based pruning for RANGE operator.
    if (filterQueryTree.getOperator() != FilterOperator.EQUALITY) {
        return false;
    }

    // Leaf node
    String column = filterQueryTree.getColumn();
    ColumnPartitionMetadata metadata = columnMetadataMap.get(column);
    if (metadata == null) {
        return false;
    }

    List<IntRange> partitionRanges = metadata.getPartitionRanges();
    if (partitionRanges == null || partitionRanges.isEmpty()) {
        return false;
    }

    String value = filterQueryTree.getValue().get(0);
    PartitionFunction partitionFunction = PartitionFunctionFactory
            .getPartitionFunction(metadata.getFunctionName(), metadata.getNumPartitions());
    int partition = partitionFunction.getPartition(value);

    for (IntRange partitionRange : partitionRanges) {
        if (partitionRange.containsInteger(partition)) {
            return false;
        }
    }
    return true;
}

From source file:edu.harvard.med.screensaver.io.screenresults.ScreenResultParser.java

/**
 * Parse the workbook containing the ScreenResult data.
 *
 * @param workbook the workbook containing some or all of the raw data for a
 *          ScreenResult/*from www  . j a v a2  s .  c o m*/
 * @throws ExtantLibraryException if an existing Well entity cannot be found
 *           in the database
 * @throws IOException
 * @throws UnrecoverableScreenResultParseException
 */
private void parseData(Workbook workbook, ScreenResult screenResult, IntRange plateNumberRange,
        boolean incrementalFlush)
        throws ExtantLibraryException, IOException, UnrecoverableScreenResultParseException {
    log.debug("incrementalFlush:" + incrementalFlush);
    long startTime = System.currentTimeMillis();
    long loopTime = startTime;

    int wellsWithDataLoaded = 0;
    int dataSheetsParsed = 0;
    int totalSheets = workbook.getWorkbook().getNumberOfSheets();
    int firstDataSheetIndex = workbook.getWorksheet(DATA_COLUMNS_SHEET_NAME).getSheetIndex() + 1;
    int totalDataSheets = Math.max(0, totalSheets - firstDataSheetIndex);
    plateNumberRange = plateNumberRange == null ? new IntRange(Integer.MIN_VALUE, Integer.MAX_VALUE)
            : plateNumberRange;

    // Note: we do this to make sure that the DataColumn's are persisted before we persist and clear the RV's
    if (screenResult.getEntityId() == null) {
        _genericEntityDao.persistEntity(screenResult);
    } else {
        _genericEntityDao.saveOrUpdateEntity(screenResult);
    }
    _genericEntityDao.flush();

    for (int iSheet = firstDataSheetIndex; iSheet < totalSheets; ++iSheet) {
        String sheetName = workbook.getWorkbook().getSheet(iSheet).getName();
        log.info("parsing sheet " + (dataSheetsParsed + 1) + " of " + totalDataSheets + ", " + sheetName);
        Worksheet worksheet = workbook.getWorksheet(iSheet).forOrigin(0, DATA_SHEET__FIRST_DATA_ROW_INDEX);

        for (Row row : worksheet) {
            // bring in the old findNextRow() logic
            if (row.getColumns() > 0 && !row.getCell(0).isEmpty()
                    && row.getCell(0).getAsString().trim().length() > 0) {
                Integer plateNumber = row.getCell(WellInfoColumn.PLATE.ordinal(), true).getInteger();
                Cell wellNameCell = row.getCell(WellInfoColumn.WELL_NAME.ordinal());
                String wellName = _wellNameParser.parse(wellNameCell);
                if (!wellName.equals("")) {
                    WellKey wellKey = new WellKey(plateNumber, wellName);
                    if (!plateNumberRange.containsInteger(wellKey.getPlateNumber())) {
                        if (log.isDebugEnabled()) {
                            log.debug(
                                    "Skipping, excluded range: " + plateNumberRange + ", row: " + row.getRow());
                        }
                    } else {
                        boolean duplicate = !parsedWellKeys.add(wellKey.getKey());
                        if (duplicate) {
                            if (!_ignoreDuplicateErrors) {
                                wellNameCell.addError("duplicate well: " + wellKey);
                            } else {
                                log.debug(
                                        "duplicate well: " + wellKey + ", duplicate found at: " + wellNameCell);
                            }
                        } else {
                            if (findLibraryWithPlate(wellKey.getPlateNumber()) == null) {
                                wellNameCell.addError(NO_SUCH_LIBRARY_WITH_PLATE);
                            } else {
                                Well well = _librariesDao.findWell(wellKey);
                                if (well == null) {
                                    wellNameCell.addError(NO_SUCH_WELL + ": " + wellKey);
                                } else if (findAssayWell(well) == null) {
                                    readResultValues(screenResult, row, well, incrementalFlush);
                                    ++wellsWithDataLoaded;
                                    if (incrementalFlush
                                            && wellsWithDataLoaded % AbstractDAO.ROWS_TO_CACHE == 0) {
                                        saveResultValuesAndFlush(screenResult, incrementalFlush);
                                        if (log.isInfoEnabled() && wellsWithDataLoaded
                                                % (AbstractDAO.ROWS_TO_CACHE * 100) == 0) {
                                            long time = System.currentTimeMillis();
                                            long cumulativeTime = time - startTime;
                                            log.info("wellsWithDataLoaded: " + wellsWithDataLoaded
                                                    + ", cumulative time: "
                                                    + (double) cumulativeTime / (double) 60000
                                                    + " min, avg row time: "
                                                    + (double) cumulativeTime / (double) wellsWithDataLoaded
                                                    + ", loopTime: " + (time - loopTime));
                                            loopTime = time;
                                        }
                                    } // incremental
                                }
                            }
                        }
                    }
                }
            }
        } // for row
        ++dataSheetsParsed;
        if (wellsWithDataLoaded > 0) {
            saveResultValuesAndFlush(screenResult, incrementalFlush);
            log.info("Sheet: " + sheetName + " done, save, count: " + wellsWithDataLoaded);
            long time = System.currentTimeMillis();
            long cumulativeTime = time - startTime;
            log.info("wellsWithDataLoaded: " + wellsWithDataLoaded + ", cumulative time: "
                    + (double) cumulativeTime / (double) 60000 + " min, avg row time: "
                    + (double) cumulativeTime / (double) wellsWithDataLoaded);
        }
    }

    if (dataSheetsParsed == 0) {
        _workbook.addError(NO_DATA_SHEETS_FOUND_ERROR);
    } else {
        log.info("done parsing " + dataSheetsParsed + " data sheet(s) " + workbook.getName());
        log.info("loaded data for " + wellsWithDataLoaded + " well(s) ");
    }
}

From source file:org.sakaiproject.util.PasswordCheck.java

/**
 * Method for checking the length of a password is within the bounds
 * /*  ww  w.j  a  v a2  s  .  co m*/
 * @param passwd - string to check length of
 * @param min   - minimum length
 * @param max   - maximum length (must be >= min)
 * @return
 */
public static boolean isAcceptableLength(String passwd, int min, int max) {

    //null
    if (StringUtils.isBlank(passwd)) {
        return false;
    }

    //check bounds
    if (min > max) {
        log.error("Invalid bounds supplied, min (" + min + ") is greater than max (" + max + ")");
    }

    // LENGTH
    int length = passwd.length();

    //check range
    IntRange range = new IntRange(min, max);

    if (range.containsInteger(length)) {
        log.debug("Range ok");
        return true;
    }
    log.debug("Range bad; min=" + min + ", max=" + max + ", length=" + length);
    return false;
}