示例#1
0
 @Test
 public void testWithGenericType() {
   val arrayDequeCallable =
       Type.of("java.util.ArrayDeque").withTypeArgument(Type.of("java.util.Callable"));
   assertEquals("java.util.ArrayDeque", arrayDequeCallable.getClassName());
   assertEquals("java.util.Callable", arrayDequeCallable.getTypeArguments().get(0).getClassName());
 }
 @Test
 public void equals_different_TYPE() {
   final Attribute a = new Blueprint().type(Type.of(String.class)).build();
   final Attribute b = new Blueprint().type(Type.of(Integer.class)).build();
   assertFalse(a.equals(b));
   assertFalse(a.hashCode() == b.hashCode());
 }
  /** Executes command to update one value in the shared preferences */
  private void doWrite(List<String> args) throws DumpUsageException {
    String usagePrefix = "Usage: prefs write <path> <key> <type> <value>, where type is one of: ";

    Iterator<String> argsIter = args.iterator();
    String path = nextArg(argsIter, "Expected <path>");
    String key = nextArg(argsIter, "Expected <key>");
    String typeName = nextArg(argsIter, "Expected <type>");

    Type type = Type.of(typeName);
    if (type == null) {
      throw new DumpUsageException(
          Type.appendNamesList(new StringBuilder(usagePrefix), ", ").toString());
    }

    SharedPreferences sharedPreferences = getSharedPreferences(path);
    SharedPreferences.Editor editor = sharedPreferences.edit();

    switch (type) {
      case BOOLEAN:
        editor.putBoolean(key, Boolean.valueOf(nextArgValue(argsIter)));
        break;
      case INT:
        editor.putInt(key, Integer.valueOf(nextArgValue(argsIter)));
        break;
      case LONG:
        editor.putLong(key, Long.valueOf(nextArgValue(argsIter)));
        break;
      case FLOAT:
        editor.putFloat(key, Float.valueOf(nextArgValue(argsIter)));
        break;
      case STRING:
        editor.putString(key, nextArgValue(argsIter));
        break;
      case SET:
        putStringSet(editor, key, argsIter);
        break;
    }

    editor.commit();
  }
示例#4
0
 private void testOf(String in, String expected) {
   Assert.assertEquals(expected, Type.of(in).descriptor);
 }
 public Type getType() {
   return Type.of(core_.getType());
 }