java.util.Collections.min()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中java.util.Collections.min()方法的一些代码示例,展示了Collections.min()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.min()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:min

Collections.min介绍

[英]Searches the specified collection for the minimum element.
[中]

代码示例

代码示例来源:origin: stackoverflow.com

import java.util.Arrays;
import java.util.Collections;

import org.apache.commons.lang.ArrayUtils;

public class MinMaxValue {

  public static void main(String[] args) {
    char[] a = {'3', '5', '1', '4', '2'};

    List b = Arrays.asList(ArrayUtils.toObject(a));

    System.out.println(Collections.min(b));
    System.out.println(Collections.max(b));
  }
}

代码示例来源:origin: jersey/jersey

public boolean contains(List<Integer> data) {
    if (Collections.min(data) < lower()
        || Collections.max(data) > upper()) {
      return false;
    } else {
      return true;
    }
  }
}

代码示例来源:origin: apache/kylin

private void setupMapper(CubeSegment cubeSeg) throws IOException {
  // set the segment's offset info to job conf
  Map<Integer, Long> offsetStart = cubeSeg.getSourcePartitionOffsetStart();
  Map<Integer, Long> offsetEnd = cubeSeg.getSourcePartitionOffsetEnd();
  Integer minPartition = Collections.min(offsetStart.keySet());
  Integer maxPartition = Collections.max(offsetStart.keySet());
  job.getConfiguration().set(CONFIG_KAFKA_PARITION_MIN, minPartition.toString());
  job.getConfiguration().set(CONFIG_KAFKA_PARITION_MAX, maxPartition.toString());
  for(Integer partition: offsetStart.keySet()) {
    job.getConfiguration().set(CONFIG_KAFKA_PARITION_START + partition, offsetStart.get(partition).toString());
    job.getConfiguration().set(CONFIG_KAFKA_PARITION_END + partition, offsetEnd.get(partition).toString());
  }
  job.setMapperClass(KafkaFlatTableMapper.class);
  job.setInputFormatClass(KafkaInputFormat.class);
  job.setOutputKeyClass(BytesWritable.class);
  job.setOutputValueClass(Text.class);
  job.setOutputFormatClass(SequenceFileOutputFormat.class);
  job.setNumReduceTasks(0);
}

代码示例来源:origin: FudanNLP/fnlp

public ArrayList<Integer> normalized(WDataSet wds){
  ArrayList<Integer> wNormalized = new ArrayList<Integer>();
  double max, min, wNDouble;
  int i, wNormalInt;
  double wNormal;
  max = Collections.max(wds.w);
  min = Collections.min(wds.w);
  
  if(max != min)
    for(i = 0; i < wds.graph.getNVerts(); i++){
      wNDouble = wds.w.get(i);
      wNormal = (wNDouble - min) / (max - min);
      wNormalInt = (int)(100 * wNormal);
      wds.w.set(i, wNormal);
      wNormalized.add(wNormalInt);
    }
  else
    for(i = 0; i < wds.graph.getNVerts(); i++)
      wNormalized.add(100);
  return wNormalized;
}

代码示例来源:origin: Graylog2/graylog2-server

private void fillEmptyTimestamps(Map<Long, Map<String, Number>> results) {
  final long minTimestamp = Collections.min(results.keySet());
  final long maxTimestamp = Collections.max(results.keySet());
  final MutableDateTime currentTime = new MutableDateTime(minTimestamp, DateTimeZone.UTC);
  while (currentTime.getMillis() < maxTimestamp) {
    final Map<String, Number> entry = results.get(currentTime.getMillis());
    // advance timestamp by the interval
    currentTime.add(interval.getPeriod());
    if (entry == null) {
      // synthesize a 0 value for this timestamp
      results.put(currentTime.getMillis(), EMPTY_RESULT);
    }
  }
}

代码示例来源:origin: jersey/jersey

