returning LinkedHashMap from IntStream, Java 8

前端 未结 1 413
滥情空心
滥情空心 2020-12-07 04:48

I have this code.

  private static Map> alternativeMethod(AudioFormat audioformat, 
      List listChu         


        
相关标签:
1条回答
  • 2020-12-07 05:35

    Does this work for you?

    public static Map<Long, List<TimePitchValue>> alternativeMethodme(
            AudioFormat audioformat, List<ChunkDTO> listChunkDTO,
            long index, int sizeChunk) {
    
        int numBytesPerSample = audioformat.getSampleSizeInBits() / 8;
        int quantitySamples = sizeChunk / numBytesPerSample;
        long baseTime = quantitySamples * index;
    
        return IntStream.range(0, quantitySamples).boxed()
                .collect(Collectors.toMap(time -> baseTime + time,
                        time -> listChunkDTO.stream()
                                .map(chunkDTO -> new TimePitchValue(
                                        chunkDTO.getPitch(),
                                        baseTime + time,
                                        extractValue(
                                                chunkDTO.getChunk(),
                                                numBytesPerSample,
                                                time)))
                                .sorted(Comparator.comparingInt(
                                        TimePitchValue::getValue)
                                        .reversed())
                                .collect(Collectors.toList()),
                                (a,b)->a,
                                LinkedHashMap::new));
    }
    

    I think I finally figure this out. I had to do some rearanging of methods and such.

    Updated. I added the sort and returned the map as a LinkedHashMap

    0 讨论(0)
提交回复
热议问题