Java Code Examples for java.util.concurrent.ConcurrentMap#getOrDefault()

The following examples show how to use java.util.concurrent.ConcurrentMap#getOrDefault() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Strata   File:    License: Apache License 2.0 6 votes vote down vote up
public Object build(Class<?> beanType, BeanBuilder<?> builder) {
  BufferingBeanBuilder<?> bld = (BufferingBeanBuilder<?>) builder;
  ConcurrentMap<MetaProperty<?>, Object> buffer = bld.getBuffer();
  BusinessDayAdjustment bda = (BusinessDayAdjustment) buffer.getOrDefault(PAYMENT_ADJUSTMENT_DATE, null);
  if (buffer.containsKey(BASE_CURRENCY_AMOUNT) &&
      buffer.containsKey(COUNTER_CURRENCY_AMOUNT) &&
      buffer.containsKey(PAYMENT_DATE)) {

    CurrencyAmount baseAmount = (CurrencyAmount) builder.get(BASE_CURRENCY_AMOUNT);
    CurrencyAmount counterAmount = (CurrencyAmount) builder.get(COUNTER_CURRENCY_AMOUNT);
    LocalDate paymentDate = (LocalDate) builder.get(PAYMENT_DATE);
    return bda != null ?
        FxSingle.of(baseAmount, counterAmount, paymentDate, bda) :
        FxSingle.of(baseAmount, counterAmount, paymentDate);

  } else {
    Payment basePayment = (Payment) buffer.get(BASE_CURRENCY_PAYMENT);
    Payment counterPayment = (Payment) buffer.get(COUNTER_CURRENCY_PAYMENT);
    return bda != null ? FxSingle.of(basePayment, counterPayment, bda) : FxSingle.of(basePayment, counterPayment);
Example 2
private static void assertSubscribersNumber(
    EventService service, Class<?> eventType, int expectNumberOfSubscribers) throws Exception {
  Field privateStringField = EventService.class.getDeclaredField("subscribersByEventType");


  ConcurrentMap<Class<?>, Set<EventSubscriber>> subscribersByEventType =
      (ConcurrentMap<Class<?>, Set<EventSubscriber>>) privateStringField.get(service);
  Set<EventSubscriber> subscribers =
      subscribersByEventType.getOrDefault(eventType, Collections.emptySet());
  assertEquals(subscribers.size(), expectNumberOfSubscribers);