final int i = data.indexOf(Collections.min(data));
g.setColor(minColor);
g.fillRect(xs[i] - step / 2, ys[i] - step / 2, step, step);
final int i = data.indexOf(Collections.max(data));
g.setColor(maxColor);
g.fillRect(xs[i] - step / 2, ys[i] - step / 2, step, step);

代码示例来源:origin: cucumber/cucumber-jvm

public byte exitStatus() {
    if (results.isEmpty()) { return DEFAULT; }

    if (runtimeOptions.isWip()) {
      return min(results, SEVERITY).is(Result.Type.PASSED) ? ERRORS : DEFAULT;
    }

    return max(results, SEVERITY).isOk(runtimeOptions.isStrict()) ? DEFAULT : ERRORS;
  }
}

代码示例来源:origin: florent37/CameraFragment

Size maxPictureSize = Collections.max(choices, new CompareSizesByArea2());
Size minPictureSize = Collections.min(choices, new CompareSizesByArea2());

代码示例来源:origin: florent37/CameraFragment

Size maxPictureSize = Collections.max(choices, new CompareSizesByArea2());
Size minPictureSize = Collections.min(choices, new CompareSizesByArea2());

代码示例来源:origin: apache/hbase

private  ResultScanner scan(Table ht, byte[] cf,
  Integer[] rowIndexes, Integer[] columnIndexes,
  Long[] versions, int maxVersions)
throws IOException {
 Arrays.asList(rowIndexes);
 byte startRow[] = Bytes.toBytes("row:" +
   Collections.min( Arrays.asList(rowIndexes)));
 byte endRow[] = Bytes.toBytes("row:" +
   Collections.max( Arrays.asList(rowIndexes))+1);
 Scan scan = new Scan(startRow, endRow);
 for (Integer colIdx: columnIndexes) {
  byte column[] = Bytes.toBytes("column:" + colIdx);
  scan.addColumn(cf, column);
 }
 scan.setMaxVersions(maxVersions);
 scan.setTimeRange(Collections.min(Arrays.asList(versions)),
   Collections.max(Arrays.asList(versions))+1);
 ResultScanner scanner = ht.getScanner(scan);
 return scanner;
}

代码示例来源:origin: gocd/gocd

private PipelineInstanceModels loadHistory(String pipelineName, List<Long> ids) {
  if (ids.isEmpty()) {
    return PipelineInstanceModels.createPipelineInstanceModels();
  }
  Map<String, Object> args = arguments("pipelineName", pipelineName)
      .and("from", Collections.min(ids))
      .and("to", Collections.max(ids)).asMap();
  PipelineInstanceModels history = PipelineInstanceModels.createPipelineInstanceModels(
      (List<PipelineInstanceModel>) getSqlMapClientTemplate().queryForList("getPipelineHistoryByName", args));
  for (PipelineInstanceModel pipelineInstanceModel : history) {
    loadPipelineHistoryBuildCause(pipelineInstanceModel);
  }
  return history;
}

代码示例来源:origin: gocd/gocd

@SuppressWarnings("unchecked")
private List<Map<String, Object>> flatHistory(IBatisUtil.IBatisArgument arguments) {
  List<Long> pipelineIds = getSqlMapClientTemplate().queryForList("limitedPipelineIds", arguments.asMap());
  arguments.and("limitedPipelineIds", pipelineIds);
  long maxId = Collections.max(pipelineIds);
  long minId = Collections.min(pipelineIds);
  arguments = arguments.and("maxId", maxId).and("minId", minId);
  return (List<Map<String, Object>>) getSqlMapClientTemplate()
      .queryForList("getAllPropertiesHistory", arguments.asMap());
}

代码示例来源:origin: googlesamples/android-Camera2Basic

