我想过滤掉空字符串以将它们放入Option中.所以我现在很快建立了这个:
def StrictOption(s: String) = s match {
case s if s != null && s.trim.length() > 0 => Some(s)
case _ => None
}
Run Code Online (Sandbox Code Playgroud)
问题:这可能已经在标准库中了吗?
我有一个多项目构建,在子项目和父项目中都有测试.聚合构建,以便父项目在子项目中运行所有测试.
我对其进行了配置,以便在子项目和父项目中都没有并行执行测试
parallelExecution in Test := false
Run Code Online (Sandbox Code Playgroud)
但是,我有一种唠叨的感觉,跨越多个项目的测试是并行运行的.在其中一个子项目的情况下,这是一个问题,因为它同时改变了测试数据库中的状态,导致测试失败.
有关如何在项目之间全局切换测试并行执行的任何想法?
我正在使用OSGi(Equinox平台)开发一个应用程序,其中一个包需要解析XML文件.到目前为止,我用SAX(javax.xml.parsers.SAXParserFactory)实现了这个,我想从平台中检索SAXParserFactory.
我看到OSGi标准提供了一个XMLParserActivator来允许JAXP实现自己注册(http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html),所以我的猜测就是那里应该是一些提供SAXParserFactory作为服务的bundle.
但是,为了找到提供SAXParserFactory的服务,我无法确定要添加哪个包作为依赖项.我尝试使用检索服务引用
context.getServiceReferences(SAXParserFactory.class.getName(), "(&(parser.namespaceAware=true)(parser.validating=true))")
Run Code Online (Sandbox Code Playgroud)
鉴于XML解析是一件相当常见的事情,我认为有可用的实现,或其他从平台获取XML解析器服务的方法.
非常欢迎任何帮助!
我试图使用mongodb java驱动程序计算集合的平均值,如下所示:
DBObject condition =
new BasicDBObject("pluginIdentifier", plugin.getIdentifier());
DBObject initial = new BasicDBObject();
initial.put("count", 0);
initial.put("totalDuration", 0);
String reduce = "function(duration, out) { out.count++;
out.totalDuration+=duration.floatApprox; }";
String finalize = "function(out) { out.avg = out.totalDuration.floatApprox /
out.count; }";
DBObject avg = durationEntries.group(
new BasicDBObject("pluginIdentifier", true),
condition, initial, reduce, finalize);
System.out.println(avg);
Run Code Online (Sandbox Code Playgroud)
"duration"是NumberLong(在java中,它是Long,可能是java驱动程序转换它).经过一些搜索我发现,为了提取数字,使用.floatApprox是一种方法,这也适用于mongodb控制台:
> db.DurationEntries.findOne().duration.floatApprox
5
Run Code Online (Sandbox Code Playgroud)
但是,运行上面的java代码不会计算平均值,而是返回它
[{"pluginIdentifier":"dummy", "count":7.0, "totalDuration":NaN, "avg":NaN}]
Run Code Online (Sandbox Code Playgroud)
我尝试了几种变体,有和没有.floatApprox,但到目前为止只能获得一些奇怪的字符串连接.
我的问题是:我做错了什么/我应该如何计算一个NumberLong列的平均值?
我有以下项目构建:
import sbt._
import Keys._
object ProjectBuild extends Build {
val buildVersion = "0.1-SNAPSHOT"
val delvingReleases = "Delving Releases Repository" at "http://development.delving.org:8081/nexus/content/repositories/releases"
val delvingSnapshots = "Delving Snapshot Repository" at "http://development.delving.org:8081/nexus/content/repositories/snapshots"
val delvingRepository = if (buildVersion.endsWith("SNAPSHOT")) delvingSnapshots else delvingReleases
lazy val root = Project(
id = "basex-scala-client",
base = file(".")
).settings(
organization := "eu.delving",
version := buildVersion,
resolvers += "BaseX Repository" at "http://files.basex.org/maven",
libraryDependencies += "org.basex" % "basex" % "7.2.1",
libraryDependencies += "org.specs2" %% "specs2" % "1.7.1" % "test",
publishTo := …Run Code Online (Sandbox Code Playgroud) 当无法找到工件的来源时,IDEA建议"在互联网上搜索"或"附加来源".在选择"在互联网上搜索"选项时,有没有办法在存储库IDEA检查中添加新位置?
我正在尝试在https://github.com/dwerder/puppet-mongodb安装puppet模块
它的工作要求之一是设置mongodb存储库.由于我正在尝试在Debian上部署它,我尝试使用以下类添加源:
class mongodb::apt::repo {
include apt
apt::source { '10gen':
location => 'http://downloads-distro.mongodb.org/repo/debian-sysvinit',
release => 'dist',
repos => '10gen',
key => '7F0CEB10',
key_server => 'keyserver.ubuntu.com',
include_src => false
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在尝试安装模块(在测试节点上)时,我得到以下输出:
root@debian:/etc/puppet/modules# puppet agent --test
info: Caching catalog for debian.lan
info: Applying configuration version '1353946258'
err: Could not apply complete catalog: Found 1 dependency cycle:
(Exec[apt_update] => Class[Apt::Update] => Anchor[apt::source::10gen] => Anchor[apt::source::10gen] => Apt::Source[10gen] => Class[Mongodb::Apt::Repo] => Package[mongodb-10gen] => Anchor[mongodb::install::end] => Anchor[mongodb::install::end] => File[10gen.list] => Apt::Source[10gen])
Try the …Run Code Online (Sandbox Code Playgroud) 我对以下内容感到困惑:我有一个这样的简单链接:
<li><a href="#/foo">Foos</a></li>
Run Code Online (Sandbox Code Playgroud)
但点击它时,视图不会更新.浏览器中的URL发生了变化,但没有任何反应,控制台中也没有显示任何内容.如果我直接在浏览器中加载URL,则会加载正确的页面.
路线看起来像这样:
app.config(function($routeProvider, RestangularProvider) {
$routeProvider
.when('/index', {templateUrl: 'assets/views/index.html'})
.when('/foos', {templateUrl: 'assets/views/list.html', controller: controllers.FooListCtrl})
.when('/foos/create', {templateUrl: 'assets/views/update.html', controller: controllers.FooUpdateCtrl})
.when('/foos/:id/update', {templateUrl: 'assets/views/update.html', controller: controllers.FooUpdateCtrl})
.otherwise({redirectTo: '/index'});
RestangularProvider.setBaseUrl("/admin");
});
Run Code Online (Sandbox Code Playgroud) 在elasticsearch文档中,数组字段的最大建议大小是多少?我正在研究使用文档字段以保持用户的"关注者"的ID列表,以便在执行查询的用户跟随潜在匹配时在查询结果中提升文档.
此外,是否有更好的方法来改善用户文档的相关性,而不是这种相当残酷的方法?
我目前开始研究一个maven web-app项目,该项目需要使用jetty启动:run-explosion目标,用于eclipse中的开发/调试.
现在,我有一个XML文件,其中包含我需要在运行时访问的内容.我的问题是:在哪里放置文件,以便执行读取的代码在"爆炸"和打包(即在WAR)模式下工作?
将文件放在src/main/java中(以便在类路径中)不会删除它,因为maven会过滤掉包装上的所有非java文件.当文件位于src/main/resources中时,一个意思是找出项目的根路径(在eclipse开发期间)并查看该目录 - 但是当项目打包时不再是这种情况.
当然,我可以编写试图从两个位置读取文件的代码,但这看起来相当麻烦.有什么建议?