的Java - 需要逻辑添加和HashMap的比较值,而不是匹配的密钥
我有2个下拉菜单在我的UI中删除,选择一个会给从下拉列表中选择另一组的配置为该特定值复选框down.each时间我添加选定的价值和复选框值之间有着某种联系,它应该保存在某个地方,并正确识别元素,这样我可以将其删除,仍然保留了它在那里的Java - 需要逻辑添加和HashMap的比较值,而不是匹配的密钥
前值---- UI --- -
Select box
<button style="display: none;" type="submit" id="selected" name="_eventId_getid"></button>
<label for="name" >Product</label>
<form:select path="selectedProduct" disabled="${isDisabled}" onchange="simulateClick('selected');">
<form:option value="0">Select...</form:option>
<form:options items="${createProject.product}" itemLabel="name" itemValue="id" />
</form:select>
checkbox, depending upon slectbox
<button style="display:none;" type="submit" id="selectCopyType" name="_eventId_submit"> </button>
<c:if test="${not empty createProject.elementType}">
<button style="display: none;" type="submit" id="copy" name="_eventId_getId2"></button>
<input class="checkAllCheckbox" id="selectall" name="selectall" type="checkbox"/>
<span style="display:inline; margin-left:auto;">Select All</span>
<!-- id must be the same as listId above -->
<div class="CFbox" id="id" >
<form:checkboxes items="${ProjectCommand.ElementType}" onclick="simulateClick('copy')" path="CopyType" cssClass="case" itemValue="id" itemLabel="name" name="case"/> </div>
</div>
Class Command
private String seelctedProduct;
private List<Integer> CopyType;
private List<Class1> class1
Class Class1
private Integer seq = 0;
private String product;
private String ElementName
public void getSelectedCopy(Command command)
{
Map<Integer,String[]>map= new HashMap<Integer,String[]>();
if (command.CopyType() != null && command.getCopyType().size() > 0)
{
List<Class1> copyList = new ArrayList<Class1>();
Integer Seq = 0;
if (command.getClass1() != null && command.getClass1().size() <= command.getCopyType.size())
{
//Max CfSeq is stored in the variable -1 .
Seq = command.getClass1().get(command.getClass1.size() - 1).getSeq();
}
for (int copytype : command.getCopyType())
{
if (command.getCopyType().size() >1)
{
if (copyType <= Seq)
{
copyList.add(command.getClass1().get(Seq - 1));
continue;
}
}
cfSeq++;
map.put(Seq,new String[]{command.getseelctedProduct(),"copyType"});
System.out.println("map"+map);
Class1 objclass1= new Class1();
objclass1.setProduct(command.getseelctedProduct());
objclass1.setElementName(copyType + "");
objclass1.setSeq(Seq);
copyList.add(objclass1);
}
command.setClass1(copyList);
}
else
{
command.setClass1(null);
}
}
现在我没有得到正确的seq编号,我无法从地图中删除正确的成员..希望你们得到了我想要做的!感谢help.I想我需要需要逻辑添加和HashMap的比较值,而不是匹配的密钥删除,如果你有其他建议,正确显示的序列,而不是每次都清理对象..请建议
如果你的问题真的有价值 - >键查找,你应该看看番石榴或Commons收藏。
番石榴: http://www.discursive.com/books/cjcook/reference/collections-sect-key-by-value
共享收藏bidimap: http://commons.apache.org/collections/api-3.1/org/apache/commons/collections/BidiMap.html
共享的集合是慈祥的老人和稳定,而番石榴提供了很多新的模式和使用泛型类型安全。
感谢您的帮助 – user1238330 2012-02-28 22:10:02
您可以发布您的实际代码。你的两个类都不是有效的代码。 – 2012-02-28 18:07:15