我在类中有一个方法,它初始化一个HashMap并在其中放入一些键和值,然后该方法返回HashMap.如何检索返回的HashMap?
public Map<String, String> getSensorValue(String sensorName) {
registerSensor(sensorName);
sensorValues.put("x","25");
sensorValues.put("y","26");
sensorValues.put("z","27");
return sensorValues;
}
Run Code Online (Sandbox Code Playgroud)
在这里,我从另一个类调用此方法:
public static HashMap<String, String> sensValues = new HashMap<String, String>();
AllSensors sensVal = new AllSensors();
sensValues.putAll(sensVal.getSensorValue("orientation"));
String something = sensValues.get("x");
Run Code Online (Sandbox Code Playgroud)
但它不会以这种方式起作用
sensValues.putAll(sensVal.getSensorValue("orientation"));
Run Code Online (Sandbox Code Playgroud)
使我的Android应用程序崩溃.重点是以某种方式回溯返回的HashMap.
我有一个Android应用程序,它有一个计时器来运行任务:
time2.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
sendSamples();
}
}, sampling_interval, sending_interval);
Run Code Online (Sandbox Code Playgroud)
让我们说sampling_interval是2000,sending_interval是4000.
所以在这个应用程序中,我将一些读数值从传感器发送到服务器.但我想在10000(10秒)后停止发送.
我该怎么办?
我对此感到有点困惑,所以我会对此表示赞赏.
public <T extends Animal> void addAll(List<T> animals)
Run Code Online (Sandbox Code Playgroud)
与
public void addAll(List<Animal> animals)
Run Code Online (Sandbox Code Playgroud) 我正在编写一个控制器,我需要让它异步.我该如何处理清单ListenableFuture?因为我有一个URL列表,我需要逐个发送GET请求,它的最佳解决方案是什么?
@RequestMapping(value = "/repositories", method = RequestMethod.GET)
private void getUsername(@RequestParam(value = "username") String username) {
System.out.println(username);
List<ListenableFuture> futureList = githubRestAsync.getRepositoryLanguages(username);
System.out.println(futureList.size());
}
Run Code Online (Sandbox Code Playgroud)
在我使用的服务List<ListanbleFuture>中似乎不起作用,因为它是异步的,在控制器方法中,我不能为回调futureList运行一个大小for loop.
public List<ListenableFuture> getRepositoryLanguages(String username){
return getRepositoryLanguages(username, getUserRepositoriesFuture(username));
}
private ListenableFuture getUserRepositoriesFuture(String username) throws HttpClientErrorException {
HttpEntity entity = new HttpEntity(httpHeaders);
ListenableFuture future = restTemplate.exchange(githubUsersUrl + username + "/repos", HttpMethod.GET, entity, String.class);
return future;
}
private List<ListenableFuture> getRepositoryLanguages(final String username, ListenableFuture<ResponseEntity<String>> future) {
final List<ListenableFuture> futures = new ArrayList<>(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 PHP 中的 GNUPLOT 绘制正弦图,但是当我exec用来绘制图形时,出现此错误:
警告:exec() [function.exec]:无法在第 8 行的 /Library/WebServer/Documents/serverSide2.php 中执行空白命令
这是我的代码:
exec(`echo "set term png;set xrange[-2*pi:2*pi]; set output 'output.png'; plot sin(x)" | gnuplot`);
Run Code Online (Sandbox Code Playgroud)
我也使用了 passthru() 但得到了同样的错误:警告:passthru() [function.passthru]: 无法在第 8 行的 /Library/WebServer/Documents/serverSide2.php 中执行空白命令
但是我使用终端来检查代码是否有效,所以我输入了这个代码:
echo "set term png;set xrange[-2*pi:2*pi]; set output 'output.png'; plot sin(x)" | gnuplot
它工作正常并给了我情节。
我知道我该怎么办?
我有一个字符串数组,其中包含智能手机中可用的传感器列表.在这个数组中,如果匹配,我想要的每个元素,替换整个字符串.
例如:
sensor[1] = "iEnemoEngine orientation sensor";
Run Code Online (Sandbox Code Playgroud)
我想如果sensor[1]包含"orientation"这个词,用"orientation"替换整个字符串"iEnemoEngine orientation sensor"
我该怎么办?