小编sec*_*ret的帖子

HashMap返回方法

我在类中有一个方法,它初始化一个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.

java android hashmap

6
推荐指数
2
解决办法
7万
查看次数

如何在一定时间后停止计时器?

我有一个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秒)后停止发送.

我该怎么办?

java android timer

5
推荐指数
1
解决办法
8508
查看次数

public <T extends Animal> void addAll(List <T> animals)和public void addAll(List <Animal> animals)有什么区别?

我对此感到有点困惑,所以我会对此表示赞赏.

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)

java generics

4
推荐指数
1
解决办法
231
查看次数

如何处理多个ListenableFutures?(弹簧)

我正在编写一个控制器,我需要让它异步.我该如何处理清单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)

java spring asynchronous

4
推荐指数
1
解决办法
1924
查看次数

警告:exec() [function.exec]:无法在

我正在尝试使用 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 它工作正常并给了我情节。

我知道我该怎么办?

php gnuplot

3
推荐指数
1
解决办法
5076
查看次数

替换java中的整个字符串

我有一个字符串数组,其中包含智能手机中可用的传感器列表.在这个数组中,如果匹配,我想要的每个元素,替换整个字符串.

例如:

sensor[1] = "iEnemoEngine orientation sensor";
Run Code Online (Sandbox Code Playgroud)

我想如果sensor[1]包含"orientation"这个词,用"orientation"替换整个字符串"iEnemoEngine orientation sensor"

我该怎么办?

java android

2
推荐指数
1
解决办法
429
查看次数

标签 统计

java ×5

android ×3

asynchronous ×1

generics ×1

gnuplot ×1

hashmap ×1

php ×1

spring ×1

timer ×1