【发布时间】:2012-10-10 09:53:20
【问题描述】:
我正在使用 HashSet,它具有用于所有元素的一些属性,然后将此 Hashset 添加到每个元素对应的 HashMap 中。此外,为特定元素添加了一些属性(例如 THEAD )。
但后来添加的属性 align 存在于 Table 和 THEAD 中。下面的代码是不是有问题。
private static HashMap<String, Set<String>> ELEMENT_ATTRIBUTE_MAP =
new HashMap<String, Set<String>>();
HashSet<String> tableSet =
new HashSet<String>(Arrays.asList(new String[]
{HTMLAttributeName.style.toString(),
HTMLAttributeName.color.toString(),
HTMLAttributeName.dir.toString(),
HTMLAttributeName.bgColor.toString()}));
ELEMENT_ATTRIBUTE_MAP.put(HTMLElementName.TABLE, new HashSet<String>(tableSet));
// Add align only for Head
tableSet.add(HTMLAttributeName.align.toString());
ELEMENT_ATTRIBUTE_MAP.put(HTMLElementName.THEAD, tableSet);
【问题讨论】:
-
我不希望 align 属性成为与 Table 相对应的 HashSet 的一部分。