小编sal*_*rin的帖子

Java 流 - 将 int 数组映射并存储到 Set 中

我有一个 的数组[5, 6, 7, 3, 9],我想将数组中的每个元素减去 2,然后将其存储在 a 中Set,所以我所做的是

Set<Integer> mySet = Arrays.stream(arr1).map(ele -> new Integer(ele - 2)).collect(Collectors.toSet());
Run Code Online (Sandbox Code Playgroud)

但我在这里有两个例外

  1. The method collect(Supplier<R>, ObjIntConsumer<R>, BiConsumer<R,R>) in the type IntStream is not applicable for the arguments (Collector<Object,?,Set<Object>>)
  2. Type mismatch: cannot convert from Collector<Object,capture#1-of ?,Set<Object>> to Supplier<R>

这些错误是什么意思,我如何通过Java Stream操作解决这里的问题?

java collections java-stream

8
推荐指数
2
解决办法
154
查看次数

有没有办法使用 AWS CLI 按名称而不是 ID 从 AWS API Gateway 获取 API?

aws apigateway get-rest-api --rest-api-id <api_id> --> 为您提供了一个特定的 API,但我想知道是否有一种方法可以使用 cli 通过其名称获取 API aws

我已经尝试过这个命令但没有用。

aws apigateway get-rest-api --rest-api-name <api_name>
Run Code Online (Sandbox Code Playgroud)

api aws-cli aws-api-gateway

8
推荐指数
1
解决办法
5064
查看次数

API 网关授权方 - IAM 策略未缓存

我试图缓存授权方 lambda 在第一次验证 JWT 令牌时返回的 IAM 策略。我已在 API Gateway Authorizer 中启用并设置authorizerResultTtlInSeconds3500秒。但是,我仍然看到一个请求在缓存时间范围内发送到 Authorizer lambda 函数。

我的 node.js 脚本如下:

const jwt = require('jsonwebtoken');
const jwksClient = require('jwks-rsa');

const keyClient = jwksClient({
    jwksUri: process.env.JWKS_URI
})

const allow = {
    "principalId": "user",
    "policyDocument": {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Action": "execute-api:Invoke",
                "Effect": "Allow",
                "Resource": process.env.RESOURCE // RESOURCE = *
            }
        ]
    }
}

const unauthorized = {
    "error": "Unauthorized",
}

//excluded verificationJWTOptions object and getSigningKey function for simplicity
function validateJWTToken(token, …
Run Code Online (Sandbox Code Playgroud)

caching node.js aws-api-gateway lambda-authorizer

5
推荐指数
1
解决办法
963
查看次数

未找到依赖项 'org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE'

我在创建一个简单的spring bootWeb 应用程序时遇到问题。我正在使用 Intellij Idea IDE 构建这个应用程序。出现了与依赖相关的问题。Intellij 说 - Dependency 'org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE' not found(在pom.xml)。

详细错误信息:

Dependency 'org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE' not found.
Tag name: artifactId Description : The unique id for an artifact produced by the project group, e.g. maven-artifact. Version : 3.0.0+ 
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>springboot-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId> …
Run Code Online (Sandbox Code Playgroud)

java maven spring-boot

5
推荐指数
1
解决办法
6930
查看次数

这段代码的时间复杂度是O(n^2)还是O(nlogn)?

for (int i = 1; i <= n; i++) {
   for (int j = 1; j <= n; j += i) {
       // some code
   }
}
Run Code Online (Sandbox Code Playgroud)

外循环肯定会运行n多次。对于内循环,假设 n = 8,

j
1 1, 2, 3, 4, 5, 6, 7, 8 ---> 跑了N次
2 1, 3, 5, 7 ---> 运行 N/2 次
3 1, 4, 7
4 1, 5
5 1, 6
6 1, 7
7 1, 8
8 1

我很困惑复杂性应该是复杂性logn还是n内部循环。任何帮助将不胜感激!

algorithm big-o time-complexity

4
推荐指数
1
解决办法
117
查看次数

Java Stream - 在过滤器中抛出异常并返回一个列表

我创建了一个 Java 流:

List<Student> getStudentWithSameGrade(List<Student> students, Grade grade) {
    return students.stream().filter(s -> s.getGradeId().equals(grade.getGid())).collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)

上面的代码返回一个List<Student>满足filter检查但我想为不满足此检查的学生/学生列表抛出异常。我尝试做这样的事情,

return students.stream().filter(s -> s.getGradeId().equals(grade.getGid())).findAny()
                .orElseThrow(() -> new EntityNotFoundException(ENTITY_NOT_FOUND));
Run Code Online (Sandbox Code Playgroud)

但是,上面的代码片段返回的是单个学生对象而不是列表。我对这个Stream概念比较陌生,所以非常感谢这方面的帮助。

java lambda exception list java-stream

2
推荐指数
1
解决办法
105
查看次数