Java 8 List<V> into Map<K, V>

I want to translate a List of objects into a Map using Java 8's streams and lambdas. This is how I would write it in Java 7 and below. private Map<String, Choice> nameMap(List<Choice> choices) { final Map<String, Choice> hashMap = new HashMap<>(); for (final Choice choice : choices) { hashMap.put(choice.getName(), choice); }

Java 8将<V>列表映射到Map <K,V>中

我想使用Java 8的流和lambda表达式将对象列表转换为Map。 这就是我将如何在Java 7和以下编写它。 private Map<String, Choice> nameMap(List<Choice> choices) { final Map<String, Choice> hashMap = new HashMap<>(); for (final Choice choice : choices) { hashMap.put(choice.getName(), choice); } return hashMap; } 我可以使用Java 8和Guava轻

:: (double colon) operator in Java 8

I was exploring the Java 8 source and found this particular part of code very surprising: //defined in IntPipeline.java @Override public final OptionalInt reduce(IntBinaryOperator op) { return evaluate(ReduceOps.makeInt(op)); } @Override public final OptionalInt max() { return reduce(Math::max); //this is the gotcha line } //defined in Math.java public static int max(int a, int b) {

Java 8中的::(双冒号)运算符

我正在研究Java 8源代码,并发现这部分代码非常令人惊讶: //defined in IntPipeline.java @Override public final OptionalInt reduce(IntBinaryOperator op) { return evaluate(ReduceOps.makeInt(op)); } @Override public final OptionalInt max() { return reduce(Math::max); //this is the gotcha line } //defined in Math.java public static int max(int a, int b) { return (a >= b) ? a : b; } M

java immutable class much slower

