在使用Google Collections(更新:Guava)时,我有一个关于简化某些Collection处理代码的问题.
我有一堆"计算机"对象,我想最终收集他们的"资源ID".这样做是这样的:
Collection<Computer> matchingComputers = findComputers();
Collection<String> resourceIds =
Lists.newArrayList(Iterables.transform(matchingComputers, new Function<Computer, String>() {
public String apply(Computer from) {
return from.getResourceId();
}
}));
Run Code Online (Sandbox Code Playgroud)
现在,getResourceId()可能会返回null(并且现在更改它不是一个选项),但在这种情况下,我想从结果String集合中省略null.
这是过滤掉空值的一种方法:
Collections2.filter(resourceIds, new Predicate<String>() {
@Override
public boolean apply(String input) {
return input != null;
}
});
Run Code Online (Sandbox Code Playgroud)
你可以像这样把所有这些放在一起:
Collection<String> resourceIds = Collections2.filter(
Lists.newArrayList(Iterables.transform(matchingComputers, new Function<Computer, String>() {
public String apply(Computer from) {
return from.getResourceId();
}
})), new Predicate<String>() {
@Override
public boolean apply(String input) {
return input != null; …Run Code Online (Sandbox Code Playgroud) 我试图编写代码来打印Z字符.
zzzzzzz
z
z
z
z
z
zzzzzzz
Run Code Online (Sandbox Code Playgroud)
但是当我编译这段代码时,它会抛出
D:\erlang\graphics>erlc zeez2.erl
d:/erlang/graphics/zeez2.erl:19: head mismatch
d:/erlang/graphics/zeez2.erl:6: function zeez/3 undefined
Run Code Online (Sandbox Code Playgroud)
我无法修复此错误.我没有发现我的错误.
有人请建议我.
谢谢.
-module(zeez2).
-export([main/0]).
main() ->
L = 8,
zeez( false ,1, L). % line 6
zeez(true, M,M) ->
init:stop();
zeez(false, M, N) ->
io:format("~p~n", [zeez(z, N-M)] ),
zeez(M rem N =:= 0, M + 1, N );
zeez(true, M, N) ->
io:format("~p~n", [zeez(space, N-M)] ), % line 16
zeez(M rem N =:= 0, M + 1 , N );
zeez(space, …Run Code Online (Sandbox Code Playgroud) 我是SVN的新手,所以这可能是一个简单的问题.
我们有一个带有第一级目录的"主干":
10 <-- documents
20 <-- source code, db scripts, ...
30 <-- documents
40 <-- referenced 3rd party library-es
Run Code Online (Sandbox Code Playgroud)
我从"后备箱"做了一个"开发"分支.在"开发"中,我们更改了源代码,在测试之后,我们将其合并到"trunk".
目录"10"和"30"中的问题是存储了开发不需要的*.doc文件,因此需要"develop"分支没有这些目录.
解决方案仍应:
编辑:我忘了提到"源代码"不仅在20中.有引用的dll-s和构建脚本等也在第1级目录,比方说40.
我有一个UITableView5 UITableViewCells.每个单元格包含一个UIButton设置如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
[cell autorelelase];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 5, 40, 20)];
[button addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTag:1];
[cell.contentView addSubview:button];
[button release];
}
UIButton *button = (UIButton *)[cell viewWithTag:1];
[button setTitle:@"Edit" forState:UIControlStateNormal];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:在buttonPressedAction:方法中,我如何知道按下了哪个按钮.我考虑过使用标签,但我不确定这是最好的路线.我希望能够以某种方式标记indexPath到控件上.
- (void)buttonPressedAction:(id)sender
{
UIButton *button = (UIButton …Run Code Online (Sandbox Code Playgroud) 我知道“XMLHttpRequest”对象支持一个方法“open”,它有一个用户名和密码的可选参数。我刚刚发现这些参数可以作为需要基于容器的身份验证的请求的提供者。
这是方法签名:
open(method, url, async, username, password)
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我了解基于容器的身份验证的含义吗?
我设置了我的实体属性
@GeneratedValue
Long id;
Run Code Online (Sandbox Code Playgroud)
我能够为数据库中的实体生成id.我的问题是为什么所有实体共享相同的增量数? 是不是每个表都应该从零开始计数?
所以我需要匹配一个可能有也可能没有掩码的ipv6地址.不幸的是我不能只使用库来解析字符串.
掩码位很容易,在这种情况下:
(?:\/\d{1,3})?$/
Run Code Online (Sandbox Code Playgroud)
困难的部分是ipv6地址的不同格式.它需要匹配::牛肉,牛肉::牛肉::牛肉等.
更新:我快到了..
/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我仅限于使用perl的正则表达式.
我的应用程序连接到db并从此处获取类别树.在调试方案中,我可以看到这个大树对象,我只想到能够将这个对象保存在磁盘上的某个地方,以便在测试存根中使用.像这样:
mockedDao = mock(MyDao.class);
when(mockedDao.getCategoryTree()).thenReturn(mySavedObject);
Run Code Online (Sandbox Code Playgroud)
假设mySavedObject- 足够大,所以我不想手动生成它或编写特殊代代码.我只是希望能够在调试会话期间将其序列化并保存在某处,然后对其进行反序列化并传递给thenReturn测试.是否有标准的方法可以这样做?如果不是如何更好地实施这种方法?
我有一个网站,其表单使用PHP发送表单数据.有没有办法在页面上创建一个看起来像是在运行的进度条,以便人们在单击并发送PHP信息后不会多次单击该按钮.
谢谢.
我试图用RSpec测试我的观点.导致我麻烦的特定视图根据url参数改变其外观:
link_to "sort>name", model_path(:sort_by => 'name') 结果 http://mydomain/model?sort_by=name
然后我的视图使用这个参数:
<% if params[:sort_by] == 'name' %>
<div>Sorted by Name</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
RSpec看起来像这样:
it "should tell the user the attribute for sorting order" do
#Problem: assign params[:sort_for] = 'name'
render "/groups/index.html.erb"
response.should have_tag("div", "Sorted by Name")
end
Run Code Online (Sandbox Code Playgroud)
我想在RSpec中测试我的视图(没有控制器),但我无法将此参数输入到我的params变量中.我试过assign各种不同的口味:
assign[:params] = {:sort_by => 'name'}assign[:params][:sort_by] = 'name'到目前为止没有成功.每个想法都表示赞赏.
java ×3
branch ×1
collections ×1
containers ×1
css ×1
entity ×1
erlang ×1
guava ×1
hibernate ×1
html ×1
http ×1
ios ×1
iphone ×1
ipv6 ×1
javascript ×1
jquery ×1
mocking ×1
perl ×1
php ×1
refactoring ×1
regex ×1
rspec ×1
svn ×1
uibutton ×1
uitableview ×1
unit-testing ×1