Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Builder模式链接UISelector对象的方法?_Java_Android_Android Uiautomator - Fatal编程技术网

Java 如何使用Builder模式链接UISelector对象的方法?

Java 如何使用Builder模式链接UISelector对象的方法?,java,android,android-uiautomator,Java,Android,Android Uiautomator,我正在尝试为UISelector对象创建一个生成器类。以下是我的生成器类的外观: ## UISelectorBuilder.class package com.company.builders; import android.support.test.uiautomator.UiSelector; public class UISelectorBuilder { /** * Constants. */ private final UiSelector u

我正在尝试为
UISelector
对象创建一个生成器类。以下是我的生成器类的外观:

## UISelectorBuilder.class

package com.company.builders;

import android.support.test.uiautomator.UiSelector;

public class UISelectorBuilder
{
    /**
     * Constants.
     */
    private final UiSelector uiSelector = new UiSelector();

    /**
     * Returns the {@link UiSelector}.
     * @return {@link UiSelector}
     */
    public UiSelector build()
    {
        return uiSelector;
    }

    /** ****** USER PROPERTIES *********

    /**
     * Method to generate a {@link UiSelector} based on the provided Class name.
     * @param aClassName The Class name
     * @return this
     */
    public UISelectorBuilder addClassName(final String aClassName)
    {
        this.uiSelector.className(aClassName);
        return this;
    }

    /**
     * Method to generate a {@link UiSelector} based on the provided description.
     * @param aDescription The description
     * @return this
     */
    public UISelectorBuilder addContainsDescription(final String aDescription)
    {
        this.uiSelector.descriptionContains(aDescription);
        return this;
    }

    /**
     * Method to generate a {@link UiSelector} based on the provided index.
     * @param aIndex The index #
     * @return this
     */
    public UISelectorBuilder addIndexOf(final int aIndex)
    {
        this.uiSelector.index(aIndex);
        return this;
    }

    /**
     * Method to generate a {@link UiSelector} based on the provided resource ID.
     * @param aResourceID The Resource ID
     * @return this
     */
    public UISelectorBuilder addResourceID(final String aResourceID)
    {
        this.uiSelector.resourceId(aResourceID);
        return this;
    }

    /**
     * Method to generate a {@link UiSelector} based on the provided text.
     * @param aText The text to match
     * @return this
     */
    public UISelectorBuilder addText(final String aText)
    {
        this.uiSelector.text(aText);
        return this;
    }

    /** ****** UI PROPERTIES *********

     /**
     * Method to generate a {@link UiSelector} based on whether the object is enabled or not.
     * @param isEnabled True or False
     * @return this
     */
    public UISelectorBuilder addIsEnabled(final boolean isEnabled)
    {
        this.uiSelector.enabled(isEnabled);
        return this;
    }

    /**
     * Method to generate a {@link UiSelector} based on whether the object is selected or not.
     * @param isSelected True or False
     * @return this
     */
    public UISelectorBuilder addIsSelected(final boolean isSelected)
    {
        this.uiSelector.selected(isSelected);
        return this;
    }
}

我希望能够通过只提供我想要的信息来动态创建
UISelector
对象。例如:一个
UISelector
可以只包含
resourceID
,而另一个可以另外包含
text

我使用生成器创建对象,如下所示:

new UISelectorBuilder().addResourceID(“resource”).build()

问题是my
UISelector
始终为空。我以前使用
ArrayList
创建过构建器,没有遇到任何问题,但这个似乎不起作用。有人对我遗漏的东西有什么建议吗

问候,


Arjun

如果您想要一些必填字段,请将它们设置为生成器构造函数的一部分
问题是我的UISelector始终为空
,您能详细说明什么是空的吗?如果您想要一些必填字段,请将它们设置为生成器构造函数的一部分
问题是我的UISelector始终为空
,什么是空的,你能详细说明一下吗?