当前位置: 首页>>代码示例>>Java>>正文


Java Collections.max方法代码示例

本文整理汇总了Java中java.util.Collections.max方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.max方法的具体用法?Java Collections.max怎么用?Java Collections.max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Collections的用法示例。


在下文中一共展示了Collections.max方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.util.Collections; //导入方法依赖的package包/类
public static void main(String[] args) {

    //create an ArrayList object
    ArrayList arrayList = new ArrayList();

    //Add elements to Arraylist
    arrayList.add(new Integer("327482"));
    arrayList.add(new Integer("13408"));
    arrayList.add(new Integer("802348"));
    arrayList.add(new Integer("345308"));
    arrayList.add(new Integer("509324"));

    /*
       To find maximum element of Java ArrayList use,
       static Object max(Collection c) method of Collections class.

       This method returns the maximum element of Java ArrayList according to
       its natural ordering.
    */

    Object obj = Collections.max(arrayList);

    System.out.println("Maximum Element of Java ArrayList is : " + obj);
  }
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:25,代码来源:FindMaximumOfArrayListExample.java

示例2: setData

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Sets data for calendar months
 *
 * @param calendarData array of data containing values from January to December
 */
public void setData(ArrayList<Integer> calendarData) {
    mCalendarData = calendarData;

    int currentMonth = mStartMonth;
    int monthOrdinal = 0;
    int maxLevel = Collections.max(calendarData);
    while (monthOrdinal < 12 && monthOrdinal < mCalendarMonthViews.size()) {
        CalendarMonth calendarMonth = mCalendarMonthViews.get(monthOrdinal);
        if (mCalendarData.size() > currentMonth) {
            calendarMonth.setMonth(currentMonth, mCalendarData.get(currentMonth), maxLevel);
        } else {
            calendarMonth.setMonth(currentMonth, 0, 0);
        }
        currentMonth++;
        if (currentMonth == 12) {
            currentMonth = 0;
        }
        monthOrdinal++;
    }
    mCalendarData = calendarData;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:27,代码来源:GameCalendar.java

示例3: as_dict

import java.util.Collections; //导入方法依赖的package包/类
public Map<String, List<String>> as_dict() {
  Map<String, List<String>> job_tasks_map = new HashMap<String, List<String>>();
  String job_name;
  List<String> jobs = this.jobs();
  for (int i = 0; i < jobs.size(); i++) {
    job_name = jobs.get(i);
    List<Integer> task_indices = this.task_indices(job_name);
    if (Collections.max(task_indices) + 1 == task_indices.size()) //the tasks indices are dense
    {
      job_tasks_map.put(job_name, this.job_tasks(job_name));
    } else //the tasks indices are not dense, manually make the list dense
    {
      List<String> tasks = new ArrayList<String>();
      Integer task_index;
      for (int j = 0; j < task_indices.size(); j++) {
        task_index = task_indices.get(j);
        tasks.add(this.task_address(job_name, task_index));

      }
    }
  }
  return job_tasks_map;
}
 
开发者ID:Intel-bigdata,项目名称:TensorFlowOnYARN,代码行数:24,代码来源:ClusterSpec.java

示例4: chooseOptimalSize

import java.util.Collections; //导入方法依赖的package包/类
public static Size chooseOptimalSize(List<Size> choices, int width, int height, Size aspectRatio) {
    List<Size> bigEnough = new ArrayList<>();
    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    for (int a = 0; a < choices.size(); a++) {
        Size option = choices.get(a);
        if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= width && option.getHeight() >= height) {
            bigEnough.add(option);
        }
    }
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizesByArea());
    } else {
        return Collections.max(choices, new CompareSizesByArea());
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:17,代码来源:CameraController.java

示例5: right

import java.util.Collections; //导入方法依赖的package包/类
public double right() {
    if (isTile()) {
        return x2;
    } else {
        return Collections.max(Arrays.asList(x1, x2, x3, x4));
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:8,代码来源:Rectangle.java

示例6: test

import java.util.Collections; //导入方法依赖的package包/类
private void test(int length) {
    List<Integer> values = StreamUtil.sequence(length);
    final Integer max = Collections.max(values);
    assertTracksMax(values);

    IntStream.range(0, N)
            .forEach(n -> {
                Collections.shuffle(values);
                StackWithMax stack = createStack(values);
                Assert.assertEquals(max, stack.max());
            });
}
 
开发者ID:gardncl,项目名称:elements-of-programming-interviews,代码行数:13,代码来源:StackWithMaxTest.java

示例7: toString

import java.util.Collections; //导入方法依赖的package包/类
public String toString() {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i <= Collections.max(tyHi.keySet()); i++) {
        System.out.println("spec: " + i);
        for (Type type : tyHi.get(i)) {
            System.out.println(type.toString());
        }
        System.out.println();
    }
    return sb.toString();
}
 
开发者ID:spetitjean,项目名称:TuLiPA-frames,代码行数:12,代码来源:TypeHierarchy.java

示例8: hentNyesteJobbsokerKartlegging

import java.util.Collections; //导入方法依赖的package包/类
public JobbsokerKartlegging hentNyesteJobbsokerKartlegging(String aktorId) {
    List<JobbsokerKartlegging> jobbsokerKartlegginger = hentJobbsokerKartlegginger(aktorId);
    return Collections.max(jobbsokerKartlegginger, new Comparator<JobbsokerKartlegging>() {
        @Override
        public int compare(JobbsokerKartlegging o1, JobbsokerKartlegging o2) {
            return o1.getLagretTidspunkt().compareTo(o2.getLagretTidspunkt());
        }
    });
}
 
开发者ID:navikt,项目名称:fo-veilarbjobbsokerkompetanse,代码行数:10,代码来源:JobbsokerKartleggingDAO.java

示例9: testFileDistributionCalculator

import java.util.Collections; //导入方法依赖的package包/类
@Test
public void testFileDistributionCalculator() throws IOException {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  PrintStream o = new PrintStream(output);
  new FileDistributionCalculator(new Configuration(), 0, 0, o)
      .visit(new RandomAccessFile(originalFsimage, "r"));
  o.close();

  String outputString = output.toString();
  Pattern p = Pattern.compile("totalFiles = (\\d+)\n");
  Matcher matcher = p.matcher(outputString);
  assertTrue(matcher.find() && matcher.groupCount() == 1);
  int totalFiles = Integer.parseInt(matcher.group(1));
  assertEquals(NUM_DIRS * FILES_PER_DIR, totalFiles);

  p = Pattern.compile("totalDirectories = (\\d+)\n");
  matcher = p.matcher(outputString);
  assertTrue(matcher.find() && matcher.groupCount() == 1);
  int totalDirs = Integer.parseInt(matcher.group(1));
  // totalDirs includes root directory
  assertEquals(dirCount + 1, totalDirs);

  FileStatus maxFile = Collections.max(writtenFiles.values(),
      new Comparator<FileStatus>() {
    @Override
    public int compare(FileStatus first, FileStatus second) {
      return first.getLen() < second.getLen() ? -1 :
          ((first.getLen() == second.getLen()) ? 0 : 1);
    }
  });
  p = Pattern.compile("maxFileSize = (\\d+)\n");
  matcher = p.matcher(output.toString("UTF-8"));
  assertTrue(matcher.find() && matcher.groupCount() == 1);
  assertEquals(maxFile.getLen(), Long.parseLong(matcher.group(1)));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:36,代码来源:TestOfflineImageViewer.java

示例10: choosePreferredSize

import java.util.Collections; //导入方法依赖的package包/类
private static Camera.Size choosePreferredSize(List<Camera.Size> sizes,double aspectRatio) {
    List<Camera.Size> options = new ArrayList<>();
    for (Camera.Size option : sizes) {
        if(option.width==1280 && option.height==720)
            return option;
        if (Math.abs((int)(option.height * aspectRatio)-option.width)<10) {
            options.add(option);
        }
    }
    if (options.size() > 0) {
        return Collections.max(options, new CompareSizesByArea());
    } else {
        return sizes.get(sizes.size()-1);
    }
}
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:16,代码来源:CameraEngine.java

示例11: chooseOptimalSize

import java.util.Collections; //导入方法依赖的package包/类
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth,
                                      int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) {

    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<>();
    // Collect the supported resolutions that are smaller than the preview Surface
    List<Size> notBigEnough = new ArrayList<>();
    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    for (Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight &&
                option.getHeight() == option.getWidth() * h / w) {
            if (option.getWidth() >= textureViewWidth &&
                    option.getHeight() >= textureViewHeight) {
                bigEnough.add(option);
            } else {
                notBigEnough.add(option);
            }
        }
    }

    // Pick the smallest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        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");
        return choices[0];
    }
}
 
