我正在项目android中使用此哈希图。
使用此命令:
@Configuration
@EnableKafka
public class ConsumerConfig {
@Value("${kafka.bootstrap-servers}")
private String bootstrapServers;
@Value("${kafka.group-id}")
private String groupId;
/**
* Configuration of Consumer properties.
*
* @return
*/
//@Bean
public Map<String, Object> consumerConfigs() {
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
return props;
}
//@Bean
public ConsumerFactory<String, ClassA> consumerFactory1() {
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new StringDeserializer(),
new ClassA());
}
/**
* Kafka Listener Container Factory.
* @return
*/
@Bean("kafkaListenerContainerFactory1")
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, ClassA>> kafkaListenerContainerFactory1() {
ConcurrentKafkaListenerContainerFactory<String, ClassA> factory;
factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory1());
return factory;
}
//@Bean
public ConsumerFactory<String, ClassB> consumerFactory2() {
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new StringDeserializer(),
new ClassB());
}
/**
* Kafka Listener Container Factory.
* @return
*/
@Bean("kafkaListenerContainerFactory2")
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, ClassB>> kafkaListenerContainerFactory2() {
ConcurrentKafkaListenerContainerFactory<String, ClassB> factory;
factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory2());
return factory;
}
@Bean
public ReceiverClass receiver() {
return new ReceiverClass();
}
class ReceiverClass {
@KafkaListener(topics = "topic1", group = "group-id-test",
containerFactory = "kafkaListenerContainerFactory1")
public void receiveTopic1(ClassA a) {
System.out.println("ReceiverClass.receive() ClassA : " + a);
}
@KafkaListener(topics = "topic2", group = "group-id-test",
containerFactory = "kafkaListenerContainerFactory2")
public void receiveTopic2(ClassB b) {
System.out.println("ReceiverClass.receive() Classb : " + b);
}
}
class ClassB implements Deserializer {
@Override
public void configure(Map configs, boolean isKey) {
// TODO Auto-generated method stub
}
@Override
public Object deserialize(String topic, byte[] data) {
// TODO Auto-generated method stub
return null;
}
@Override
public void close() {
// TODO Auto-generated method stub
}
}
class ClassA implements Deserializer {
@Override
public void configure(Map configs, boolean isKey) {
// TODO Auto-generated method stub
}
@Override
public Object deserialize(String topic, byte[] data) {
// TODO Auto-generated method stub
return null;
}
@Override
public void close() {
// TODO Auto-generated method stub
}
}
}
其中test1是:
List<Map<Integer, Double>> peak = PeakDetect.peak_detection(test1,delta, indices);
我有这个结果:
double [] test1= {16 ,1, 2, -20, 3, 12, 2, 1, 0, -1, -2 ,-3, -6, -3, -2 ,-1, 0};
在该示例中,我希望将第一个索引存储在新数组中:
Result: [{0=0.14692041925343213, 5=0.28567859299278475}, {3=0.4244367667321373}]
0和5表示test1的最大值,3表示test1的最小值。
我该怎么做?在此先感谢
修改 这是peak_detector.java:
0 and 5
答案 0 :(得分:0)
像这样吗?
List<List<Integer>> indexes = peaks
.stream()
.map(p -> p.entrySet()
.stream()
.map(Map.Entry::getKey)
.collect(Collectors.toList()))
.collect(Collectors.toList());
System.out.println(indexes.get(0)); // maxima list output = [0, 5]
System.out.println(indexes.get(1)); // minima list output = [3]