我读过Room Persistence Library.我还克隆了android-architecture-components,然后我尝试添加Mirgration测试.但是,我无法导入
import android.arch.persistence.room.testing.MigrationTestHelper;
Run Code Online (Sandbox Code Playgroud)
我也使用最新的lib版本.
android.arch.core:core-testing:1.0.0-alpha3
Run Code Online (Sandbox Code Playgroud)
这是MigrationTest的代码
import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import android.arch.persistence.room.testing.MigrationTestHelper;
@RunWith(AndroidJUnit4.class)
public class MigrationTest {
private static final String TEST_DB = "migration-test";
@Rule
public MigrationTestHelper helper;
public MigrationTest() {
helper = new MigrationTestHelper(InstrumentationRegistry.getInstrumentation(),
MigrationDb.class.getCanonicalName(),
new FrameworkSQLiteOpenHelperFactory());
}
@Test
public void migrate1To2() throws IOException {
SupportSQLiteDatabase db = helper.createDatabase(TEST_DB, 1);
// db has schema version 1. insert some data using SQL …Run Code Online (Sandbox Code Playgroud) android database-migration android-room android-architecture-components
我对Android感兴趣并且一直在尝试查找有关创建自定义锁屏的示例或教程.
我想创建新的锁屏,以方便访问.
例如
我想为盲人设计锁屏.
我使用java 1.7.25但发现此错误.我该怎么办?
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Unknown pattern character 'u'
at java.text.SimpleDateFormat.validateFormat(SimpleDateFormat.java:264)
at java.text.SimpleDateFormat.validatePattern(SimpleDateFormat.java:319)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:365)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:249)
Run Code Online (Sandbox Code Playgroud)
这是我的代码
public static int getDayNumberOfWeek(int day, String monthString, int yyyy) {
//http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
int dayNumberOfWeek = 1;
final String inputFormat = "MMM/dd/yyyy";
final String outputFormat = "u";
String dayString2Digit = DateTimeHelper.getTwoDigit(day);
String inputTimeStamp = monthString + "/" + dayString2Digit + "/" + String.valueOf(yyyy);
try {
dayNumberOfWeek =Integer.valueOf(TimeStampConverter(inputFormat, inputTimeStamp,
outputFormat));
}
catch (ParseException e) {
e.printStackTrace();
}
return dayNumberOfWeek;
}
Run Code Online (Sandbox Code Playgroud) 我已将java shellSort转换为Kotlin.问题是我不知道这个方法.
Java的
package Sorts;
public class ShellSort extends Sorter{
@Override
public <T extends Comparable<? super T>> void sort(T[] a) {
int h = 1;
while((h*3+1) < a.length)
h = 3*h+1;
while(h > 0){
for(int i = h-1; i < a.length; i++){
T s = a[i];
int j = i;
for(j = i; (j>=h) && (a[j-h].compareTo(s) > 0); j-=h)
a[j] = a[j-h];
a[j] = s;
}
h /= 3;
}
}
}
Run Code Online (Sandbox Code Playgroud)
科特林
fun <T : Comparable<T>> shellSort(a: …Run Code Online (Sandbox Code Playgroud) 当我们像这样用 Kotlin 创造乐趣时
fun foo(bar: Int = 0, baz: Int) { /* ... */ }
foo(baz = 1) // The default value bar = 0 is used
Run Code Online (Sandbox Code Playgroud)
所以在java中我们需要这样写
不需要写
void foo(int bar, int baz){
...
}
void foo(int baz){
foo(0,baz);
}
Run Code Online (Sandbox Code Playgroud)
让我们想象一下,如果我们有 10 个以上的参数。我想知道 Kotlin 如何处理这个问题。Kotlin 会生成所有可能的方法吗?或者它只是生成程序员真正使用的方法?
我想知道是否有更好的方法或惯用的方法来使用 Kotlin 计算数组中的最大 int 并且比 O(nlogn) 更快?
这段代码给出了 O(n) 但我觉得它太长了
fun countMax(n: Int, ar: Array<Int>): Int {
val max = ar.max();
var countMax = 0
for(i in ar)
if(i==max)
countMax++
return countMax
}
fun main(args: Array<String>) {
val scan = Scanner(System.`in`)
val n = scan.nextLine().trim().toInt()
val ar = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
val result = birthdayCakeCandles(n, ar)
println(result)
}
Run Code Online (Sandbox Code Playgroud)
排序然后计数得到 nlogn
val input: Scanner = if (inputFile.exists()) Scanner(inputFile) else Scanner(System. in)
fun main(args: Array<String>) {
input.nextLine()
val nums = …Run Code Online (Sandbox Code Playgroud) 我读过Kotlin 文档
<init>(size: Int, init: (Int) -> Boolean)
Run Code Online (Sandbox Code Playgroud)
创建指定大小的新数组,其中每个元素都是通过调用指定的 init 函数计算的。
从第一个元素开始按顺序为每个数组元素调用 init 函数。它应该返回给定索引的数组元素的值。
Common JVM JS Native (size: Int) 创建指定大小的新数组,所有元素初始化为 false。
构造函数 创建指定大小的新数组,所有元素都初始化为 false。
<init>(size: Int)
Run Code Online (Sandbox Code Playgroud)
创建指定大小的新数组,所有元素都初始化为 false。
构造函数 创建指定大小的新数组,所有元素都初始化为 false。
也尝试简单的代码
var booleanArray = <init>(30)
Run Code Online (Sandbox Code Playgroud)
它仍然不起作用。有什么帮助吗?
我用sqlite和使用内容提供程序实现了android数据库.
但我的数据库中的数据未加密.
有没有最好的实践来实现Android设备的安全数据库?
我的意思不仅仅是加密,还包括可以提高我的应用程序安全性的任何技术.
我刚刚开始试用JUnit.我创建了一些测试用例.但是,当我发现任何错误的测试用例时,测试用例将停止.即使有很多错误的测试用例,我想要遍历每个测试用例.
例如
assertEquals ( "this test case will be shown", Main.plus ( 1,2 ),3 );
assertEquals ( "this first wrong test case will be shown", Main.plus ( 1, 2 ), 4 );
assertEquals ( "this first wrong test case **won't be shown**", Main.plus ( 1, 2 ), 4 );
Run Code Online (Sandbox Code Playgroud)
我想让第三个案例运行(表明它是错的)
注意:ErrorCollector规则允许在找到第一个问题后继续执行测试(例如,收集表中的所有不正确的行,并立即报告所有行):
更多信息在这里
http://junit.org/apidocs/org/junit/rules/ErrorCollector.html
android ×5
java ×4
kotlin ×4
arrays ×2
algorithm ×1
android-architecture-components ×1
android-room ×1
database ×1
generics ×1
junit ×1
lockscreen ×1
security ×1