How to use toString method of io.appium.java_client.remote.options.BaseMapOptionData class

Best io.appium code snippet using io.appium.java_client.remote.options.BaseMapOptionData.toString

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

BaseMapOptionData.java

Source: BaseMapOptionData.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client.remote.options;
18
19import com.google.gson.Gson;
20import com.google.gson.JsonObject;
21
22import java.util.Collections;
23import java.util.HashMap;
24import java.util.Map;
25import java.util.Optional;
26
27public abstract class BaseMapOptionData<T extends BaseMapOptionData<T>> {
28    private Map<String, Object> options;
29    private static final Gson gson = new Gson();
30
31    public BaseMapOptionData() {
32    }
33
34    public BaseMapOptionData(Map<String, Object> options) {
35        this.options = options;
36    }
37
38    public BaseMapOptionData(String json) {
39        //noinspection unchecked
40        this((Map<String, Object>) gson.fromJson(json, Map.class));
41    }
42
43    /**
44     * Sets the given value on the data object.
45     *
46     * @param key Key name.
47     * @param value The actual value to set.
48     * @return self instance for chaining.
49     */
50    public T assignOptionValue(String key, Object value) {
51        if (options == null) {
52            options = new HashMap<>();
53        }
54        options.put(key, value);
55        //noinspection unchecked
56        return (T) this;
57    }
58
59    /**
60     * Retrieves a value with the given name from a data object.
61     * This method does not perform any type transformation, but rather
62     * just tries to cast the received value to the given type, so
63     * be careful while providing a very specific result type value to
64     * not get a type cast error.
65     *
66     * @param name Key name.
67     * @param <R> The expected value type.
68     * @return The actual value.
69     */
70    public <R> Optional<R> getOptionValue(String name) {
71        //noinspection unchecked
72        return Optional.ofNullable(options)
73                .map(opts -> (R) opts.getOrDefault(name, null));
74    }
75
76    public Map<String, Object> toMap() {
77        return Optional.ofNullable(options).orElseGet(Collections::emptyMap);
78    }
79
80    public JsonObject toJson() {
81        return gson.toJsonTree(toMap()).getAsJsonObject();
82    }
83
84    @Override
85    public String toString() {
86        return gson.toJson(toMap());
87    }
88}
89
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in BaseMapOptionData

Trigger toString code on LambdaTest Cloud Grid

Execute automation tests with toString on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)