小编azu*_*rog的帖子

在Java中比较2个x509证书

已为我提供了字节数组和X509证书。我可以使用以下代码从字节数组生成X509证书。

CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(bytes);
X509Certificate cert = (X509Certificate)certificatefactory.generateCertificate(in);
Run Code Online (Sandbox Code Playgroud)

请指导我如何验证提供给我的X509与生成的X509。

java bytearray certificate x509certificate

3
推荐指数
2
解决办法
2156
查看次数

JAVA:ImmutableSet作为List

我目前从函数调用(getFeatures())返回一个ImmutableSet,并且由于我稍后要执行的其余代码的结构 - 将其更改为List会更容易.我试图将其转换为产生运行时异常.我也四处寻找函数调用将其转换为列表无济于事.有没有办法做到这一点?我最近的[失败]尝试如下所示:

ImmutableSet<FeatureWrapper> wrappersSet =  getFeatures();
List<FeatureWrapper> wrappers = (List<FeatureWrapper>) wrappersSet;
Run Code Online (Sandbox Code Playgroud)

我找到了wrapperSet.asList(),它会给我一个ImmutableList但是我更喜欢一个可变列表

java list immutable-collections

3
推荐指数
2
解决办法
2602
查看次数

检查数组是否包含Java值的最有效方法?

我对Java类中的方法有一个类似的逻辑(不是真正的代码,为了示例目的,这是简化的).

private Boolean method(Boolean booleanValue, SomeObject object) {
  return booleanValue ? Arrays.asList(object.getStringsArray()).contains("string") : false;
}
Run Code Online (Sandbox Code Playgroud)

指派自己检查PR的合作者给出了以下评论:

这是低效的.它正在创建一个新的数据结构,只是迭代它并检查是否有某个字符串.

getStringsArray()方法返回一个String[],所以使用for循环会比Arrays.asList()

哪种方式更有效地实现这一目标?

java list data-structures

3
推荐指数
1
解决办法
2838
查看次数

如何通过在数组中只引用它来使对象为null?

我在GameWorld中有一系列游戏对象,他们可以从那个世界中删除.问题是某些游戏对象引用了其他游戏对象.例如,Player类引用了Bird.Bird会从GameWorld中随机删除,但Player仍然会引用它.我目前进行空检查以检查GameObject是否仍然有效并且在世界上.但是,从数组中删除对象不会使该引用为null.那我怎么能把它变成空?

这是一个例子:

// GameWorld creates bird
ArrayList<Object> gameObjects = new ArrayList<>();
Object bird = new Object();
gameObjects.add(bird);

// Player references it
Object referencedBird = gameObjects.get(0);

// later in GameWorld, another scope, there is no access to the 'bird' object, trying to remove the bird from the world
Object objectToRemove = gameObjects.get(0);
gameObjects.remove(0);
objectToRemove = null;

// back in the Player class
Debug.log("is null " + (referencedBird == null)); // false! I need it to be true
Run Code Online (Sandbox Code Playgroud)

java arrays null reference object

3
推荐指数
1
解决办法
63
查看次数

两个重载方法,相同的操作,导致重复的代码

我有两种方法可以采用a Circle或a,Scene并通过fill每N ms 更改一次使背景闪烁红 - 绿 - 蓝.

这两种方法:

private void makeRGB(Circle c) {
    Timer t = new Timer();
    t.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            if(c.getFill() == Color.RED) {
                c.setFill(Color.GREEN);
            } else if (c.getFill() == Color.GREEN) {
                c.setFill(Color.BLUE);
            } else {
                c.setFill(Color.RED);
            }
        }
    },0, RGB_CHANGE_PERIOD);
}

