我正在尝试以最简单的方式编写一个程序来计算Scala语言中文件中的单词出现次数.到目前为止,我有这些代码:
import scala.io.Codec.string2codec
import scala.io.Source
import scala.reflect.io.File
object WordCounter {
val SrcDestination: String = ".." + File.separator + "file.txt"
val Word = "\\b([A-Za-z\\-])+\\b".r
def main(args: Array[String]): Unit = {
val counter = Source.fromFile(SrcDestination)("UTF-8")
.getLines
.map(l => Word.findAllIn(l.toLowerCase()).toSeq)
.toStream
.groupBy(identity)
.mapValues(_.length)
println(counter)
}
}
Run Code Online (Sandbox Code Playgroud)
不要打扰正则表达式.我想知道如何从此行中检索的序列中提取单个单词:
map(l => Word.findAllIn(l.toLowerCase()).toSeq)
Run Code Online (Sandbox Code Playgroud)
为了得到每个单词的出现次数.目前我正在使用计算单词序列的地图.
我使用的代码如下:
public Configuration {
private boolean isBatmanCar = someMethod(...);
@Produces
public Car getCar(@New Car car) {
if(isBatmanCar) {
car.setName("BatmanCar");
}
return car;
}
}
public Car {
private String name = "NormalCar";
public void setName(String name) {
this.name = name;
}
}
public Demo {
@Inject
Car car;
// rest of code
}
Run Code Online (Sandbox Code Playgroud)
当我将应用程序部署到glassfish(Java EE 6顺便说一句)时,我得到了
AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between (...) Car with qualifiers [@Any @Default] (...) Producer Method [Car] with qualifiers [@Any @Default]
我知道当我添加@Alternative …
我怎么能展平Stream
的Map
(同类型)s到一个Map
用Java 8?
Map<String, Long> toMap(Stream<Map<String, Long>> stream) {
return stream. ???
}
Run Code Online (Sandbox Code Playgroud) 我正在使用AngularJS $资源模型来REST API.我有这样的事情:
angular.module('libraryapp')
.factory('Book', function($resource){
return $resource('books/:id');
});
Run Code Online (Sandbox Code Playgroud)
我用这种方式:
Book.get({ id: 42 }, function(book) {
console.log(book);
});
Run Code Online (Sandbox Code Playgroud)
但我也想要一个端点到子资源,让我们说:
GET /books/:id/comments
Run Code Online (Sandbox Code Playgroud)
我该如何在模块中定义它?我可以用某种方式扩展Book,就像这样使用它
Book.get({ id: 42 }).Comment.query(function(comments) {
console.log(comments);
});
Run Code Online (Sandbox Code Playgroud) 我正在不同的机器(PostgreSQL)上使用相同的数据库模式.我想知道,如何将数据从一台机器合并到另一台机器.Schema有很多表(大约10个).我想要实现什么?
我正在尝试从机器A转储数据到简单的SQL插入命令,但是当我尝试恢复它时,我收到重复的密钥错误.更重要的是,我想从命令行恢复数据(我必须导入250 MB数据),因为现在我正在尝试使用pgAdmin手动执行此操作.
最好的方法是什么?
在post
过滤器中使用Zuul作为代理时如何读取响应主体?
我试图像这样调用代码:
@Component
public class PostFilter extends ZuulFilter {
private static final Logger log = LoggerFactory.getLogger(PostFilter.class);
@Override
public String filterType() {
return "post";
}
@Override
public int filterOrder() {
return 2000;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
ctx.getResponseBody(); // null
// cant't do this, cause input stream is used later in other filters and I got InputStream Closed exception
// GZIPInputStream gzipInputStream = new GZIPInputStream(stream);
return …
Run Code Online (Sandbox Code Playgroud) 如何在IntelliJ中的Groovy中提取变量(cmd+ alt+ v)来得到这个:
Car car = new Car()
Run Code Online (Sandbox Code Playgroud)
而不是这个?
def car = new Car()
Run Code Online (Sandbox Code Playgroud) 我想在Java SE中使用
@Stateless
public class CarDAO {
@Inject
private EntityManager em;
public Car findById(Long id) {
return em.find(Car.class, id);
}
}
@Singleton
public class Application {
@Inject
private CarDAO carDAO;
public void run() {
Car car = carDAO.findById(44);
System.out.println(car);
}
}
public class EntryPoint {
public static void main(String[] args) {
Application application = // missing code
application.run();
}
}
Run Code Online (Sandbox Code Playgroud)
我必须做些什么才能实现这一目标?我在我的项目中使用postgres数据库和maven.
我已经读过一些关于Weld的内容(但它看起来只有CDI).我不知道如何添加到Weld possibilty来注入实体管理器.我知道我可以获得实体经理
EntityManagerFactory emf = Persistence.createEntityManagerFactory("mgr");
EntityManager em = emf.createEntityManager();
Run Code Online (Sandbox Code Playgroud)
但它不如注射方便.
如果有任何相关的教程,那将是很棒的.无论如何,谢谢你的帮助!
我的配置如下:
的pom.xml
<dependencies>
<!-- Swagger -->
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>0.9.1</version>
</dependency>
<!-- Swagger WebJar -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>2.0.24</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
根的context.xml
<mvc:annotation-driven/>
<beans:bean class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />
Run Code Online (Sandbox Code Playgroud)
我将我的应用程序部署到Tomcat 8.0中.我能够在URI上看到Swagger JSON数据:
http://localhost:8080/myapp/api-docs
Run Code Online (Sandbox Code Playgroud)
但我无法运行Swagger UI.我还应该在项目中运行Swagger UI?
这是否可以以编程方式设置Android lockreen所有者信息?
所有者信息我的意思是"Alex Dobie",如下图所示:
java ×4
cdi ×2
android ×1
angularjs ×1
groovy ×1
java-8 ×1
java-ee ×1
java-stream ×1
jpa ×1
lambda ×1
netflix-zuul ×1
pg-dump ×1
postgresql ×1
proxy ×1
refactoring ×1
rest ×1
restful-url ×1
scala ×1
spring ×1
swagger ×1
swagger-ui ×1
tomcat ×1
weld ×1