我想在Scala中使用NIO.2特性(类在java.nio.file中):
在Java中我会这样做:
Files.newDirectoryStream(Paths.get("/tmp"), new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
我怎么能在Scala中做同样的事情?该Fitler是内部的静态接口DirectoryStream界面.
谢谢.
编辑:如果您想建议我另一个列出文件的库/方法,请不要回复.我主要对主要问题感兴趣.
以下代码完美无缺.
public class StaticClass {
public static void main(String[] args) {
L.P h = new L.P();
h.show();
}
}
class L {
static class P {
public void show() {
System.out.println("This is static nested class.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
那么为什么".Thread.WeakClassKey t"无法访问java.lang.Thread类中的静态嵌套类"static class WeakClassKey extends WeakReference>".在我班上?
java.lang.Thread的源代码可以在这里找到:http://www.docjar.com/html/api/java/lang/Thread.java.html [在#1984行].
我正在编写一个解析一些命令的应用程序.命令以下列形式给出:
A {B}
我只想要A和B.A是可选的,但这很容易处理.我遇到的问题是A和B几乎都可以包含任何字符,包括空格和'{'和'}'.括号也不需要平衡.这可以用正则表达式解析吗?如果没有,您认为可以做的最简单的事情是什么?
例如,给定:
"parsme {foo {"hello"} {"goodbye"} {{{} {bar {"up"} {"down"}}"
然后:
A ="parseme {foo {"hello"} {"goodbye"} {{{}}和B ="bar {"up"} {"down"}"
当用户为钻石输入5时,我希望能够打印出这样的钻石.但也适用于任何奇数且大于0的值.

我有一个代码,用于为用户输入5制作钻石,但不适用于所有奇数输入..
half = (size/2)+1;
for (a=1; a <= half ; a++) /*top to mid row of diamond*/
{
for (b=a; b<half;b++)
{
printf(" ");
}
for (c= size -2* a; c <= half; c++)
{
printf("*");
}
printf("\n");
}
for (a = 1; a < half;a++)
{
for (b = a; b>0;b--)
{
printf(" ");
}
for (c = size-2*a; c >0 ;c--)
{
printf("*");
}
printf("\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.谢谢.
麦克风
这个主题已在网上多次讨论,但所有主题都没有帮助我解决我的问题.我的javascript代码接收JSON嵌套数据.所有JSON数据1级数据都在网格面板中转录,但所有子数据都没有.我尝试了很多方法,但不可能.这就是我要求你帮助我的原因.
我的JSON:
{
"success":true,
"error":false,
"redirectUrl":null,
"fund":[{
"cat_id":1,
"catname":"Europe OE Japan Large-Cap Equity",
"region":{
"region_id":2,
"region_name":"JAPAN"
}
},{
"cat_id":2,
"catname":"Europe OE Europe Large-Cap Growth Equity",
"region":{
"region_id":1,
"region_name":"EUROPE"
}
}]
}
Run Code Online (Sandbox Code Playgroud)
我的型号:
var Recommended = new function() {
this.DataModel = function() {
Ext.define('Fund', {
extend: 'Ext.data.Model',
fields: [{
name: 'catname',
type: 'string'
},{
name: 'cat_id',
type: 'int'
}],
proxy :{
type: 'rest',
url: application +'directory/function',
reader: {
type: 'json',
root: 'fund'
}
},
associations: [{
type: 'hasOne',
model: 'Region',
primaryKey: …Run Code Online (Sandbox Code Playgroud) 我正在尝试建立一个条件系统,以编程方式检测浏览器(使用USER_AGENT字符串)和平台(使用PHP-Mobile-Detect).我目前的设置大致如下:
<DOCTYPE html>
<html>
<head>
<?php
include("Mobile_Detect.php");
$detect = new Mobile_Detect();
?>
<?php if($detect->isiPad()) {
echo '<link rel="stylesheet" href="/style/iPad.css" type="text/css">';
}
else
{
echo '<meta charset="UTF-8">
<link rel="stylesheet" href="/style.css" type="text/css">;
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false)
{
echo '<link rel="stylesheet" href="../style/splash-webkit.css" type="text/css">';
}
//and so on for other browsers
[etc]'
}
Run Code Online (Sandbox Code Playgroud)
这里出现的明显问题是's 之间的冲突.正如我希望的那样,echounder else,而不是在我的<style>标签的末尾结束,首先'出现在代码中,因为它是在第一个USER_AGENT声明中.我该如何绕过这个问题?
我正在尝试为网站制作垂直边栏。中有多个主要项目ul,如果这些项目具有子类别,则新项目ul会嵌套在ul其父项目下的主要项目中li(这在下面的代码中更加明显)。在最新版的Chrome中,它应显示,但在最新的Firefox中,父级li及其对应的嵌套子项之间有一个空格ul。关于原因有什么想法吗?
这是基本的html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<script>
</script>
<style>
</style>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<ul class="navigation">
<li>ITEM1</li>
<li>ITEM2</li>
<ul class="navigation subitem">
<li>subitem1</li>
<li>subitem2</li>
<li>subitem3</li>
</ul>
<li>ITEM3</li>
</ul>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是相应的CSS:
.navigation {
display: inline;
width: 150px;
margin-top: 5px;
padding-left: 15px;
text-align: right;
vertical-align: middle;
}
.subitem {
margin: 0px;
vertical-align: top;
top: 0px;
}
.navigation li {
display: block;
font-family: 'Oxygen'; …Run Code Online (Sandbox Code Playgroud) public class MyClass {
public int myclassMember=NestedClass.nestedclassMember; //Compiler error,static reference to a non-static field
public static class NestedClass {
public int nestedclassMember=myclassMember; //Compiler error,static reference to a non-static field.
public NestedClass() {
}
}
}
Run Code Online (Sandbox Code Playgroud)
但与此同时,在删除编译时错误后,以下内容完全合法 - :
MyClass.NestedClass nestedInstance= new MyClass.NestedClass();
Run Code Online (Sandbox Code Playgroud)
给出了什么?这个类如何同时是静态的和非静态的?
我在分割数据文件中的文本时遇到问题,假设数据文件包含:
Row 1
apple
bob
cat
dog
ear
fun
Row 2
glow
horse
idea
joke
kick
lemon
Row 3
money
new
odd
park
queen
run
Run Code Online (Sandbox Code Playgroud)
我想拆分它,使它成为一个嵌套列表,如下所示:
[[apple, bob], [cat, dog], [ear, fun]],
[[glow, horse], [idea, joke], [kick, lemon]],
[[money, new], [odd, park], [queen, run]]
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的工作:
def text_file(data_file):
nested_list = []
main_list = []
my_list = ''
for index in data_file:
index = index.strip()
if (index in my_list):
main_list.append(nested_list)
nested_list = []
else:
nested_list.append(index)
if (nested_list):
main_list.append(nested_list)
return (main_list)
Run Code Online (Sandbox Code Playgroud)
但是这会返回:
text_file(open("data_file.txt", …Run Code Online (Sandbox Code Playgroud) 我试图附加到嵌套在字典中的列表,以便我可以看到哪些字母跟随一个字母.我想在底部获得理想的结果.为什么这不匹配?
word = 'google'
word_map = {}
word_length = len(word)
last_letter = word_length - 1
for index, letter in enumerate(word):
if index < last_letter:
if letter not in word_map.keys():
word_map[letter] = list(word[index+1])
if letter in word_map.keys():
word_map[letter].append(word[index+1])
if index == last_letter:
word_map[letter] = None
print word_map
desired_result = {'g':['o', 'l'], 'o':['o', 'g'], 'l':['e'],'e':None}
print desired_result
Run Code Online (Sandbox Code Playgroud) nested ×10
java ×2
list ×2
python ×2
static ×2
brackets ×1
c ×1
conditional ×1
dictionary ×1
extjs4 ×1
file ×1
firefox ×1
for-loop ×1
gridpanel ×1
html-lists ×1
interface ×1
java-7 ×1
json ×1
jvm ×1
loops ×1
model ×1
nested-lists ×1
parsing ×1
php ×1
regex ×1
scala ×1
spacing ×1
user-agent ×1
visibility ×1