private void makeRGB(Scene s) {
    Timer t = new Timer();
    t.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            if(s.getFill() == Color.RED) {
                s.setFill(Color.GREEN);
            } else if …
Run Code Online (Sandbox Code Playgroud)

java javafx javafx-8

3
推荐指数
1
解决办法
98
查看次数

ClassNotFoundException:com.mysql.jdbc.jdbc2.optional.MysqlDataSource

我在我的项目中使用Hikari库进行MySQL连接.当我尝试运行该程序时,我得到一个ClassNotFoundException:com.mysql.jdbc.jdbc2.optional.MysqlDataSource错误.我想我必须在我的项目中包含mysql-connector库.

这是我的pom.xml

    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP-java6</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.18.1-GA</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.0.Beta3</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>GridControl</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Main-Class>net.thegridmc.control.GridControl</Main-Class>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <minimizeJar>true</minimizeJar>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <artifactSet>
                                <includes>
                                    <include>mysql:*</include>
                                    <include>org.slf4j:*</include>
                                    <include>com.zaxxer:*</include>
                                    <include>org.javassist:javassist</include>
                                    <include>io.netty:netty-all</include>
                                </includes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
Run Code Online (Sandbox Code Playgroud)

jar已成功构建,但仍会出现错误.非常感谢任何帮助.谢谢.

java mysql jdbc maven

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

任何人都可以告诉我为什么我的旧列表中只有新列表中应该存在的所有值.

  1. 我在tmp中存储一个列表,然后在列表中添加新值.
  2. 刷新时我将旧列表与新列表进行比较.
  3. 如果新列表有新条目然后生成通知,但每次我在旧列表中找到所有值.

    public void populateList(String result) {
        ArrayList<User> tmp;
        tmp = list;
        list.clear();
        try {
            JSONArray jsonArray = new JSONArray(result);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject json_data = jsonArray.getJSONObject(i);
                String NAME = json_data.getString(StaticMember.NAME);
                String STATUS = json_data.getString(StaticMember.STATUS);
                list.add(new User(NAME, STATUS));
            }
            ArrayList tmpN = list;
            compare(tmp, tmpN);
            CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, list);
            lv.setAdapter((customAdapter));
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void compare(ArrayList list_old, ArrayList list_new) {
        try {
            Iterator<User> iterator_old …
    Run Code Online (Sandbox Code Playgroud)

java android iterator arraylist

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

在Java中将String转换为Date会增加一些额外的时间

我在Java中将字符串转换为Date,但是我遇到了问题它在结果Date中添加了一些额外的分钟.

字符串具有以下格式"yyyy-MM-dd HH:mm:ss.sss"并且我已创建此函数:

public static Date parseISO8601(String date) {
    Date result = null;

    try {

        if (!TextUtils.isEmpty(date)) {
            SimpleDateFormat dateFormat = new SimpleDateFormat(
                    ISO8601_DATE_FORMAT);

            result = dateFormat.parse(date);
        }

    }
    catch (Exception ex){
        return null;
    }
    return result;
}

public static final String ISO8601_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.sss";
Run Code Online (Sandbox Code Playgroud)

当我使用此字符串 "2015-06-11 20:17:56.873"时,结果是"Thu Jun 11 20:31:33 CST 2015".我是Java的新编码,我已经阅读了很多帖子,但对我而言,一切似乎都很正常,我不知道为什么会发生这种情况.

一些想法?

java date

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

java队列接口

我正在查看 java 队列,我坚持这一行“队列实现通常不定义 equals 和 hashCode 方法的基于元素的版本,而是从 Object 继承基于身份的版本。

1.需要以上文字的完整意思。
2.什么是equals和hashcode的基于元素的版本——它指的是什么?
3.基于身份的版本——这是什么意思?
4. 版本是属于类还是对象/谁的版本以及它将在哪里?

网址:https : //docs.oracle.com/javase/tutorial/collections/interfaces/queue.html

java queue interface

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

部分匹配的可能解决方案(至少 n 个字段中的 p 个匹配)

我正在寻找部分匹配/可能匹配的可能解决方案(至少 n 个字段中的 p 个匹配)。

我们有一个数据库(Oracle),其中填充了个人记录,如下所示:

  • 名,
  • 姓,
  • 生日,
  • 公民号,
  • 市民广场,
  • 出生地,
  • 另一个号码,
  • 区。

(*) 请记住,没有唯一标识符,并非所有字段都可以提供,某些字段可能是可选的(空)。

如果 8 个字段中至少有 5 个匹配,我们正在寻找一种解决方案来根据数据库记录检查给定人员。

是否有可能使用 SQL、SQL/Java 的解决方案,或者我们应该寻找 nosql 或弹性搜索解决方案?

先感谢您。

java sql oracle

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