当前位置: 首页>>代码示例>>Java>>正文


Java ReadableInstant类代码示例

本文整理汇总了Java中org.joda.time.ReadableInstant的典型用法代码示例。如果您正苦于以下问题:Java ReadableInstant类的具体用法?Java ReadableInstant怎么用?Java ReadableInstant使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReadableInstant类属于org.joda.time包,在下文中一共展示了ReadableInstant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toDoubleValue

import org.joda.time.ReadableInstant; //导入依赖的package包/类
private static double toDoubleValue(Object o) {
    if (o instanceof Number) {
        return ((Number) o).doubleValue();
    } else if (o instanceof ReadableInstant) {
        // Dates are exposed in scripts as ReadableDateTimes but aggregations want them to be numeric
        return ((ReadableInstant) o).getMillis();
    } else if (o instanceof Boolean) {
        // We do expose boolean fields as boolean in scripts, however aggregations still expect
        // that scripts return the same internal representation as regular fields, so boolean
        // values in scripts need to be converted to a number, and the value formatter will
        // make sure of using true/false in the key_as_string field
        return ((Boolean) o).booleanValue() ? 1.0 : 0.0;
    } else {
        throw new AggregationExecutionException("Unsupported script value [" + o + "], expected a number, date, or boolean");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ScriptDoubleValues.java

示例2: toLongValue

import org.joda.time.ReadableInstant; //导入依赖的package包/类
private static long toLongValue(Object o) {
    if (o instanceof Number) {
        return ((Number) o).longValue();
    } else if (o instanceof ReadableInstant) {
        // Dates are exposed in scripts as ReadableDateTimes but aggregations want them to be numeric
        return ((ReadableInstant) o).getMillis();
    } else if (o instanceof Boolean) {
        // We do expose boolean fields as boolean in scripts, however aggregations still expect
        // that scripts return the same internal representation as regular fields, so boolean
        // values in scripts need to be converted to a number, and the value formatter will
        // make sure of using true/false in the key_as_string field
        return ((Boolean) o).booleanValue() ? 1L : 0L;
    } else {
        throw new AggregationExecutionException("Unsupported script value [" + o + "], expected a number, date, or boolean");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ScriptLongValues.java

示例3: createBasicMappings

import org.joda.time.ReadableInstant; //导入依赖的package包/类
protected static Map<Class<?>, IndexType> createBasicMappings() {
    Map<Class<?>, IndexType> map = new LinkedHashMap<>();
    map.put(Short.class, IndexType.SmallDecimal);
    map.put(Integer.class, IndexType.SmallDecimal);
    map.put(short.class, IndexType.SmallDecimal);
    map.put(int.class, IndexType.SmallDecimal);
    map.put(AtomicInteger.class, IndexType.SmallDecimal);
    map.put(AtomicBoolean.class, IndexType.Identifier);
    map.put(boolean.class, IndexType.Identifier);
    map.put(Boolean.class, IndexType.Identifier);
    map.put(Enum.class, IndexType.Identifier);
    map.put(UUID.class, IndexType.Identifier);
    map.put(Number.class, IndexType.BigDecimal);
    map.put(long.class, IndexType.BigDecimal);
    map.put(float.class, IndexType.BigDecimal);
    map.put(double.class, IndexType.BigDecimal);
    map.put(CharSequence.class, IndexType.Text);
    map.put(ReadableInstant.class, IndexType.Date);
    map.put(Date.class, IndexType.Date);
    map.put(GeoPoint.class, IndexType.GeoPoint);
    return map;
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:23,代码来源:IndexTypeLookup.java

示例4: shouldTakeTypeInheritenceIntoAccountWhenGettingBestTransformerWhenConsideringDestination

import org.joda.time.ReadableInstant; //导入依赖的package包/类
@Test
public void shouldTakeTypeInheritenceIntoAccountWhenGettingBestTransformerWhenConsideringDestination() {
    ObjectToDateTime transformer = new ObjectToDateTime();
    transformerManager.register(Object.class, DateTime.class, transformer);

    assertThat(transformerManager.getTransformer(String.class, ReadableInstant.class), is(nullValue()));
    assertThat(transformerManager.getTransformer(Long.class, ReadableInstant.class), is(nullValue()));

    ETransformer<? super String, ? extends ReadableInstant> stringToDateTime = transformerManager.getBestTransformer(String.class, ReadableInstant.class);
    assertThat(stringToDateTime, is(notNullValue()));
    assertThat(stringToDateTime.from("2014-06-05T00:00:00.000Z").compareTo(new DateTime(2014, 6, 5, 0, 0, 0).withZoneRetainFields(DateTimeZone.UTC)), is(0));

    ETransformer<? super Long, ? extends ReadableInstant> longToDateTime = transformerManager.getBestTransformer(Long.class, ReadableInstant.class);
    assertThat(longToDateTime, is(notNullValue()));
    assertThat(longToDateTime.from(123456L).compareTo(new DateTime(123456)), is(0));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:17,代码来源:TransformerManagerTest.java

示例5: shouldCacheBestTransformerForFasterLaterLookups

import org.joda.time.ReadableInstant; //导入依赖的package包/类
@Test
public void shouldCacheBestTransformerForFasterLaterLookups() {
    ObjectToDateTime registered = new ObjectToDateTime();
    transformerManager.register(Object.class, DateTime.class, registered);

    ETransformer<? super String, ? extends ReadableInstant> found = transformerManager.getBestTransformer(String.class, ReadableInstant.class);

    ETransformer<? super String, ? extends ReadableInstant> cached = transformerManager.getFromCache(String.class, ReadableInstant.class);
    assertThat(cached, is(notNullValue()));
    assertThat(cached, is(sameInstance((Object) registered)));
    assertThat(cached, is(sameInstance((Object) found)));

    // inject another instance into the cache
    ObjectToDateTime newInstance = new ObjectToDateTime();
    transformerManager.addToCache(String.class, ReadableInstant.class, newInstance);

    ETransformer<? super String, ? extends ReadableInstant> found2 = transformerManager.getBestTransformer(String.class, ReadableInstant.class);
    assertThat(found2, sameInstance((Object) newInstance));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:20,代码来源:TransformerManagerTest.java

示例6: shouldClearConvertorCacheWhenNewTransformersRegistered

import org.joda.time.ReadableInstant; //导入依赖的package包/类
@Test
public void shouldClearConvertorCacheWhenNewTransformersRegistered() {
    ObjectToDateTime registered = new ObjectToDateTime();
    transformerManager.register(Object.class, DateTime.class, registered);

    ETransformer<? super String, ? extends ReadableInstant> found = transformerManager.getBestTransformer(String.class, ReadableInstant.class);
    ETransformer<? super String, ? extends ReadableInstant> cached = transformerManager.getFromCache(String.class, ReadableInstant.class);
    assertThat(found, is((Object) registered));
    assertThat(cached, is((Object) registered));

    StringToDateTime registered2 = new StringToDateTime();
    transformerManager.register(String.class, DateTime.class, registered2);

    ETransformer<? super String, ? extends ReadableInstant> found2 = transformerManager.getBestTransformer(String.class, ReadableInstant.class);
    ETransformer<? super String, ? extends ReadableInstant> cached2 = transformerManager.getFromCache(String.class, ReadableInstant.class);
    assertThat(found2, is((Object) registered2));
    assertThat(cached2, is((Object) registered2));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:19,代码来源:TransformerManagerTest.java

示例7: shouldUnregisterPreviouslyRegisteredTransformerAndClearCache

import org.joda.time.ReadableInstant; //导入依赖的package包/类
@Test
public void shouldUnregisterPreviouslyRegisteredTransformerAndClearCache() {
    ObjectToDateTime registered = new ObjectToDateTime();
    transformerManager.register(Object.class, DateTime.class, registered);

    ETransformer<? super String, ? extends ReadableInstant> found = transformerManager.getBestTransformer(String.class, ReadableInstant.class);
    ETransformer<? super String, ? extends ReadableInstant> cached = transformerManager.getFromCache(String.class, ReadableInstant.class);
    assertThat(found, is((Object) registered));
    assertThat(cached, is((Object) registered));

    transformerManager.unregister(Object.class, DateTime.class);

    ETransformer<? super String, ? extends ReadableInstant> found2 = transformerManager.getBestTransformer(String.class, ReadableInstant.class);
    ETransformer<? super String, ? extends ReadableInstant> cached2 = transformerManager.getFromCache(String.class, ReadableInstant.class);
    assertThat(found2, is(nullValue()));
    assertThat(cached2, is(nullValue()));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:18,代码来源:TransformerManagerTest.java

示例8: getInterval

import org.joda.time.ReadableInstant; //导入依赖的package包/类
private static ReadableInstant[] getInterval(int beforeOrAfter, ReadableInstant now, LastRun lastRun, int timeType) {
    ReadableInstant[] res = new ReadableInstant[2];

    switch (beforeOrAfter) {
        case TIME_BEFORE_NOW: // Before now, starting from lastRun, depending on timeType
            res[0] = timeType == DbTimeView.SCHEDULED_TIME ? lastRun.scheduled : lastRun.deadline;
            if (res[0] == null) {
                res[0] = now;
            }
            res[1] = now;
            break;

        case TIME_FROM_NOW:
            res[0] = now;
            res[1] = null;
            break;

        default:
            throw new IllegalArgumentException("Before or after now?");
    }

    return res;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:24,代码来源:ReminderService.java

示例9: getAsStringValue

import org.joda.time.ReadableInstant; //导入依赖的package包/类
private String getAsStringValue(FacesContext facesContext, UIComponent uiComponent, Object value) {
	if (facesContext == null) {
		throw new NullPointerException("facesContext");
	}
	if (uiComponent == null) {
		throw new NullPointerException("uiComponent");
	}

	if (value == null) {
		return "";
	}
	if (value instanceof String) {
		return (String) value;
	}

	DateTimeFormatter format = getDateFormat(uiComponent);

	try {
		return format.print((ReadableInstant) value);
	}
	catch (Exception e) {
		throw new ConverterException("Cannot convert value '" + value + "'");
	}
}
 
开发者ID:TheCoder4eu,项目名称:BootsFaces-Tests,代码行数:25,代码来源:DateTimeConverter.java

示例10: garbageCollectionTimeAfterEndOfGlobalWindowWithLateness

import org.joda.time.ReadableInstant; //导入依赖的package包/类
@Test
public void garbageCollectionTimeAfterEndOfGlobalWindowWithLateness() {
  FixedWindows windowFn = FixedWindows.of(Duration.standardMinutes(5));
  Duration allowedLateness = Duration.millis(Long.MAX_VALUE);
  WindowingStrategy<?, ?> strategy =
      WindowingStrategy.globalDefault()
          .withWindowFn(windowFn)
          .withAllowedLateness(allowedLateness);

  IntervalWindow window = windowFn.assignWindow(new Instant(-100));
  assertThat(
      window.maxTimestamp().plus(allowedLateness),
      Matchers.<ReadableInstant>greaterThan(GlobalWindow.INSTANCE.maxTimestamp()));
  assertThat(
      LateDataUtils.garbageCollectionTime(window, strategy),
      equalTo(GlobalWindow.INSTANCE.maxTimestamp()));
}
 
开发者ID:apache,项目名称:beam,代码行数:18,代码来源:LateDataUtilsTest.java

示例11: getFirstWarningTime

import org.joda.time.ReadableInstant; //导入依赖的package包/类
public static DateTime getFirstWarningTime(
        int timeType,
        OrgDateTime orgDateTime,
        ReadableInstant fromTime,
        ReadableInstant beforeTime,
        OrgInterval defaultTimeOfDay,
        OrgInterval defaultWarningPeriod) {

    List<DateTime> times = OrgDateTimeUtils.getTimesInInterval(
            orgDateTime, fromTime, beforeTime, false, 1);

    for (DateTime time : times) {
        if (!orgDateTime.hasTime()) {
            time = time.plusHours(9); // TODO: Move to preferences
        }

        return time;
    }

    return null;
}
 
开发者ID:orgzly,项目名称:org-java,代码行数:22,代码来源:OrgDateTimeUtils.java

示例12: compareTo

import org.joda.time.ReadableInstant; //导入依赖的package包/类
/**
 * Compares this object with the specified object for ascending
 * millisecond instant order. This ordering is inconsistent with
 * equals, as it ignores the Chronology.
 * <p>
 * All ReadableInstant instances are accepted.
 *
 * @param other  a readable instant to check against
 * @return negative value if this is less, 0 if equal, or positive value if greater
 * @throws NullPointerException if the object is null
 * @throws ClassCastException if the object type is not supported
 */
public int compareTo(ReadableInstant other) {
    if (this == other) {
        return 0;
    }
    
    long otherMillis = other.getMillis();
    long thisMillis = getMillis();
    
    // cannot do (thisMillis - otherMillis) as can overflow
    if (thisMillis == otherMillis) {
        return 0;
    }
    if (thisMillis < otherMillis) {
        return -1;
    } else {
        return 1;
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:31,代码来源:AbstractInstant.java

示例13: afterStep

import org.joda.time.ReadableInstant; //导入依赖的package包/类
public ExitStatus afterStep(StepExecution stepExecution) {
	logger.debug("After Step " + currentStep.getStepName());

	try {
		Url u = new Url();
		u.setLastmod(ISODateTimeFormat.dateTime().print((ReadableInstant) null));
		u.setLoc(new URL(portalBaseUrl +"/" + sitemapDir + "/" + currentFile.getFilename()));
		sitemapNames.add(u);
	} catch (MalformedURLException e) {
		logger.error("Unable create Url for sitemap", e);
	}

	//reset counts to nulls to support beforeStep()
	currentStep = null;
	currentFile = null;
	chunkOfFile = 0;
	commitSize = 0;

	return stepExecution.getExitStatus();
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:21,代码来源:SitemapFilesListener.java

示例14: beforeChunk

import org.joda.time.ReadableInstant; //导入依赖的package包/类
public void beforeChunk() {
	//Check sizes (MB & count) & if over limit
	if (FileUtils.sizeOf(currentFile.getFile()) >= MAX_SITEMAP_LENGTH || (chunkOfFile * commitSize) >= MAX_URL_COUNT){
		logger.debug("Creating a new file");
		try {
			Url u = new Url();
			u.setLastmod(ISODateTimeFormat.dateTime().print((ReadableInstant) null));
			u.setLoc(new URL(portalBaseUrl + "/sitemap/" + currentFile.getFilename()));
			sitemapNames.add(u);
		} catch (MalformedURLException e) {
			logger.error("Unable create Url for sitemap", e);
		}
		//close & open writer with new name
		staxWriter.close();
		currentFile = new FileSystemResource(sitemapSpoolDir + "/"+ currentStep.getStepName()  + ++fileCount + ".xml");
		logger.debug("Open:" + currentFile.isOpen());
		logger.debug("Writable:" + currentFile.isWritable());
		staxWriter.setResource((Resource) currentFile);
		staxWriter.open(currentStep.getExecutionContext());

		chunkOfFile = 0;
	}
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:24,代码来源:SitemapFilesListener.java

示例15: testBigHashtable

import org.joda.time.ReadableInstant; //导入依赖的package包/类
public void testBigHashtable() {
    Converter[] array = new Converter[] {
        c1, c2, c3, c4,
    };
    ConverterSet set = new ConverterSet(array);
    set.select(Boolean.class);
    set.select(Character.class);
    set.select(Byte.class);
    set.select(Short.class);
    set.select(Integer.class);
    set.select(Long.class);
    set.select(Float.class);
    set.select(Double.class);
    set.select(null);
    set.select(Calendar.class);
    set.select(GregorianCalendar.class);
    set.select(DateTime.class);
    set.select(DateMidnight.class);
    set.select(ReadableInstant.class);
    set.select(ReadableDateTime.class);
    set.select(ReadWritableInstant.class);  // 16
    set.select(ReadWritableDateTime.class);
    set.select(DateTime.class);
    assertEquals(4, set.size());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:TestConverterSet.java


注:本文中的org.joda.time.ReadableInstant类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。