dev.rico.internal.core.Assert.requireNonNull()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中dev.rico.internal.core.Assert.requireNonNull()方法的一些代码示例,展示了Assert.requireNonNull()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.requireNonNull()方法的具体详情如下:
包路径:dev.rico.internal.core.Assert
类名称:Assert
方法名:requireNonNull

Assert.requireNonNull介绍

[英]Checks that the specified value is null and throws java.lang.NullPointerException with a customized error message if it is.
[中]检查指定的值是否为null并抛出java。lang.NullPointerException,如果是,则显示自定义错误消息。

代码示例

代码示例来源:origin: dev.rico/rico-core

public static <T> T[] requireNonNullEntries(final T[] array, final String argumentName) {
  requireNonNull(array, "array");
  requireNonNullEntries(Arrays.asList(array), argumentName);
  return array;
}

代码示例来源:origin: dev.rico/rico-server

public <T> T getInstance(final Class<T> cls) {
    Assert.requireNonNull(cls, "cls");
    return (T) instances.get(cls);
  }
}

代码示例来源:origin: dev.rico/rico-remoting-server

public RemotingContextTaskQueue(final String clientSessionId, final ClientSessionProvider sessionProvider, final CommunicationManager communicationManager, final long maxExecutionTime, final TimeUnit maxExecutionTimeUnit) {
  this.clientSessionId = Assert.requireNonBlank(clientSessionId, "clientSessionId");
  this.tasks = new LinkedBlockingQueue<>();
  this.communicationManager = Assert.requireNonNull(communicationManager, "communicationManager");
  this.sessionProvider = Assert.requireNonNull(sessionProvider, "sessionProvider");
  this.maxExecutionTime = maxExecutionTime;
  this.maxExecutionTimeUnit = Assert.requireNonNull(maxExecutionTimeUnit, "maxExecutionTimeUnit");
}

代码示例来源:origin: dev.rico/rico-remoting-common

@Override
public JsonObject encode(final EmptyCommand command) {
  Assert.requireNonNull(command, "command");
  final JsonObject jsonCommand = new JsonObject();
  jsonCommand.addProperty(ID, EMPTY_COMMAND_ID);
  return jsonCommand;
}

代码示例来源:origin: dev.rico/rico-core

public void setUncaughtExceptionHandler(final Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
    Assert.requireNonNull(uncaughtExceptionHandler, "uncaughtExceptionHandler");
    uncaughtExceptionHandlerLock.lock();
    try {
      this.uncaughtExceptionHandler = uncaughtExceptionHandler;
    } finally {
      uncaughtExceptionHandlerLock.unlock();
    }
  }
}

代码示例来源:origin: dev.rico/rico-core

public static InputStream getContentStream(final HttpURLConnection connection) throws IOException {
  Assert.requireNonNull(connection, "connection");
  final InputStream errorstream = connection.getErrorStream();
  if (errorstream == null) {
    return connection.getInputStream();
  } else {
    return errorstream;
  }
}

代码示例来源:origin: dev.rico/rico-server

public <T> void provideInstance(final Class<T> cls, final T instance) {
  Assert.requireNonNull(cls, "cls");
  Assert.requireNonNull(instance, "instance");
  if(getInstance(cls) != null) {
    throw new IllegalStateException("Instance for class " + cls + " already provided");
  }
  instances.put(cls, instance);
}

代码示例来源:origin: dev.rico/rico-core

private static synchronized Properties getBuildProperties(final ClassLoader classLoader) throws IOException {
  Assert.requireNonNull(classLoader, "classLoader");
  try (final InputStream inputStream = classLoader.getResourceAsStream(DEFAULT_LOCATION)) {
    if (inputStream != null) {
      Properties properties = new Properties();
      properties.load(inputStream);
      return properties;
    }
  }
  throw new RuntimeException("Can not load properties!");
}

代码示例来源:origin: dev.rico/rico-remoting-common

@Override
public JsonObject encode(final DeletePresentationModelCommand command) {
  Assert.requireNonNull(command, "command");
  final JsonObject jsonCommand = new JsonObject();
  jsonCommand.addProperty(ID, DELETE_PRESENTATION_MODEL_COMMAND_ID);
  jsonCommand.addProperty(PM_ID, command.getPmId());
  return jsonCommand;
}

代码示例来源:origin: dev.rico/rico-remoting-common

public static <T> T assertIsRemotingBean(T bean) {
  Assert.requireNonNull(bean, "bean");
  assertIsRemotingBean(bean.getClass());
  return bean;
}

代码示例来源:origin: dev.rico/rico-remoting-server