I was in need of some Complex math library, so I hesitated between libraries that use immutable Complex and libraries that use mutable Complex. Obviously, I want computations to run reasonably fast (unless it kills readability etc.). So I created simple test of speed mutable vs immutable: final class MutableInt { private int value; public int getValue() { return value; }

java不可变类慢得多

我需要一些复杂的数学库,所以我犹豫在使用不可变复杂的库和使用可变复杂的库之间。 显然,我希望计算能够合理快速地运行(除非它杀死可读性等)。 所以我创建了速度可变vs不可变的简单测试: final class MutableInt { private int value; public int getValue() { return value; } public void setValue(int value) { this.value = value; } public MutableInt() { thi

Break in nested for loops

Possible Duplicate: How to Break from main/outer loop in a double/nested loop? I have the following situation: for(int i = 0; i < schiffe.length-1; i++){ if(schiffe[i].schaden){ schlepper.fliege(schiffe[i].x, schiffe[i].y, schiffe[i].z); schlepper.wirdAbgeschleppt = schiff

打破嵌套for循环

可能重复: 如何从双/嵌套循环中的主/外循环中断开? 我有以下情况: for(int i = 0; i < schiffe.length-1; i++){ if(schiffe[i].schaden){ schlepper.fliege(schiffe[i].x, schiffe[i].y, schiffe[i].z); schlepper.wirdAbgeschleppt = schiffe[i]; for(int k = 0; k < st

Android Microsoft dynamics CRM adal4j Login Issue

I'm using Microsoft aad:adal4j to handle the dynamics crm login from Mobile. After Implementing I am Getting the below Exception. What am I doing wrong? Error java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears

Android微软动态CRM adal4j登录问题

我正在使用Microsoft aad:adal4j来处理来自Mobile的动态crm登录。 实现后我正在获取下面的异常。 我究竟做错了什么? 错误 java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boo

How to avoid adding of inject method for each view?

Currently to get instance of for example Picasso in an activity, I need to add inject method to AppComponent. How to avoid adding of the inject method, because I have a lot of fragments and views where it should be injected: AppComponent.class: @ForApplication @Singleton @Component( modules = {AppModule.class,OkHttpClientModule.class,NetworkApiModule.class,NetworkAuthModule.class}) pu

如何避免为每个视图添加注入方法?

目前要在活动中获得例如毕加索的实例,我需要向AppComponent添加注入方法。 如何避免添加注入方法,因为我有很多的片段和视图应该注入它: AppComponent.class: @ForApplication @Singleton @Component( modules = {AppModule.class,OkHttpClientModule.class,NetworkApiModule.class,NetworkAuthModule.class}) public interface AppComponent { void inject(Fragment1 obj); void inject(Fragment2 obj);

Dagger 2 on Android. Different ways to store and access a @Singleton Component

This is the Nth question about how to store @Singleton scoped Dagger 2 Components whose lifetime should equal the application's lifetime. In Android apps using Dagger 2 there is usually at least one Component which is @Singleton scoped and should last for all the application's lifetime: because of these requirements it is usually initialised and stored inside a custom Application class.

Android上的Dagger 2。 存储和访问@Singleton组件的不同方式

这是关于如何存储@Singleton范围的Dagger 2组件的第N个问题,它的生存期应该等于应用程序的生命周期。 在使用Dagger 2的Android应用程序中,通常至少有一个Component是@Singleton范围的,并且应该持续所有应用程序的生命周期:由于这些需求,它通常被初始化并存储在自定义Application类中。 由于这个组件的实例必须在我们的应用程序的所有部分都可以访问,所以我看过这样的代码: 1.将组件存储在应用程序类中的公共静态变

Amazon MWS API: Some orders are missing when we download orders

I have implemented a system to download an Amazon seller's orders. The system works like this: we start off wanting to download orders from 12:00pm - 2:00pm, so I tell Amazon (via their Java client): "give me all orders from 12:02 to 2:00 (the two minute time difference is to accommodate pending orders as described by Amazon in their API). We fully download these orders: if there ar

亚马逊MWS API:我们下载订单时缺少一些订单

我已经实施了一个系统来下载亚马逊卖家的订单。 系统的工作原理是这样的: 我们开始希望从下午12:00到下午2:00下载订单,所以我告诉亚马逊(通过他们的Java客户端):“给我所有从12:02到2:00的订单(两分钟的时间差是为了容纳待定亚马逊在其API中描述的订单)。 我们完全下载这些订单:如果有超过一百个我们使用下一个标记,并且一旦我们拥有了它们,我们就使用每个订单上的listOrderItems操作来获取行项目。 其中一些订

Getting sequential logs while executing tests in parallel

We have been using testng with java to execute integration tests for our code. We have implemented a listener for the test execution as follows :- public class TestExecutionListener implements IInvokedMethodListener { @Override public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) { System.out.println("Testing : " + iInvokedMethod.getTestMethod().

并行执行测试时获取顺序日志

我们一直在使用testng和java来为我们的代码执行集成测试。 我们已经为测试执行实现了一个监听器 ,如下所示: - public class TestExecutionListener implements IInvokedMethodListener { @Override public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) { System.out.println("Testing : " + iInvokedMethod.getTestMethod().getMethodName()); } @Override

Finding a irreducible fraction

Given a positive integer n , it is asked to find the probability that one can pick two numbers A and B from the set [1...n] , such that the GCD of A and B is B . So my approach was to calculate number of pairs such that one is divisible by another. And the answer was expected to be in irreducible fraction form . EXAMPLE: 1 2 3 OUTPUT: 1/1 3/4 5/9 long n = sc.nextLong(); long sum=0; for(

找到一个不可简化的部分

给定一个正整数n ,它要求找到一个可以选择两个号码的概率A和B从集合[1...n]使得GCD的A和B是B 。 所以我的方法是计算一对可以被另一个整除的数量。 预计答案是不可简化的分数形式 。 例: 1 2 3 OUTPUT: 1/1 3/4 5/9 long n = sc.nextLong(); long sum=0; for(long i=1;i<=n/2;i++) sum+=(n/i)-1; long tot = n*n; sum+=n; long bro = hcf(tot,sum); sum/=bro; tot/=bro; System.out.print(sum+"/"+tot);