我有这个算法,我想使用递归回溯实现图搜索.
首先我的代码:
public static boolean buildTree(GenericTreeNode<String> inputNode){
while(!interruptFlag)
{
try { Thread.sleep(200); } catch(InterruptedException e) {}
gui.frame.MainWindow.progress.setText("Iterations Deployment: " + c);
gui.panel.ResultMatrix.setResult(mappingList);
Multimap<String,String> openList = LinkedHashMultimap.create();
openList = UtilityClasses.getOpenList.getOpenList(dataMap, ApplicationList, HardwareList, mappingList);
if(openList.isEmpty() && !mappingList.keySet().containsAll(XMLParser.ApplicationsListGUI))
{
gui.frame.MainWindow.labelSuccess.setText("Mapping not succesful!");
return false;
}
if(openList.isEmpty() && mappingList.keySet().containsAll(XMLParser.ApplicationsListGUI))
{
System.out.println(calculateOverallCost.getOverallCosts());
System.out.println("Mapping done:" + " " + mappingList);
gui.panel.ResultMatrix.setResult(mappingList);
return true;
}
if(!openList.isEmpty() && (!mappingList.keySet().containsAll(XMLParser.ApplicationsListGUI)))
{
for(String s : openList.keySet())
{
for(String h : openList.get(s))
{
GenericTreeNode<String> child = new GenericTreeNode<String>(s + ":" + …Run Code Online (Sandbox Code Playgroud) 有一点Stringcutting问题.我有一个像这样的字符串:
@VAR;Variable=Deteministic;Value=mostly;Note=Unless Slave is already in use;Op==;@ENDVAR;
Run Code Online (Sandbox Code Playgroud)
注意对我来说不是必需的,所以我想删除所有以Note开头的内容,直到下一个分号.替换方法会很好,但我不知道如何在Note之后获得Chars.
我试过这样的事情:
int index1 = rs.IndexOf("Note=");
int index2 = rs.IndexOf(';', index1+1);
rs = rs.Remove(index1, index2);
Run Code Online (Sandbox Code Playgroud)
我认为这应该足够了,但是如果没有注释就会失败并且我的程序弹出错误.正则表达式是一个选择,但我不能想到这里适合的一个.
请注意,该示例只是一个示例.我不知道输入字符串是什么样的.一行可以包含两个Notes,另一行可以没有.请在答案中考虑这一点.
Multimaps的这个东西开始让我感到困惑.这就是我创建地图的方式.
Map<String, Multimap<String,Values>> valuesMap = new HashMap<String, Multimap<String, Values>>();
Run Code Online (Sandbox Code Playgroud)
然后第二个内部地图就是这个.
Multimap<String, Values> mm = new HashMultimap.create();
Run Code Online (Sandbox Code Playgroud)
但是在编译之后我得到了这个失败的消息:HashMultimap.create无法解析为一个类型
我包括所有进口的番石榴.我不明白,Intellisense识别Hashmap但不识别Hashmultimap.我希望有人可以给我一个提示,我正在寻找几个小时.
我使用Gridlayout将4个元素放在一行中.首先,我有一个JPanel,一切正常.对于行数变大而我必须能够向下滚动的情况,我改变了一下.现在我添加JPanel了一个JScrollPane.我使用相同的代码,现在我只是将元素添加到视口中Jscrollpane,但现在我得到了这个例外Get java.lang.ClassCastException: layout of JScrollPane must be a ScrollPaneLayout: at javax.swing.JScrollPane.setLayout(Unknown Source),我不知道究竟是为什么.为什么Gridlayout不为人所知Jscrollpane?
这是代码:
public objectDetails() {
setTitle("LLI_MC_Solver");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = new JPanel();
contentPane.setLayout(new GridLayout());
setBounds(100, 100, 510, 401);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setVisible(true);
contentPane.setPreferredSize(new Dimension(500, 390));
JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setViewportBorder(new LineBorder(new Color(0, 0, 0), 2));
scrollPane.setBounds(10, 10, 474, 342);
scrollPane.setLayout(new GridLayout(0,4)); //Line which causes the error
scrollPane.setPreferredSize(new Dimension(465, 330));
contentPane.add(scrollPane);
JPanel view = (JPanel)scrollPane.getViewport().getView();
for(Values …Run Code Online (Sandbox Code Playgroud) 我希望在一定的延迟后调用一个特定的方法.我尝试了不同的aproaches,如计时器,执行程序或处理程序.他们满足了他们应该做的事情,但有一点例外.延迟方法调用在番石榴的多图中进行了一些更改.在runTimerTask 的方法中,输出就像我想要的那样.但是如果我打印出多边形图,run那么更改将被撤消,我仍然拥有旧的多图值.但我需要更新的,因为我的数据保存在其中,我需要使用更新的值.
我的代码看起来像这样:
public class classTimer {
public static void main(String[] args) {
//some code, irrelevant for the task
new Timer().schedule(new TimerTask() {
@Override
public void run() {
dataMap = UndoManager.undoChanges(dataMap, a, hw);
// Point 1
}
}, delay);
// Point 2
}
}
Run Code Online (Sandbox Code Playgroud)
就像我之前说过的那样,打印dataMapat Point1会给出正确的输出,在Point 2处旧的值,比如Method UndoChanges更新的调用.实现了多重映射,更改保持一致,并且通常必须更改值,但这不是这里的情况.我在这里错过了什么?如果有人知道在延迟后调用方法的方法不同,我会很高兴听到它.
谢谢,非常感谢