标签: apache-commons-collection

Java综合列表

我正在寻找一个具有复合列表实现的开源库.我需要一个列表,从其他列表中读取其值,并可以构造如下:

List list1 = new ArrayList();
list1.add("0");
List list2 = new LinkedList();
list2.add("1");
list3.add("2");
List list3 = new CompositeList(list1, list2...)
Run Code Online (Sandbox Code Playgroud)然后:
assertEquals("0", list3.get(0));
assertEquals("1", list3.get(1));
assertEquals("2", list3.get(2));
Run Code Online (Sandbox Code Playgroud) 我的想法是,我不需要复制源列表中的所有内容.

一个快速的谷歌没有找到任何东西,我没有在番石榴或公共收藏中看到它(我可能忽略了它).我现在没有足够的时间正确实施它.

java collections guava apache-commons-collection

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

Java:Commons-Collections泛型:如何使自定义变换器工作

嗨,我正在使用commons集合泛型4.01.

我有一个dto对象.

Class PricingDto {
   private Double tax;
   private Double price;
   private Double tip;

   // getters and setters
}
Run Code Online (Sandbox Code Playgroud)

我有一份清单 List<PricingDto> pricingDtos = this.pricingService.getAllPricings();

比我有一个私人静态类.

import org.apache.commons.collections15.Transformer;
import org.apache.commons.collections15.list.TransformedList;

class TotalServiceImpl implements TotalService {
    public static final PricingDtoTransformer PRICING_DTO_TRANSFORMER =
        new PricingDtoTransformer();
    private static class PricingDtoTransformer
        implements Transformer<PricingDto, Double> {
        public PricingDtoTransformer() {}

        @Override
        public Double transform(final PricingDto pricingDto) {
            return pricingDto.getTax()
                     + pricingDto.getPrice()
                     + pricingDto.getTips();
        }
    }

    @Override
    public List<Double> getListDouble(final List<PricingDto> pricingDtos) {
        final List<Double> totalList = 
            TransformedList.decorate(pricingDtos, …
Run Code Online (Sandbox Code Playgroud)

java generics transformer-model apache-commons-collection

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

将 Guava ListMultimap 转换为 Java Map

GuavaMultiMap有实现ImmutableListMultimapImmutableSetMultimap. 鉴于我已经创建了一个ImmutableListMultimap<String, Anything>实例,如何将其转换为java.util.Map<String, List<Anything>>

asMap()方法返回 a java.util.Map<String, Collection<Anything>>,但不能转换为java.util.Map<String, List<Anything>>

我现在拥有的最好的就是

 final Map<String, Collection<Anything>> listMultimap = multimap.asMap();
 // convert to Map<String, List<>>
 final Map<String, List<Anything>> listMap = listMultimap.entrySet().stream()
     .collect(Collectors.toMap(
                  Map.Entry::getKey, 
                  e -> (List<Anything>) e.getValue()));

Run Code Online (Sandbox Code Playgroud)

但这看起来并不理想。鉴于实例变量是 ListMultimap 类型,是否应该有一个方便的方法将其表示为 a Map<..., List>

Apache commons-collections 也ArrayListValuedHashMap有同样的问题。

java multimap guava apache-commons-collection

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

如何为Collection的所有字段分配公共值?

我有一个名为Employee的POJO类,带有empName和Salary.我有一个Employee集合作为具有员工详细信息的对象.现在我想将特定字段的值重置为某个常用值.在这种情况下,我想为列表中的所有员工项目分配薪水"0".

List<Employee> empList;

public class Employee{
    private String empName = "";
    private int empSalary = "";
}
Run Code Online (Sandbox Code Playgroud)

而不是使用For/Foreach迭代员工列表,并为列表中的所有项目分配所需的值.

有没有任何简单或有效的方法来使用任何CollectionUtils(Apache公共或任何其他)实现相同的方法.

java collections apache-commons-collection

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

升级到 commons-collections4 会抛出 NoClassDefFoundError

我正在升级旧项目的 pom 中的库,并且在从 org.apache.commons commons-collections 3.2.1 升级到 org.apache.commons commons-collections4 4.0 时遇到了问题。我知道它不向后兼容,但我认为我做了必要的调整。旧 jar 不再在项目存储库中。

它编译得很好但是当我运行测试时我总是得到这个异常:

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap
    at org.hibernate.util.SimpleMRUCache.init(SimpleMRUCache.java:71)
    at org.hibernate.util.SimpleMRUCache.<init>(SimpleMRUCache.java:55)
    at org.hibernate.engine.query.QueryPlanCache.<init>(QueryPlanCache.java:76)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:237)
Run Code Online (Sandbox Code Playgroud)

(底部的完整堆栈跟踪)

我已经运行,mvm dependency:tree -Dincludes=org.apache.commons:commons-collection*但它只向我显示取决于 commons-collections4 的类,我看不到那个旧库。

有没有办法在不将旧的依赖项添加到 pom 的情况下解决这个问题?

我正在使用休眠 3.6.0.Final。

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:217)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:276)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:278)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) …
Run Code Online (Sandbox Code Playgroud)

java maven apache-commons-collection

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

较新的 apache commons 库是否与旧的兼容

具体来说,我感兴趣的是向后兼容 3.x 版本的新行 4.x commons-collections库。

apache version backwards-compatibility apache-commons-collection

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

Apache Commons MultiMap 已弃用,我现在应该使用什么?

自 4.1 版以来,Apache Commons 的MultiMap接口及其MultiValueMap实现已被弃用。而且MultiHashMap似乎完全消失了......

我应该使用什么作为替代?

java collections deprecated apache-commons-collection

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