标签: apache-commons

向 java 添加新库

我正在尝试使用Apache Commons中名为 StringUtils 的功能。但是,这需要您下载库并添加它,以便我可以使用该代码import org.apache.commons.lang3.StringUtils;。我的问题是我不确定将其添加到哪里,以便我可以在命令提示符下编译我的程序。我也不知道应该将哪些文件添加到所需的文件夹中。

任何帮助将不胜感激。

java apache-commons

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

将域添加到 apache.commons 中的 UrlValidator

所以我正在使用 Commons UrlValidator (org.apache.commons.validator.routines.UrlValidator),我想知道是否有一种方法可以自定义它允许的域。现在似乎只允许 TLD,但我希望有一两个有效的名称不在该列表中,例如“.corp”(列表可在此处找到:http://data.iana.org/TLD/tlds-alpha -by-domain.txt)。是否有一种设置或解决方法,以便我不必创建自己的 url 验证器,并且可以将其与添加的域一起使用?

java url apache-commons url-validation

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

将 Collection<myClass> 转换为 Collection<String>

我尝试实现类似于CollectionUtils 转换(Apache Commons Collections)的功能

class CollectionUtils {

    public static void transformerModifier(Collection<MyClass> myCollection) {
        // How should I implement this method in order that 
        // output from the line 1 and line 2 will be the same ? 
    }

    public static List<String> transform(Collection<MyClass> myCollection) {
        List<String> strCollection = new LinkedList<>();
        for (MyClass item : myCollection) {
            strCollection.add(item.getName());
        }
        return strCollection;
    }
}
Run Code Online (Sandbox Code Playgroud)

class myClass { 
    private String name; 
    private int value; 

    myClass( String name, int value) {
        this.name = name …
Run Code Online (Sandbox Code Playgroud)

java collections anonymous-class apache-commons

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

ClassNotFoundException:org.apache.commons.javaflow.core.StackRecorder

填写 Jasper 报告时,出现以下异常:

java.lang.ClassNotFoundException: org.apache.commons.javaflow.core.StackRecorder
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:162)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:145)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:689)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:670)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:992)
Run Code Online (Sandbox Code Playgroud)

我已经添加了commons-javaflowhttps://search.maven.org/#search%7Cga%7C1%7Ca%3A%22commons-javaflow%22) - 但这没有帮助。哪里可以找到这个类?

编辑:对重复问题标签的一条评论:这不是关于 ClassNotFoundException 的一般问题 - 这是关于 Jasper-Reports / Apache Commons JavaFlow 的特殊问题。所以请拿走这个标签。

java jasper-reports apache-commons

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

PassiveExpiringMap 不使对象过期

我期待 org.apache.commons.collections4.map.PassiveExpiringMap 能够开箱即用。不幸的是,在对象按时过期的最明显用例中,它对我不起作用。下面的代码创建了 5 秒的过期策略。测试等待 10 秒,这是所有地图对象应过期并删除的时间。但他们不是。

import org.apache.commons.collections4.map.PassiveExpiringMap;
import org.junit.Assert;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
    
public class PassiveExpiringMapTest {
    @Test
    public void givenDataMap_whenWrappingMapWithPassiveExpiringMap_thenObjectsAreRemovedWhenExpired() {
        
        final Map<String, Integer> m = new HashMap<>();
        m.put("one", Integer.valueOf(1));
        m.put("two", Integer.valueOf(2));
        m.put("three", Integer.valueOf(3));

        PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<String, Integer>
            expirationPolicy = new PassiveExpiringMap.ConstantTimeToLiveExpirationPolicy<>(
            5, TimeUnit.SECONDS);

        PassiveExpiringMap<String, Integer> expiringMap = new PassiveExpiringMap<>(expirationPolicy, m);

        int initialCapacity = expiringMap.size();
        System.out.println("initialCapacity = " + initialCapacity);
        Assert.assertEquals(3, initialCapacity);

        System.out.println("Sleeping...");
        try { Thread.sleep(10000L); } catch (InterruptedException e) { }

        int updatedCapacity = …
Run Code Online (Sandbox Code Playgroud)

java collections apache-commons

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

如何:将字节数组转换为InputStream

与Apache共享它是非常简单转换InputStreambyte[],

static byte[] toByteArray(InputStream input)

但我找不到相反的方法.将字节数组转换为InputStream对象的最流行/最直接的方法是什么?

提前致谢.

java io bytearray inputstream apache-commons

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

Java中的数字到数字转换的对象.常见库中的任何方法?

我们的项目使用google guava,apache commons以及其他具有常见任务的库,我想知道这些库是否包含进行空安全转换的方法(对象编号,对象到字符串).至于现在我给自己写了一些辅助方法,例如:

int parseInteger(Object obj) {
        if (obj!= null) {
            if (obj instanceof Integer) return (Integer) obj;
            if (obj instanceof Long) return ((Long) obj).intValue();
            return Integer.parseInt(obj.toString());
        } else {
            return 0;
        }
    }
Run Code Online (Sandbox Code Playgroud)

java apache-commons guava

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

StringEscapeUtils查明字符串是否被转义

我一直在使用StringEscapeUtils.escapeHTML来转义URL.是否有类似的东西可以找出字符串是否已被转义?

java string escaping apache-commons

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

使用Class.getResourcesAsStream获取Apache Commons配置

填充java.util.Properties对象的理想方法似乎是使用一些变体

properties.load(ClassLoader.getSystemClassLoader().getResourcesAsStream(String className));
Run Code Online (Sandbox Code Playgroud)

最重要的想法是指向Properties.load类的InputStream,而不是路径.

如何使用org.apache.commons.configuration.Configuration

java configuration class apache-commons

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

如何通过检查长度和比较Java中的文本从数组中删除String?

如何通过检查长度和比较Java中的文本从数组中删除String?

假设用户搜索"Hi Tonki with Monkey"

String[] pattern = userSearchString.toLowerCase().split("\\s");
Run Code Online (Sandbox Code Playgroud)

1)我们想从模式中删除"With"

2)也想删除小于3的图案,如"Hi".

因此模式应仅包含Tonki和Monkey.

如果有人可以从Apache Commons或Guava建议方法,那将是很好的.

使用Java 1.6

java arrays apache-commons guava

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