本文介绍了在Java中使用泛型(域模型,而不是持久层)有多少到多个集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在Google中使用错误的搜索字词...

I seem to be using the wrong search terms for this in Google...

我已经为多对多协会编写了通用类,但是猜测这已经完成了。它的存在比我自己更有优势。这是我第一次写通用类。

I have written a Generic Class for Many-To-Many Associations, but I'm guessing this has already been done. It is highly likely that it exists in an implementation much better than my own. This is my first foray into writing a generic class.

为了更好地了解我正在寻找的内容,我包含了我自己的一些代码片段:

For a better idea of what I'm looking for, I am including some snippets of my own:

我已经用2个hashmaps支持了:

I've backed it with 2 hashmaps:

private final Map<T, List<S>> ssForTs = new HashMap<T, List<S>>();
private final Map<S, List<T>> tsForSs = new HashMap<S, List<T>>();

以下是实例化:

new ManyToManyAssociations<Integer, Integer>();

有些方法可用:


  • public void addAssociation(T t,S s)

  • public void removeAssociation(T t,S s)

  • public列表< T> getListOfTs()

  • public List< S> getListOfSs()

  • public List< T> getTsForSs(S)

  • public List< S> getSsForTs(T t)

  • public void addAssociation(T t, S s)
  • public void removeAssociation(T t, S s)
  • public List<T> getListOfTs()
  • public List<S> getListOfSs()
  • public List<T> getTsForSs(S s)
  • public List<S> getSsForTs(T t)

方法的名称很差...我很抱歉

The names of the methods are quite poor... I apologize.

基本用法是:
我可以很容易地找到所有的S和反向。

Basic usage is:I can find all S for T and the reverse quite easily.

你可以发布链接到已经包含此功能的抛光库?

Can you post the link to a polished library that already includes this functionality?

推荐答案

到目前为止,这是一个比我想象的更不便宜的问题。我知道的两个Java Collections扩展名是由duffymo提到的Google,而。也没有多对多的地图。在Google的术语中,它将是一个 BiMultiMap ;在Apache中,它将是一个 BidiMultiMap MultiBidiMap

So far, this is a less trivial question than I thought. The two Java Collections extensions I know of off the top of my head are the Google one mentioned by duffymo, and the Apache Commons Collections. Neither has a many-to-many map. In Google's terminology, it would be a BiMultiMap; in Apache's, it would be a BidiMultiMap or MultiBidiMap.

这篇关于在Java中使用泛型(域模型,而不是持久层)有多少到多个集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 19:41