package com.outbrain.ob1k.server.spring;

import org.springframework.context.support.AbstractApplicationContext;

import java.util.Map;

/**
 * User: aronen
 * Date: 6/25/13
 * Time: 6:50 PM
 */
public class SpringBeanContext {
  private final Map<String, AbstractApplicationContext> contexts;

  public SpringBeanContext(final Map<String, AbstractApplicationContext> contexts) {
    this.contexts = contexts;
  }

  public <T> T getBean(final String ctxName, final Class<T> type) {
    final AbstractApplicationContext context = contexts.get(ctxName);
    if (context == null) {
      throw new NullPointerException("Context not found for name '" + ctxName + "'");
    }
    return context.getBean(type);
  }

  public <T> T getBean(final String ctxName, final String id, final Class<T> type) {
    final AbstractApplicationContext context = contexts.get(ctxName);
    if (context == null) {
      throw new NullPointerException("Context not found for name '" + ctxName + "'");
    }
    return context.getBean(id, type);
  }

  public boolean contextExists(final String ctxName) {
    return contexts.containsKey(ctxName);
  }
}

@@ -128,16 +128,42 @@
 til.Map;
+%0Aimport java.util.Objects;
 %0A%0A/**%0A *
@@ -580,68 +580,40 @@
     
-if (context == null) %7B%0A      throw new NullPointerException(
+Objects.requireNonNull(context, 
 %22Con
@@ -649,38 +649,32 @@
 ctxName + %22'%22);%0A
-    %7D%0A
     return conte
@@ -859,68 +859,40 @@
     
-if (context == null) %7B%0A      throw new NullPointerException(
+Objects.requireNonNull(context, 
 %22Con
@@ -940,14 +940,8 @@
 %22);%0A
-    %7D%0A
     

use java.util.Objects