congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
DataModelReflection
Code IndexAdd Tabnine to your IDE (free)

How to use
DataModelReflection
in
com.asakusafw.testdriver.core

Best Java code snippets using com.asakusafw.testdriver.core.DataModelReflection (Showing top 18 results out of 315)

origin: asakusafw/asakusafw

  /**
   * Builds a reflection object with since added properties.
   * @return the built
   */
  public DataModelReflection build() {
    return new DataModelReflection(properties);
  }
}
origin: asakusafw/asakusafw

  public Object getValue(PropertyName name) {
    assert name != null;
    return model.getValue(name);
  }
}
origin: asakusafw/asakusafw

/**
 * Creates a new instance.
 * @param properties current property list
 * @throws IllegalArgumentException if some parameters were {@code null}
 */
public DataModelReflection(Map<PropertyName, ?> properties) {
  if (properties == null) {
    throw new IllegalArgumentException("properties must not be null"); //$NON-NLS-1$
  }
  this.properties = normalize(properties);
}
origin: asakusafw/asakusafw

  /**
   * return formatted value.
   * This method is equivalent to {@link DataModelReflection#toStringRepresentation(Object)}.
   * @param value target value.
   * @return formatted value.
   */
  public static String format(Object value) {
    return DataModelReflection.toStringRepresentation(value);
  }
}
origin: asakusafw/asakusafw

/**
 * Returns formatted string representation of values.
 * @param value original value
 * @return formatted string representation
 * @since 0.5.1
 */
public static String toStringRepresentation(Object value) {
  if (value instanceof String) {
    return toStringLiteral((String) value);
  } else if (value instanceof Calendar) {
    Calendar c = (Calendar) value;
    if (c.isSet(Calendar.HOUR_OF_DAY)) {
      return new SimpleDateFormat(DateTime.FORMAT).format(c.getTime());
    } else {
      return new SimpleDateFormat(Date.FORMAT).format(c.getTime());
    }
  } else if (value instanceof BigDecimal) {
    return ((BigDecimal) value).toPlainString();
  }
  return String.valueOf(value);
}
origin: asakusafw/asakusafw

@Override
public String toString() {
  StringBuilder buf = new StringBuilder();
  buf.append('{');
  if (properties.isEmpty() == false) {
    for (Map.Entry<PropertyName, ?> entry : properties.entrySet()) {
      buf.append(entry.getKey());
      buf.append('=');
      buf.append(toStringRepresentation(entry.getValue()));
      buf.append(',');
      buf.append(' ');
    }
    buf.delete(buf.length() - 2, buf.length());
  }
  buf.append('}');
  return buf.toString();
}
origin: asakusafw/asakusafw

@Override
public Map<PropertyName, Object> getKey(DataModelReflection target) {
  Map<PropertyName, Object> results = new LinkedHashMap<>();
  for (PropertyName name : keys) {
    results.put(name, target.getValue(name));
  }
  return results;
}
origin: asakusafw/asakusafw-examples

private Difference createDifference(long actual) {
  PropertyName name = PropertyName.newInstance("count");
  return new Difference(
      new DataModelReflection(Collections.singletonMap(name, expected)),
      new DataModelReflection(Collections.singletonMap(name, actual)),
      "count verification was failed");
}
origin: asakusafw/asakusafw

  @Override
  public T toObject(DataModelReflection reflection) {
    try {
      T instance = modelClass.newInstance();
      for (Map.Entry<PropertyName, Field> entry : fields.entrySet()) {
        PropertyName name = entry.getKey();
        Field field = entry.getValue();
        Object value = reflection.getValue(name);
        try {
          field.set(instance, value);
        } catch (IllegalAccessException e) {
          throw new AssertionError(e);
        }
      }
      return instance;
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }
}
origin: asakusafw/asakusafw-examples

private Difference createDifference(long actual) {
  PropertyName name = PropertyName.newInstance("count");
  return new Difference(
      new DataModelReflection(Collections.singletonMap(name, expected)),
      new DataModelReflection(Collections.singletonMap(name, actual)),
      "count verification was failed");
}
origin: asakusafw/asakusafw

@Override
public T toObject(DataModelReflection reflection) {
  try {
    T instance = modelClass.newInstance();
    for (Map.Entry<PropertyName, Method> entry : accessors.entrySet()) {
      PropertyName property = entry.getKey();
      Method accessor = entry.getValue();
      Object value = reflection.getValue(property);
      set(instance, accessor, value);
    }
    return instance;
  } catch (Exception e) {
    throw new AssertionError(e);
  }
}
origin: asakusafw/asakusafw-examples

