Java 类org.joda.time.base.BasePeriod 实例源码

项目:jfixture    文件:BasePeriodRelay.java   
@Override
public Object create(Object request, SpecimenContext context) {

    if (!(request instanceof SpecimenType)) {
        return new NoSpecimen();
    }

    SpecimenType<?> type = (SpecimenType) request;
    if (!BasePeriod.class.isAssignableFrom(type.getRawType())) {
        return new NoSpecimen();
    }

    Duration duration = (Duration) context.resolve(Duration.class);
    Period period = duration.toPeriod();

    try {
        return type.getRawType().getDeclaredConstructor(Object.class).newInstance(period);
    } catch (Exception e) {
        e.printStackTrace();
        return new NoSpecimen();
    }
}