public ServerPresentationModelBuilder(ServerModelStore serverModelStore) {
  Assert.requireNonNull(serverModelStore, "modelStore");
  this.serverModelStore = serverModelStore;
  this.slots.add(new Slot(LegacyConstants.SOURCE_SYSTEM, LegacyConstants.SOURCE_SYSTEM_SERVER));
}

代码示例来源:origin: dev.rico/rico-remoting-server

@Override
public CompletableFuture<Void> runLaterInClientSession(final Runnable task) {
  Assert.requireNonNull(task, "task");
  return callLaterInClientSession(new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      task.run();
      return null;
    }
  });
}

代码示例来源:origin: dev.rico/rico-core

public static ParameterizedType toParameterizedType(final Type type) {
  Assert.requireNonNull(type, "type");
  if (isParameterizedType(type)) {
    return (ParameterizedType) type;
  } else {
    throw new IllegalArgumentException("The given type is not a ParameterizedType. Type: " + type);
  }
}

代码示例来源:origin: dev.rico/rico-core

public URL create(final Map<String, String> variables) {
  Assert.requireNonNull(variables, "variables");
  final String url = variables.keySet()
      .stream()
      .reduce(urlRepresentation, (base, key) -> replace(base, key, variables.get(key)));
  try {
    return new URL(url);
  } catch (final MalformedURLException e) {
    throw new RuntimeException("Can not create url for '" + url + "'");
  }
}

代码示例来源:origin: dev.rico/rico-remoting-common

private boolean isAnyConversionTypeAlreadyAdded(final ConverterFactory converterFactory) {
  Assert.requireNonNull(converterFactory, "converterFactory");
  for(ConverterFactory factory : converterFactories){
    return factory.getSupportedTypes().stream().filter(type -> converterFactory.getSupportedTypes().contains(type)).findAny().map(c -> true).orElse(false);
  }
  return false;
}

代码示例来源:origin: dev.rico/rico-remoting-server

private void checkPreDestroyContainsParameter(final Class<?> clazz)  throws ControllerValidationException {
  Assert.requireNonNull(clazz, "clazz");
  final ControllerValidationException controllerValidationException = ReflectionHelper.getInheritedDeclaredMethods(clazz).stream().
      filter(method -> method.isAnnotationPresent(PreDestroy.class)).
      filter(method -> method.getParameterTypes().length > 0).
      findAny().map(method ->new ControllerValidationException("PreDestroy method " + method.getName() + " should not contain parameter in Controller " + ControllerUtils.getControllerName(clazz))).
      orElse(null);
  if(controllerValidationException != null){
    throw controllerValidationException;
  }
}

代码示例来源:origin: dev.rico/rico-remoting-server

private void checkActionVoid(final Class<?> clazz) throws ControllerValidationException {
  Assert.requireNonNull(clazz, "clazz");
  final ControllerValidationException controllerValidationException = ReflectionHelper.getInheritedDeclaredMethods(clazz).stream().
      filter(method -> method.isAnnotationPresent(RemotingAction.class)).
      filter(method -> !method.getReturnType().equals(Void.TYPE)).
      findAny().
      map(method -> new ControllerValidationException("Return type of controller action " + ControllerUtils.getActionMethodName(method) + " in controller type " + ControllerUtils.getControllerName(clazz) + " must be of type void.")).
      orElse(null);
  if(controllerValidationException != null){
    throw controllerValidationException;
  }
}

代码示例来源:origin: dev.rico/rico-core

public void writeRequestContent(final String content) throws IOException {
  Assert.requireNonNull(content, "content");
  addRequestHeader(CHARSET_HEADER, CHARSET);
  writeRequestContent(content.getBytes(CHARSET));
}

代码示例来源:origin: dev.rico/rico-remoting-server

@Override
  protected void doPost(final HttpServletRequest req, final HttpServletResponse response) throws ServletException, IOException {
    Assert.requireNonNull(response, "response");
    final ServerRemotingContext currentContext = contextProvider.getCurrentContext();
    if(currentContext == null) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing or wrong client session id");
    } else {
      currentContext.interrupt();
    }
  }
}

代码示例来源:origin: dev.rico/rico-server

@Override
  public void initialize(final ServerCoreComponents coreComponents) throws ModuleInitializationException {
    Assert.requireNonNull(coreComponents, "coreComponents");
    final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
    final Configuration configuration = coreComponents.getConfiguration();

    HttpSessionTimeoutListener sessionCleaner = new HttpSessionTimeoutListener(configuration);
    servletContext.addListener(sessionCleaner);
  }
}

相关文章