我有一个具有多个值的对象。
{Object
{ value1: 1204
value2: 5
value3: blah
},
{ value1: 1204
value2: 3
value3: blah
},
{ value1: 942
value2: 1
value3: blah
},
etc
}
Run Code Online (Sandbox Code Playgroud)
我需要做的是在渲染对象之前对对象进行排序value1和value2。我在网上搜索没有找到好的解决方案。
我下面的内容显然不起作用。它首先按 value1 排序,然后按 value2 排序。我尝试过类似于链接的功能,以及其他一些尝试。但我还没有成功。
sortObject = (results) => {
results.sort((a, b) => a.value1 - b.value1);
results.sort((a, b) => a.value2 - b.value2);
console.log(results);
return results;
};
Run Code Online (Sandbox Code Playgroud)
对我的对象进行排序的有效方法是什么?
我正在尝试为独立应用程序创建一个清晰的Java UI布局.我知道JSwing不是最好的UI,但它就是我现在所拥有的.
我的UI目前看起来像:

我希望文本排成一行,按钮排列,向上,以及所有这些按钮的提交和状态,彼此堆叠或平行.
我的布局目前是这样的:
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addComponent(lbl_inputFile)
.addComponent(txt_inputFile)
.addComponent(btn_inputFile)
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_searchTermFile)
.addComponent(txt_searchTermFile)
.addComponent(btn_searchTermFile))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_outputFile)
.addComponent(txt_outputFile)
.addComponent(btn_outputFile))
.addGroup(layout.createSequentialGroup()
.addComponent(btn_sumbit)
.addComponent(lbl_status))
);
layout.linkSize(SwingConstants.HORIZONTAL, btn_inputFile, btn_outputFile, btn_searchTermFile);
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(lbl_inputFile)
.addComponent(txt_inputFile)
.addComponent(btn_inputFile))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(lbl_searchTermFile)
.addComponent(txt_searchTermFile)
.addComponent(btn_searchTermFile))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(lbl_outputFile)
.addComponent(txt_outputFile)
.addComponent(btn_outputFile))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(btn_sumbit)
.addComponent(lbl_status))
);
Run Code Online (Sandbox Code Playgroud)
任何想法如何实现我想要的?
我有一个正确的正则表达式,但它在我的程序中失败了.通常一组不同的眼睛是好的.
相关守则:
String s_mapping = ".*<MAPPING DESCRIPTION.*NAME =.*";
Pattern mapName = Pattern.compile("\"(m_.*?)\"");
String o_mapping = "";
...
if (line.matches(s_mapping)){
Matcher matcher = mapName.matcher(line);
System.out.println(line);
System.out.println(matcher);
o_mapping = matcher.group(1);
System.out.println(o_mapping);
Run Code Online (Sandbox Code Playgroud)
产量
<MAPPING DESCRIPTION ="Mapping to generate the parameters file based on the parameters inserted in the table." ISVALID ="YES" NAME ="m_FAR_Gen_ParmFile" OBJECTVERSION ="1" VERSIONNUMBER ="2">
java.util.regex.Matcher[pattern="(m_.*?)" region=0,195 lastmatch=]
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: No match found
Run Code Online (Sandbox Code Playgroud)
我希望最终看到m_FAR_Gen_ParmFile我的o_mapping输出.
当我在这个网站上测试时:http://www.regexplanet.com/advanced/java/index.html,所有通行证都很顺利.为什么我的程序失败了?以及如何解决?
我正在使用Java正则表达式问题.我需要匹配的字符串遵循这种模式:378-Columbian Forecast Yr-NB-Q-Columbian_NB我需要提取第一个和第二个之间的内容-.
Pattern modelRegEx = Pattern.compile("[^-]{15,}[^-]");
Matcher m = modelRegEx.matcher(temp);
String model = m.group(0);
Run Code Online (Sandbox Code Playgroud)
以下是这个正则表达式背后的理由[^-]{15,}[^-]:
我只想要使用连字符之间的内容[^-].连字符之间有多个文本实例,所以我选择了一个足够大的数字,它不会在较小的匹配上获取.所以我用过{15,}
我的错误:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Matcher.java:496)
at alfaSpecificEditCheck.tabTest.main(tabTest.java:21)
Run Code Online (Sandbox Code Playgroud)
当我在这里测试我的正则表达式模式时:http://regexpal.com/模式匹配.当我使用此测试仪更具体地针对Java进行测试时(http://www.regexplanet.com/advanced/java/index.html)结果是未找到匹配项.