private Difference createDifference(long actual) {
  PropertyName name = PropertyName.newInstance("count");
  return new Difference(
      new DataModelReflection(Collections.singletonMap(name, expected)),
      new DataModelReflection(Collections.singletonMap(name, actual)),
      "count verification was failed");
}
origin: asakusafw/asakusafw

@SuppressWarnings("unchecked")
private static <T> Comparator<DataModelReflection> toComparator(DataModelDefinition<T> definition, String term) {
  if (term.isEmpty()) {
    throw new IllegalArgumentException("order term must not be empty"); //$NON-NLS-1$
  }
  Ordering order = parseOrder(term);
  checkProperty(definition, order.propertyName);
  Comparator<DataModelReflection> comparator = (a, b) -> {
    Comparable<Object> aValue = (Comparable<Object>) a.getValue(order.propertyName);
    Comparable<Object> bValue = (Comparable<Object>) b.getValue(order.propertyName);
    if (aValue == null) {
      if (bValue == null) {
        return 0;
      } else {
        return -1;
      }
    } else if (bValue == null) {
      return +1;
    }
    return aValue.compareTo(bValue);
  };
  if (order.direction == Direction.ASCENDANT) {
    return comparator;
  } else {
    return comparator.reversed();
  }
}
origin: asakusafw/asakusafw-examples

private Difference createDifference(long actual) {
  PropertyName name = PropertyName.newInstance("count");
  return new Difference(
      new DataModelReflection(Collections.singletonMap(name, expected)),
      new DataModelReflection(Collections.singletonMap(name, actual)),
      "count verification was failed");
}
origin: asakusafw/asakusafw

private Map<List<Object>, List<DataModelReflection>> asRefMap() {
  Map<List<Object>, List<DataModelReflection>> results = new LinkedHashMap<>();
  try (DataModelSource source = factory.createSource(definition, context)) {
    while (true) {
      DataModelReflection ref = source.next();
      if (ref == null) {
        break;
      }
      List<Object> key = new ArrayList<>(grouping.size());
      for (PropertyName name : grouping) {
        Object value = ref.getValue(name);
        key.add(value);
      }
      results.computeIfAbsent(key, k -> new ArrayList<>()).add(ref);
    }
  } catch (IOException e) {
    throw new IllegalStateException(e);
  }
  if (refComparator != null) {
    for (List<DataModelReflection> refs : results.values()) {
      refs.sort(refComparator);
    }
  }
  return results;
}
origin: asakusafw/asakusafw

private Object describeProperty(DataModelReflection object, PropertyName property) {
  assert property != null;
  if (object == null) {
    return null;
  }
  Object value = object.getValue(property);
  if (value == null) {
    return null;
  }
  PropertyType type = definition.getType(property);
  switch (type) {
  case DATE:
    return dateFormat.format(((Calendar) value).getTime());
  case TIME:
    return timeFormat.format(((Calendar) value).getTime());
  case DATETIME:
    return datetimeFormat.format(((Calendar) value).getTime());
  case DECIMAL:
    return String.format(
        "%s(scale=%d)", //$NON-NLS-1$
        ((BigDecimal) value).toPlainString(),
        ((BigDecimal) value).scale());
  case STRING:
    return toStringLiteral((String) value);
  default:
    return value;
  }
}
origin: asakusafw/asakusafw

  private Object checkProperties(DataModelReflection expected, DataModelReflection actual) {
    List<String> differences = new ArrayList<>(1);
    for (PropertyCondition<?> condition : propertyConditions) {
      Object e = expected.getValue(condition.getPropertyName());
      Object a = actual.getValue(condition.getPropertyName());
      if (condition.accepts(e, a) == false) {
        differences.add(MessageFormat.format(
            Messages.getString("VerifyRuleInterpretor.messageWrongProperty"), //$NON-NLS-1$
            condition.getPropertyName(),
            Util.format(a),
            condition.describeExpected(e, a)));
      }
    }
    return differences.isEmpty() ? null : differences;
  }
}
origin: asakusafw/asakusafw

Object p1 = r1.getValue(name);
Object p2 = r2.getValue(name);
if (p1 == null && p2 != null) {
  return -1;
com.asakusafw.testdriver.coreDataModelReflection

Javadoc

A data-model representation in record form.

Most used methods

  • <init>
    Creates a new instance.
  • getValue
    Returns the property value. This can returns one of the following type: * wrapper types of any
  • normalize
  • toStringLiteral
  • toStringRepresentation
    Returns formatted string representation of values.

Popular in Java

  • Creating JSON documents from java classes using gson
  • compareTo (BigDecimal)
  • findViewById (Activity)
  • getSharedPreferences (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • JFrame (javax.swing)
  • Table (org.hibernate.mapping)
    A relational table
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now