public List<List<Integer>> subsetsWithDup(int[] num) { Arrays.sort(num); return new ArrayList<>( IntStream.range(0, 1 << num.length) .mapToObj( mask -> IntStream.range(0, num.length) .filter(i -> ((1 << i) & mask) > 0) .map(i -> num[i]) .boxed() .collect(Collectors.toList())) .collect(Collectors.toSet())); }
void fun() { IntStream.range(1, 5) .map((x) -> x * x) .map( x -> square( x)) // Noncompliant [[sc=16;ec=18]] {{Replace this lambda with a method // reference.}} .map( x -> { // Noncompliant return square(x); }) .map(this::square) // Compliant .forEach(System.out::println); IntStream.range(1, 5).forEach(x -> System.out.println(x)); // Noncompliant IntStream.range(1, 5) .forEach( x -> { // Noncompliant System.out.println(x); }); IntStream.range(1, 5) .forEach( x -> { return; }); // Compliant Arrays.asList("bar").stream().filter(string -> string.startsWith("b")); // Compliant Arrays.asList(new A()).stream().filter(a -> a.coolerThan(0, a)); // Compliant foo((x, y) -> x * y); foo( (x, y) -> {; }); foo( (x, y) -> {;; }); }
public void requestExamples() { // #ws-holder WSRequest request = ws.url("http://example.com"); // #ws-holder // #ws-complex-holder WSRequest complexRequest = request .setHeader("headerKey", "headerValue") .setRequestTimeout(1000) .setQueryParameter("paramKey", "paramValue"); // #ws-complex-holder // #ws-get CompletionStage<WSResponse> responsePromise = complexRequest.get(); // #ws-get String url = "http://example.com"; // #ws-auth ws.url(url).setAuth("user", "password", WSAuthScheme.BASIC).get(); // #ws-auth // #ws-follow-redirects ws.url(url).setFollowRedirects(true).get(); // #ws-follow-redirects // #ws-query-parameter ws.url(url).setQueryParameter("paramKey", "paramValue"); // #ws-query-parameter // #ws-header ws.url(url).setHeader("headerKey", "headerValue").get(); // #ws-header String jsonString = "{\"key1\":\"value1\"}"; // #ws-header-content-type ws.url(url).setHeader("Content-Type", "application/json").post(jsonString); // OR ws.url(url).setContentType("application/json").post(jsonString); // #ws-header-content-type // #ws-timeout ws.url(url).setRequestTimeout(1000).get(); // #ws-timeout // #ws-post-form-data ws.url(url) .setContentType("application/x-www-form-urlencoded") .post("key1=value1&key2=value2"); // #ws-post-form-data // #ws-post-json JsonNode json = Json.newObject().put("key1", "value1").put("key2", "value2"); ws.url(url).post(json); // #ws-post-json String value = IntStream.range(0, 100).boxed().map(i -> "abcdefghij").reduce("", (a, b) -> a + b); ByteString seedValue = ByteString.fromString(value); Stream<ByteString> largeSource = IntStream.range(0, 10).boxed().map(i -> seedValue); Source<ByteString, ?> largeImage = Source.from(largeSource.collect(Collectors.toList())); // #ws-stream-request CompletionStage<WSResponse> wsResponse = ws.url(url).setBody(largeImage).execute("PUT"); // #ws-stream-request }