我正在使用核心数据来存储和获取我的数据,但我遇到了一些问题.我想使用两个并行线程进行以下操作:
我怎么能这样做?
我对谷歌进行了一些研究,他们说,我们需要使用多个托管对象上下文,但我不知道我们将如何使用它.
所以...基本上我有一个docx文件.我必须在几个段落中进行一些格式更改,然后保存在一个新文件中.我正在做的主要是遵循.
import scala.collection.JavaConversions._
import org.apache.poi.xwpf.usermodel._
def format( sourceDocumentPath: String, outputDocumentPath: String ) {
val sourceXWPFDocument = new XWPFDocument( new FileInputStream( sourcePath ) )
// lets say I have a list of paragraph numbers... I want to format
val parasToFormat = List( 2, 10, 15, 20 )
val allParagraphs = sourceXWPFDocument.getParagraphs
for ( ( paragraph, index ) <- allParagraphs.zipWithIndex ) {
if( parasToFormat.contains( index ) ) {
formatParagraph( paragraph )
}
}
val outputDocx = new FileOutputStream( new File( outputDocumentPath ) …
Run Code Online (Sandbox Code Playgroud) 我试图在将来改变FSM状态,但我不工作..我想我正在寻找pipeTo like方法.
When(State.Waiting) {
case Event(anyMsg, anyData) =>
asyncCode.map(res =>
if (res == 1) {
goto(State.Working) using Data.MyData
} else {
stay() replying "bad response"
}
)
}
Run Code Online (Sandbox Code Playgroud)
goto命令被执行但fsm不会将状态更改为State.Working
我自己找到了这个工作
When(State.Waiting) {
case Event(anyMsg, anyData) =>
asyncCode.map(res =>
if (res == 1) {
self ! "do job"
} else {
stay() replying "bad response"
}
)
case Event("do job", anyData) => {
goto(State.Working) using Data.MyData
}
}
Run Code Online (Sandbox Code Playgroud)
可能有一个更好的主意来解决问题
我正在制作一个基于太空入侵者的2D java游戏.在我的Game类中,我有以下3个字段:
//enemies left to kill
private LinkedList<Enemy> enemiesLeft = new LinkedList<Enemy>();
//enemies killed
private LinkedList<Enemy> enemiesKilled = new LinkedList<Enemy>();
//missiles that have been fired
private LinkedList<Missile> missiles = new LinkedList<Missile>();
Run Code Online (Sandbox Code Playgroud)
在我的checkCollision()
方法,我通过每个运行Enemy
的enemiesLeft
列表,并检查每次碰撞Missile
的missiles
列表,但它抛出一个ConcurrentModificationException
.
这是checkCollision()
方法:
private void checkCollisions(){
//make an iterator over enemies
ListIterator<Enemy> iterEnemies = enemiesLeft.listIterator();
//loop through enemies
while(iterEnemies.hasNext()){
//error is thrown at below line
Enemy e = iterEnemies.next(); //current Enemy
//go through each Missile
ListIterator<Missile> …
Run Code Online (Sandbox Code Playgroud) 我想在我的MacOS中截取某些应用程序的屏幕截图,即使在另一个虚拟屏幕上也没有在活动屏幕中.
我可以使用以下代码进行活动屏幕捕获,但如何捕获给定的应用程序?
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.imageio.ImageIO;
public class Screenshot {
public static void main(String args[]) throws AWTException, IOException {
while(true) {
String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
BufferedImage screencapture = new Robot().createScreenCapture(
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())
);
// Save as JPEG
File file = new File("./screens/screencapture" + timeStamp + ".jpg");
ImageIO.write(screencapture, "jpg", file);
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一些代码,用于将一些测试数据播种到我正在开发的关于神奇宝贝的应用程序的核心数据数据库中.我的播种代码基于此:http://www.andrewcbancroft.com/2015/02/25/using-swift-to-seed-a-core-data-database/
我有一件事有点问题.我似乎无法在元组中添加nil值.
我正在尝试将一些神奇宝贝动作播种到数据库中.移动可以有许多不同的属性,但它具有哪种组合完全取决于移动本身.所有种子移动数据都在元组数组中.
展示...
let moves = [
(name: "Absorb", moveType: grass!, category: "Special", power: 20, accuracy: 100, powerpoints: 25, effect: "User recovers half the HP inflicted on opponent", speedPriority: 0),
// Snip
]
Run Code Online (Sandbox Code Playgroud)
......很好.这是一个包含所有上述属性的举动,其中speedPriority为零意味着什么.但是,有些动作没有动力或精确属性,因为它们与特定动作无关.但是,在数组中创建第二个元组而没有命名元素的幂或精度,例如......
(name: "Acupressure", moveType: normal!, category: "Status", powerpoints: 30, effect: "Sharply raises a random stat", speedPriority: 0)
Run Code Online (Sandbox Code Playgroud)
......可以理解地抛出一个错误
元组类型{firstTuple}和{secondTuple}具有不同数量的元素(8对6)
因为,元组有不同数量的元素.所以相反,我试过......
(name: "Acupressure", moveType: normal!, category: "Status", power: nil, accuracy: nil, powerpoints: 30, effect: "Sharply raises …
Run Code Online (Sandbox Code Playgroud) 我正在研究一个运行很长时间的Meteor应用程序,我正在寻找一种在没有用户活动时保持屏幕的方法(当然应用程序在运行时).
谢谢
我正在编写Spring MVC控制器,它将接受多部分文件上传(从HTML表单上传文件的标准方法).
Servlet 3.0规范引入了servlet容器处理multipart/form-data的标准方法,引入了MultipartConfigElement用于配置和Part接口,Spring MVC与它们集成,没有任何问题.
问题:我希望获得通过Part.write()
方法输出的文件的完整路径,跳过不必要的InputStream
读取.由于文件大小的原因,上传到我的控制器的文件最有可能最终由servlet容器输出到磁盘的临时文件,因此Part.write()
会将文件移动到目标名称而不是滥用RAM资源.根据规范,该文件是相对于配置的多部分位置编写的.
我想出的解决方案是这样的:
@RestController
@RequestMapping("/upload")
public class UploadController {
@Autowired
private MultipartConfigElement multipartConfigElement;
@RequestMapping(value = "/{uploadId}", method = RequestMethod.POST)
public String handleMultipartFileUpload(
@PathVariable String uploadId,
@RequestParam("file") List<Part> files) throws IOException {
for (Part uploadedPart : files) {
String temporaryFileName = UUID.randomUUID().toString();
uploadedPart.write(temporaryFileName);
// CODE-SMELL FOLLOWS:
Path temporaryFilePath = FileSystems.getDefault().getPath(
multipartConfigElement.getLocation()).resolve(temporaryFileName);
}
return "handleMultipartFileUpload";
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码气味评论就是这样:代码味道.我使用autowired创建了写入文件的路径MultipartConfigElement
,Spring恰好将其作为bean.问题是:
MultipartConfigElement
bean的应用程序怎么样?我想根据白色分割一个字符串,但是我知道字符串的某些部分将用引号引起来,并且其中会有空格,所以我不希望它分割封装在双引号中的字符串。
if (file == null) return;
else
{
using (StreamReader reader = new StreamReader(file))
{
string current_line = reader.ReadLine();
string[] item;
do
{
item = Regex.Split(current_line, "\\s+");
current_line = reader.ReadLine();
echoItems(item);
}
while (current_line != null);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的分割将分割,即使它被引用,例如“大城市”会出现在我的数组中:
0:“大
1:城镇”
编辑:在尝试@vks答案后,我只能让IDE接受所有引号:Regex.Split(current_line, "[ ](?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
Item 是一个数组,我的 print 方法在打印数组内容时在每个元素周围放置一个“[]”。这是我的输出:
[0 0 0 1 2 1 1 1 "Album" 6 6 11 50 20 0 0 0 40 40 0 0 0 1 1] [] [1] [] [1] [] [1] [] …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个应用程序,我需要使用它连接到Active Directory UnboundID
.使用一个例子,我设法将用户与他们distinguishedName
和password
.
但是,我想仅使用domain
和username
它进行身份验证,类似于在Windows中完成的操作.使用名为JXplorer
它的工具浏览AD 似乎sAMAccountName
可能是我需要的属性.但是,distinguishedName
使用sAMAccountName 替换会导致AcceptSecurityContext
错误.使用"uid=..."
示例中显示的语法也产生了相同的错误.
有没有办法只使用域登录,username
/ sAMAccountName
和password
.或者我是否需要通过AD搜索并找到distinguishedName
我想要进行身份验证的用户,然后使用他们distinguishedName
和password
?绑定连接?
java ×5
scala ×2
akka ×1
apache-poi ×1
c# ×1
core-data ×1
fsm ×1
ios ×1
iphone ×1
ldap ×1
linked-list ×1
macos ×1
meteor ×1
null ×1
regex ×1
screenshot ×1
servlet-3.0 ×1
spring-mvc ×1
swift ×1
tuples ×1