我正在寻找检查字符串是否包含关键字列表中的子字符串的最佳方法.
例如,我创建一个这样的列表:
List<String> keywords = new ArrayList<>();
keywords.add("mary");
keywords.add("lamb");
String s1 = "mary is a good girl";
String s2 = "she likes travelling";
Run Code Online (Sandbox Code Playgroud)
字符串s1具有来自关键字的"mary",但字符串s2没有它.所以,我想定义一个方法:
boolean containsAKeyword(String str, List<String> keywords)
Run Code Online (Sandbox Code Playgroud)
哪里containsAKeyword(s1, keywords)会返回true但containsAKeyword(s2, keywords)会返回false.即使有一个子字符串匹配,我也可以返回true.
我知道我可以遍历关键字列表并在列表中的每个项目上调用str.contains(),但我想知道是否有更好的方法来迭代完整列表(避免O(n)复杂性)或者Java为此提供了任何内置方法.
我的CSV文件的前几行看起来像这样(从Notepad ++查看时):
跟踪,原始序列号,新序列号0000073800000000097612345678901234567890,0054,0001
当我在excel中打开这个文件时,我得到了这个:

出于某种原因,excel会截断序列号和跟踪号.我已经尝试将格式更改为Text但仍然无法正常工作,因为excel只能看到高达6的值:
7.38000000000976E + 34
如果我将其更改为Number:
73800000000097600000000000000000000.00
我能做什么?我只有60行,所以如果我必须重新开始,有些人会如何将文本重新复制到excel中,但我担心保存它会再次改变格式.
我正在尝试将Travis CI添加到我的Android项目中以便为我运行测试.目前我只是尝试使用CI来构建和清理我的项目,但它不起作用,它似乎在一段时间后挂起并在最终错误输出之前在日志中无限重复.以下是日志示例:https://gist.github.com/AdamMc331/6da4433a047815d8e072bf2b7fb81a44
我完全被这个困惑了.我不知道问题是什么.下面是我的.travis.yml文件:
language: android
android:
components:
- tools
- platform-tools
- build-tools-25.0.2
- extra-android-m2repository
- extra-android-support
- android-25
jdk:
- oraclejdk8
script:
- chmod +x gradlew
- ./gradlew clean build --stacktrace --info
licenses:
- android-sdk-license-.+
notifications:
email: false
sudo: false
cache:
directories:
- $HOME/.gradle
Run Code Online (Sandbox Code Playgroud)
我已经尝试将--debug添加到gradle任务中,但它没有多大帮助.一旦文件命中"尝试启动构建工具"行,就不会再打印[DEBUG]语句.
如果有人想分叉项目并亲自尝试,我使用分支CC-46:https://github.com/AdamMc331/CashCaretaker/tree/feature/CC-46如果你看看settings.gradle文件你'请注意我现在只使用utility和app-v2模块.
当我在终端本地运行这些命令时,这是一个日志文件:https://gist.github.com/AdamMc331/6d0d0575aa170a760c84ad3244aed1b7
您可以看到它也尝试在那里启动构建工具,但它不会尝试15次不同的时间,它最终会在没有错误的情况下工作.travis构建必须做一些不同的事情.
我在我的项目中使用数据绑定,我有一个用于从视图模型设置可见性条件:
<View
app:visibilityCondition="@{viewModel.showingItems}" />
Run Code Online (Sandbox Code Playgroud)
这一切都很好,但是突然间我想在这样的包含标签上使用它时:
<include
layout="@layout/my_include_layout
app:visibilityCondition="@{viewModel.showingItems}" />
Run Code Online (Sandbox Code Playgroud)
它不会构建,并出现以下错误:
e: [kapt] 发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误。在 com.example.CustomBinding 上找不到参数类型为 boolean 的属性“app:visibilityCondition”的设置器。
由于CustomBinding该类实际上并未从 扩展View,而是从 扩展ViewDataBinding,因此看起来我没有办法做到这一点。
有没有办法解决这个问题,还是我被迫以编程方式设置这个包含布局的可见性?我知道这会起作用,但如果可能的话,我真的很想将它保留在数据绑定中。
我正在尝试从我的应用程序更改锁定屏幕背景图像,但我无法弄清楚如何做到这一点.我成功地使用WallPaperManager更改了主屏幕壁纸,但找不到为锁定屏幕执行相同操作的源.我知道QuickPic和Stock Gallery这样的应用程序会这样做,所以我该如何实现呢?
这是我用来更改主屏幕的代码:
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
try {
myWallpaperManager.setBitmap(bm);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
有人实施了这个请指出我正确的方向与我的应用程序这样做?
我目前正在为我的应用程序中的ContentProvider编写测试用例(这是一个支票簿录制应用程序),并且在比较双值时我遇到了测试失败.说明这一点的最好方法是使用代码.我有这个函数返回要插入数据库的帐户对象的ContentValues:
private ContentValues getAccountContentValues(){
String testName = "Capital One";
double testStartingBalance = 3000.00;
ContentValues accountValues = new ContentValues();
accountValues.put(AccountEntry.COLUMN_NAME, testName);
accountValues.put(AccountEntry.COLUMN_BALANCE, testStartingBalance);
return accountValues;
}
Run Code Online (Sandbox Code Playgroud)
在函数内部,testInsertReadProvider()我有以下代码,以插入该帐户:
// Get Account values and write them
ContentValues accountValues = getAccountContentValues();
Uri accountInsertUri =
mContext.getContentResolver().insert(AccountEntry.CONTENT_URI, accountValues);
long accountRowId = ContentUris.parseId(accountInsertUri);
// Verify we got a row back
assertTrue(accountRowId > 0);
// A cursor is the primary interface to the query results
Cursor cursor = mContext.getContentResolver().query(
AccountEntry.CONTENT_URI, // Table name
null, // columns …Run Code Online (Sandbox Code Playgroud) 我有一个包含RecyclerView的Fragment来显示给定日期的事件.我使用ViewPager将片段分成多天; 周六活动的片段和周日活动的片段.
但是,看起来两个片段都引用相同的RecyclerView和/或Adapter,因为它只是显示其事件的最后一个选项卡(在本例中为Sunday).
在我的具体案例中,星期六有两个事件,周日没有事件.两个片段都有空的RecyclerViews.为了证实我的理论它是由最后一个标签引起的,我改变了日期.这导致RecyclerViews有两个事件(周六的事件).
以下是各个片段的相关代码:
public class EventListFragment extends Fragment{
private EventAdapter mEventAdapter;
private static final String DATE_ARG = "eventDate";
public static EventListFragment newInstance(LocalDate date){
EventListFragment eventListFragment = new EventListFragment();
Bundle args = new Bundle();
args.putSerializable(DATE_ARG, date);
eventListFragment.setArguments(args);
return eventListFragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_event_list, container, false);
// Setup recyclerview
RecyclerView eventRecyclerView = (RecyclerView) view.findViewById(R.id.event_recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
eventRecyclerView.setLayoutManager(layoutManager);
// Get date
LocalDate eventDate = (LocalDate) …Run Code Online (Sandbox Code Playgroud) android android-fragments android-viewpager android-recyclerview
我有一个使用3个字母的字符串的switch语句.对于很多情况(但不是全部)我只想关注前2个字母.
例如,我希望每个以"FF"开头的代码都处理相同:
switch(code)
{
case "FF(?)":
// Handle it
break;
default:
break;
}
Run Code Online (Sandbox Code Playgroud)
我能在这做什么?我可以使用通配符吗?我是否必须考虑每个FF代码?
出于显而易见的原因,我不希望有这样的代码,这可能会变得非常大:
case "FFA":
case "FFB":
case "FFD":
// Handle it
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种根据自定义字母表对字符串列表进行排序的有效方法.
例如,我有一个字符串字母表,它是一个字符串"bafmxpzv"列表,仅由该字母表中包含的字符组成.
我想要一种方法来排序该列表与其他常见排序类似,但使用此自定义字母表.我怎样才能做到这一点?
我的应用程序中有三个活动
我想使用espresso来测试一系列事件:单击登录活动上的登录按钮,打开主活动,然后单击主活动中的列表项,打开详细活动,然后单击详细信息中的另一个按钮活动.我开始创建这个简单的测试,以获得对listview的引用:
public class LoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {
public LoginActivityTest() {
super(LoginActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
getActivity();
}
public void testSequence() throws Exception {
// Login
onView(withId(R.id.button_log_in)).perform(click());
// Check if MainActivity is loaded
onView(withId(R.id.container)).check(matches(isDisplayed()));
// Check if Fragment is loaded
onView(withId(R.id.list)).check(matches(isDisplayed()));
}
}
Run Code Online (Sandbox Code Playgroud)
在mainActivity onCreate()方法中,我加载一个像这样的片段:
getFragmentManager().beginTransaction()
.add(R.id.container, mListFragment)
.commit();
Run Code Online (Sandbox Code Playgroud)
该ListFragment片段有一个列表(R.id.list),但仍是测试失败了NoMatchingViewException:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.tests.android.development:id/list
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
java android functional-testing android-fragments android-espresso