我想阅读Java快速入门中描述的Google电子表格
https://developers.google.com/sheets/quickstart/java
快速入门说明了如何从给定范围读取数据
.....
String range = "Class Data!A2:E";
ValueRange response = service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List<List<Object>> values = response.getValues();
....
Run Code Online (Sandbox Code Playgroud)
但我有一个问题,我不知道电子表格的范围.列数可以更改.那么如何在不知道范围的情况下阅读Sheet的所有数据呢?
问候
迈克尔
在这里,我在演示者中获得了一些代码示例.如何在改装调用中为onSuccess和onFailure编写测试
public void getNotifications(final List<HashMap<String,Object>> notifications){
if (!"".equalsIgnoreCase(userDB.getValueFromSqlite("email",1))) {
UserNotifications userNotifications =
new UserNotifications(userDB.getValueFromSqlite("email",1),Integer.parseInt(userDB.getValueFromSqlite("userId",1).trim()));
Call call = apiInterface.getNotifications(userNotifications);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
UserNotifications userNotifications1 = (UserNotifications) response.body();
if(userNotifications1.getNotifications().isEmpty()){
view.setListToAdapter(notifications);
onFailure(call,new Throwable());
}
else {
for (UserNotifications.Datum datum:userNotifications1.getNotifications()) {
HashMap<String,Object> singleNotification= new HashMap<>();
singleNotification.put("notification",datum.getNotification());
singleNotification.put("date",datum.getDate());
notifications.add(singleNotification);
}
view.setListToAdapter(notifications);
}
}
@Override
public void onFailure(Call call, Throwable t) {
call.cancel();
}
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我如何编写单元测试来涵盖这段代码的所有情况.
谢谢
当我尝试连接谷歌自定义搜索 api glassfish 时抛出 nosuchmethoderror
这就是代码
private int conn (String search)throws Exception {
String key="mykey";
URL url = new URL("https://www.googleapis.com/customsearch/v1?q="+search+"&cx=017576662512468239146%3Aomuauf_lfve&key="+key);
doTrustToCertificates();
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader((connection.getInputStream())));
String splitreader = "";
StringBuilder ss = new StringBuilder();
while((splitreader = reader.readLine()) != null){
ss.append(splitreader);
}
JSONObject json = new JSONObject(ss.toString());
JSONObject jsonrequest = json.getJSONObject("queries").getJSONArray("request").getJSONObject(0);
return jsonrequest.getInt("totalResults");
}
public void doTrustToCertificates() throws Exception {
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() …Run Code Online (Sandbox Code Playgroud) 我正在使用异步RFC调用在SAP中进行一些并行工作。在这里您可以看到我的伪代码。
* class variable
data: gv_counter type i .
....
method start_tasks .
do 10 times .
call function 'my_remote_function'
starting new task task_identifier
calling task_finish on end of task .
enddo .
wait for asynchronous tasks until gv_counter eq 10 .
endmethod .
.....
method task_finish .
gv_counter = gv_counter + 1 .
endmethod .
Run Code Online (Sandbox Code Playgroud)
如您所见,我开始了10个过程,然后等到它们全部完成为止。
我的问题是关于方法task_finish和对全局类变量的访问gv_counter。如何确保对变量的访问gv_counter是同步的?
例如在Java中,我会做类似的事情:
synchronized {
gv_counter += 1 ;
}
Run Code Online (Sandbox Code Playgroud)