return Collections.min(bigEnough, new CompareSizesByArea());
} else if (notBigEnough.size() > 0) {
  return Collections.max(notBigEnough, new CompareSizesByArea());
} else {
  Log.e(TAG, "Couldn't find any suitable preview size");

代码示例来源:origin: apache/hbase

/**
 * Uses the TimestampFilter on a Get to request a specified list of
 * versions for the row/column specified by rowIdx & colIdx.
 *
 */
private  Cell[] getNVersions(Table ht, byte[] cf, int rowIdx,
  int colIdx, List<Long> versions)
throws IOException {
 byte row[] = Bytes.toBytes("row:" + rowIdx);
 byte column[] = Bytes.toBytes("column:" + colIdx);
 Get get = new Get(row);
 get.addColumn(cf, column);
 get.setMaxVersions();
 get.setTimeRange(Collections.min(versions), Collections.max(versions)+1);
 Result result = ht.get(get);
 return result.rawCells();
}

代码示例来源:origin: stackoverflow.com

versions.add(new Version("1.01.0"));
versions.add(new Version("1.00.1"));
Collections.min(versions).get() // return min version
Collections.max(versions).get() // return max version

代码示例来源:origin: guoguibing/librec

maxRate = Collections.max(ratingScale);
minRate = Collections.min(ratingScale);
if (minRate == maxRate) {
  minRate = 0;

代码示例来源:origin: stackoverflow.com

List<Integer> list = Arrays.asList(100,2,3,4,5,6,7,67,2,32);
 int min = Collections.min(list);
 int max = Collections.max(list);
 System.out.println(min);
 System.out.println(max);

代码示例来源:origin: yahoo/egads

/**
 * Drops as many of the highest or lowest values as possible, leaving
 * at least one value in the list.
 * @param accumulator A non-null accumulator list.
 * @param count A count of 1 or more.
 * @param highest Drop higher values == true or drop lower values == false.
 */
public static void drop(final List<WeightedValue> accumulator, 
    final int count, final boolean highest) {
  for (int x = 0; x < count; x++) {
    if (accumulator.size() <= 1) {
      break;
    }
    if (highest) {
      accumulator.remove(Collections.max(accumulator));
    } else {
      accumulator.remove(Collections.min(accumulator));
    }
  }
}

代码示例来源:origin: yahoo/egads

/**
 * Creates a histogram of the provided data.
 * 
 * @param data list of observations
 * @param breaks number of breaks in the histogram
 * @return List of integer values size of the breaks
 */
public static List<Integer> getHistogram(List<Double> data, int breaks) {
  if (data.isEmpty()) {
    return Collections.emptyList();
  }
  List<Integer> ret = new ArrayList<Integer>(breaks);
  for (int i = 0; i < breaks; i++) {
    ret.add(0);
  }
  double min = Collections.min(data);
  double range = Collections.max(data) - min + 1;
  double step = range / breaks;
  for (double point : data) {
    // Math.min necessary because rounding error -> AIOOBE
    int index = Math.min((int) ((point - min) / step), breaks - 1);
    ret.set(index, ret.get(index) + 1);
  }
  return ret;
}

代码示例来源:origin: yahoo/egads

/**
 * Same as <code>getHistogram</code> but operates on <code>BigIntegers</code>.
 */
public static List<Integer> getHistogramBigInt(List<BigInteger> data, int breaks) {
  if (data.isEmpty()) {
    return Collections.emptyList();
  }
  List<Integer> ret = new ArrayList<Integer>(breaks);
  for (int i = 0; i < breaks; i++) {
    ret.add(0);
  }
  BigInteger min = Collections.min(data);
  BigInteger max = Collections.max(data);
  BigInteger range = max.subtract(min).add(BigInteger.valueOf(1));
  BigInteger step = range.divide(BigInteger.valueOf(breaks));
  if (step.equals(BigInteger.ZERO)) {
    return Collections.emptyList(); // too small
  }
  for (BigInteger point : data) {
    int index = point.subtract(min).divide(step).intValue();
    // Math.min necessary because rounding error -> AIOOBE
    index = Math.min(index, breaks - 1);
    ret.set(index, ret.get(index) + 1);
  }
  return ret;
}

相关文章

Collections类方法