开发者ID:raulh82vlc,项目名称:Image-Detection-Samples,代码行数:33,代码来源:FDCamera2Presenter.java

示例12: prepareGreenIndexSlots

import java.util.Collections; //导入方法依赖的package包/类
private void prepareGreenIndexSlots() {
    double max = Collections.max(_greenIndices.values());
    double min = Collections.min(_greenIndices.values());
    double step = (max - min) / TOTAL_LEVEL;
    // Divide the range of raw green index values into TOTAL_LEVEL,
    // then map the raw value to [0..TOTAL_LEVEL - 1]
    for (byte i = 0; i < TOTAL_LEVEL; i++) {
        _slots.put(i, new SlotRange(min + i * step, min + (i + 1) * step));
    }
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:11,代码来源:GreenIndexGraphStorageBuilder.java

示例13: chooseOptimalSize

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
 * is at least as large as the respective texture view size, and that is at most as large as the
 * respective max size, and whose aspect ratio matches with the specified value. If such size
 * doesn't exist, choose the largest one that is at most as large as the respective max size,
 * and whose aspect ratio matches with the specified value.
 *
 * @param choices           The list of sizes that the camera supports for the intended output
 *                          class
 * @param textureViewWidth  The width of the texture view relative to sensor coordinate
 * @param textureViewHeight The height of the texture view relative to sensor coordinate
 * @param maxWidth          The maximum width that can be chosen
 * @param maxHeight         The maximum height that can be chosen
 * @param aspectRatio       The aspect ratio
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth,
                                      int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) {

    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<>();
    // Collect the supported resolutions that are smaller than the preview Surface
    List<Size> notBigEnough = new ArrayList<>();
    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    for (Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight &&
                option.getHeight() == option.getWidth() * h / w) {
            if (option.getWidth() >= textureViewWidth &&
                    option.getHeight() >= textureViewHeight) {
                bigEnough.add(option);
            } else {
                notBigEnough.add(option);
            }
        }
    }

    // Pick the smallest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        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");
        return choices[0];
    }
}
 
