use of java.time.ZoneOffset.UTC in project molgenis by molgenis.
the class PostgreSqlUtils method getPostgreSqlValue.
/**
* Returns the PostgreSQL value for the given entity attribute
*
* @param entity entity
* @param attr attribute
* @return PostgreSQL value
*/
static Object getPostgreSqlValue(Entity entity, Attribute attr) {
String attrName = attr.getName();
AttributeType attrType = attr.getDataType();
switch(attrType) {
case BOOL:
return entity.getBoolean(attrName);
case CATEGORICAL:
case XREF:
Entity xrefEntity = entity.getEntity(attrName);
return xrefEntity != null ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute()) : null;
case CATEGORICAL_MREF:
case MREF:
case ONE_TO_MANY:
Iterable<Entity> entities = entity.getEntities(attrName);
return stream(entities.spliterator(), false).map(mrefEntity -> getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute())).collect(toList());
case DATE:
return entity.getLocalDate(attrName);
case DATE_TIME:
// As a workaround for #5674, we don't store milliseconds
Instant instant = entity.getInstant(attrName);
return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null;
case DECIMAL:
return entity.getDouble(attrName);
case EMAIL:
case ENUM:
case HTML:
case HYPERLINK:
case SCRIPT:
case STRING:
case TEXT:
return entity.getString(attrName);
case FILE:
FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class);
return fileEntity != null ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute()) : null;
case INT:
return entity.getInt(attrName);
case LONG:
return entity.getLong(attrName);
case COMPOUND:
throw new RuntimeException(format("Illegal attribute type [%s]", attrType.toString()));
default:
throw new UnexpectedEnumException(attrType);
}
}
use of java.time.ZoneOffset.UTC in project jpx by jenetics.
the class FiltersTest method splitByDay.
public void splitByDay() {
final Random random = new Random(1);
final ZonedDateTime time = ZonedDateTime.of(2017, 1, 1, 0, 0, 0, 0, UTC);
final AtomicInteger count = new AtomicInteger();
final List<WayPoint> points = Stream.generate(() -> nextWayPoint(random)).limit(100).map(wp -> wp.toBuilder().time(time.plusHours(count.incrementAndGet())).build()).collect(toList());
for (TrackSegment list : Filters.splitByDay(TrackSegment.of(points))) {
System.out.println("------------------------");
for (WayPoint point : list) {
System.out.println(point.getTime() + ": " + point);
}
}
}
Aggregations