开发者ID:neural-nuts,项目名称:Cam2Caption,代码行数:49,代码来源:Camera2BasicFragment.java

示例14: sparseMax

import java.util.Collections; //导入方法依赖的package包/类
/**
 * @param matrixUuid Matrix UUID.
 * @return Maximum value obtained using sparse logic.
 */
@SuppressWarnings("unchecked")
public static <K, V> double sparseMax(UUID matrixUuid, String cacheName) {
    A.notNull(matrixUuid, "matrixUuid");
    A.notNull(cacheName, "cacheName");

    Collection<Double> maxes = fold(cacheName, (CacheEntry<K, V> ce, Double acc) -> {
        V v = ce.entry().getValue();

        double max;

        if (v instanceof Map) {
            Map<Integer, Double> map = (Map<Integer, Double>)v;

            max = Collections.max(map.values());
        }
        else if (v instanceof MatrixBlockEntry) {
            MatrixBlockEntry be = (MatrixBlockEntry)v;

            max = be.maxValue();
        }
        else
            throw new UnsupportedOperationException();

        if (acc == null)
            return max;
        else
            return Math.max(acc, max);

    }, sparseKeyFilter(matrixUuid));

    return Collections.max(maxes);
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:37,代码来源:CacheUtils.java

示例15: novo

import java.util.Collections; //导入方法依赖的package包/类
@GetMapping("/rest/pedido/novo/{clienteId}/{listaDeItens}")
public RespostaDTO novo(@PathVariable("clienteId") Long clienteId,@PathVariable("listaDeItens") String listaDeItens) {

	RespostaDTO dto = new RespostaDTO();

	try {
		Cliente c = clienteRepository.findOne(clienteId);

		String[] listaDeItensID = listaDeItens.split(",");

		Pedido pedido = new Pedido();

		double valorTotal = 0;
		List<Item> itensPedidos = new ArrayList<Item>();

		for (String itemId : listaDeItensID) {
			Item item = itemRepository.findOne(Long.parseLong(itemId));
			itensPedidos.add(item);
			valorTotal += item.getPreco();
		}
		pedido.setItens(itensPedidos);
		pedido.setValorTotal(valorTotal);
		pedido.setData(new Date());
		pedido.setCliente(c);
		c.getPedidos().add(pedido);

		this.clienteRepository.saveAndFlush(c);
		
		enviaNotificacao.enviaEmail(c,pedido);
		
		List<Long> pedidosID = new ArrayList<Long>();
		for (Pedido p : c.getPedidos()) {
			pedidosID.add(p.getId());
		}

		Long ultimoPedido = Collections.max(pedidosID);

		dto = new RespostaDTO(ultimoPedido,valorTotal,"Pedido efetuado com sucesso");

	} catch (Exception e) {
		dto.setMensagem("Erro: " + e.getMessage());
	}
	return dto;

}
 
开发者ID:boaglio,项目名称:spring-boot-greendogdelivery-casadocodigo,代码行数:46,代码来源:NovoPedidoController.java


注:本文中的java.util.Collections.max方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。