org.checkerframework.checker.nullness.qual.NonNull Java Examples

The following examples show how to use org.checkerframework.checker.nullness.qual.NonNull. 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 File: VelocityCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (args.length != 0) {
    source.sendMessage(TextComponent.of("/velocity plugins", TextColor.RED));
    return;
  }

  List<PluginContainer> plugins = ImmutableList.copyOf(server.getPluginManager().getPlugins());
  int pluginCount = plugins.size();

  if (pluginCount == 0) {
    source.sendMessage(TextComponent.of("No plugins installed.", TextColor.YELLOW));
    return;
  }

  TextComponent.Builder output = TextComponent.builder("Plugins: ")
      .color(TextColor.YELLOW);
  for (int i = 0; i < pluginCount; i++) {
    PluginContainer plugin = plugins.get(i);
    output.append(componentForPlugin(plugin.getDescription()));
    if (i + 1 < pluginCount) {
      output.append(TextComponent.of(", "));
    }
  }

  source.sendMessage(output.build());
}
 
Example #2
Source File: Target.java    From promregator with Apache License 2.0 6 votes vote down vote up
/**
 * @return the list of preferred Route Regex Patterns
  * This will never return a null value
 */
public @NonNull List<Pattern> getPreferredRouteRegexPatterns() {
	if (this.cachedPreferredRouteRegexPattern != null) {
		return this.cachedPreferredRouteRegexPattern;
	}
	
	List<String> regexStringList = this.getPreferredRouteRegex();
	
	List<Pattern> patterns = new ArrayList<>(regexStringList.size());
	for (String routeRegex : regexStringList) {
		try {
			Pattern pattern = Pattern.compile(routeRegex);
			patterns.add(pattern);
		} catch (PatternSyntaxException e) {
			log.warn(String.format("Invalid preferredRouteRegex '%s' detected. Fix your configuration; until then, the regex will be ignored", routeRegex), e);
			// continue not necessary here
		}
	}
	
	this.cachedPreferredRouteRegexPattern = patterns;
	
	return this.cachedPreferredRouteRegexPattern;
}
 
Example #3
Source File: MainDesignerController.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initLanguageChoicebox() {
    languageChoicebox.getItems().addAll(getSupportedLanguages().sorted().collect(Collectors.toList()));
    languageChoicebox.setConverter(DesignerUtil.stringConverter(Language::getName, AuxLanguageRegistry::findLanguageByNameOrDefault));

    SingleSelectionModel<Language> langSelector = languageChoicebox.getSelectionModel();
    @NonNull Language restored = globalLanguage.getOrElse(defaultLanguage());

    globalLanguage.bind(langSelector.selectedItemProperty());

    langSelector.select(restored);

    Platform.runLater(() -> {
        langSelector.clearSelection();
        langSelector.select(restored); // trigger listener
    });
}
 
Example #4
Source File: SourceEditorController.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void handleTestOpenRequest(@NonNull LiveTestCase oldValue, @NonNull LiveTestCase newValue) {
    oldValue.commitChanges();

    if (!newValue.getSource().equals(nodeEditionCodeArea.getText())) {
        nodeEditionCodeArea.replaceText(newValue.getSource());
    }

    if (newValue.getLanguageVersion() == null) {
        newValue.setLanguageVersion(globalLanguageProperty().getValue().getDefaultVersion());
    }

    Subscription sub = Subscription.multi(
        ReactfxUtil.rewireInit(newValue.sourceProperty(), astManager.sourceCodeProperty()),
        ReactfxUtil.rewireInit(newValue.languageVersionProperty(), languageVersionUIProperty),
        () -> propertiesPopover.rebind(null)
    );

    newValue.addCommitHandler(t -> sub.unsubscribe());
}
 
Example #5
Source File: VelocityCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  try {
    if (server.reloadConfiguration()) {
      source.sendMessage(TextComponent.of("Configuration reloaded.", TextColor.GREEN));
    } else {
      source.sendMessage(TextComponent.of(
          "Unable to reload your configuration. Check the console for more details.",
          TextColor.RED));
    }
  } catch (Exception e) {
    logger.error("Unable to reload configuration", e);
    source.sendMessage(TextComponent.of(
        "Unable to reload your configuration. Check the console for more details.",
        TextColor.RED));
  }
}
 
Example #6
Source File: DesignerUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static BuilderFactory customBuilderFactory(@NonNull DesignerRoot owner) {
    return type -> {

        boolean needsRoot = Arrays.stream(type.getConstructors()).anyMatch(it -> ArrayUtils.contains(it.getParameterTypes(), DesignerRoot.class));

        if (needsRoot) {
            // Controls that need the DesignerRoot can declare a constructor
            // with a parameter w/ signature @NamedArg("designerRoot") DesignerRoot
            // to be injected with the relevant instance of the app.
            ProxyBuilder<Object> builder = new ProxyBuilder<>(type);
            builder.put("designerRoot", owner);
            return builder;
        } else {
            return null; //use default
        }
    };
}
 
Example #7
Source File: VelocityCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public List<String> suggest(CommandSource source, String @NonNull [] currentArgs) {
  if (currentArgs.length == 0) {
    return subcommands.entrySet().stream()
            .filter(e -> e.getValue().hasPermission(source, new String[0]))
            .map(Map.Entry::getKey)
            .collect(ImmutableList.toImmutableList());
  }

  if (currentArgs.length == 1) {
    return subcommands.entrySet().stream()
        .filter(e -> e.getKey().regionMatches(true, 0, currentArgs[0], 0,
            currentArgs[0].length()))
        .filter(e -> e.getValue().hasPermission(source, new String[0]))
        .map(Map.Entry::getKey)
        .collect(ImmutableList.toImmutableList());
  }

  Command command = subcommands.get(currentArgs[0].toLowerCase(Locale.US));
  if (command == null) {
    return ImmutableList.of();
  }
  @SuppressWarnings("nullness")
  String[] actualArgs = Arrays.copyOfRange(currentArgs, 1, currentArgs.length);
  return command.suggest(source, actualArgs);
}
 
Example #8
Source File: VelocityCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (args.length == 0) {
    usage(source);
    return;
  }

  Command command = subcommands.get(args[0].toLowerCase(Locale.US));
  if (command == null) {
    usage(source);
    return;
  }
  @SuppressWarnings("nullness")
  String[] actualArgs = Arrays.copyOfRange(args, 1, args.length);
  command.execute(source, actualArgs);
}
 
Example #9
Source File: GlistCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public List<String> suggest(CommandSource source, String @NonNull [] currentArgs) {
  ImmutableList.Builder<String> options = ImmutableList.builder();
  for (RegisteredServer server : server.getAllServers()) {
    options.add(server.getServerInfo().getName());
  }
  options.add("all");

  switch (currentArgs.length) {
    case 0:
      return options.build();
    case 1:
      return options.build().stream()
          .filter(o -> o.regionMatches(true, 0, currentArgs[0], 0, currentArgs[0].length()))
          .collect(ImmutableList.toImmutableList());
    default:
      return ImmutableList.of();
  }
}
 
Example #10
Source File: VelocityEventManager.java    From Velocity with MIT License 6 votes vote down vote up
/**
 * Initializes the Velocity event manager.
 *
 * @param pluginManager a reference to the Velocity plugin manager
 */
public VelocityEventManager(PluginManager pluginManager) {
  // Expose the event executors to the plugins - required in order for the generated ASM classes
  // to work.
  PluginClassLoader cl = new PluginClassLoader(new URL[0]);
  cl.addToClassloaders();

  // Initialize the event bus.
  this.bus = new SimpleEventBus<Object>(Object.class) {
    @Override
    protected boolean shouldPost(@NonNull Object event, @NonNull EventSubscriber<?> subscriber) {
      // Velocity doesn't use Cancellable or generic events, so we can skip those checks.
      return true;
    }
  };
  this.methodAdapter = new SimpleMethodSubscriptionAdapter<>(bus,
      new ASMEventExecutorFactory<>(cl),
      new VelocityMethodScanner());
  this.pluginManager = pluginManager;
  this.service = Executors
      .newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder()
          .setNameFormat("Velocity Event Executor - #%d").setDaemon(true).build());
}
 
Example #11
Source File: CacheTest.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    LoadingCache<String, Map<String, Object>> caches = Caffeine.newBuilder()
            .maximumSize(10)
            .refreshAfterWrite(10000, TimeUnit.MINUTES)
            .build(new CacheLoader<String, Map<String, Object>>() {
                       @Nullable
                       @Override
                       public Map<String, Object> load(@NonNull String s) throws Exception {

                           Map<String, Object> map = new HashMap<>();
                           map.put("aaa", "aaa");
                           return map;
                       }
                   }
            );


    Map<String, Object> aaa = caches.get("aaa");
    System.out.println(aaa);
    Map<String, Object> bbb = caches.get("aaa");
    System.out.println(bbb);
    Map<String, Object> bbb1 = caches.get("aaa1");
    System.out.println(bbb1);

}
 
Example #12
Source File: CacheTest.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    LoadingCache<String, Map<String, Object>> caches = Caffeine.newBuilder()
            .maximumSize(10)
            .refreshAfterWrite(10000, TimeUnit.MINUTES)
            .build(new CacheLoader<String, Map<String, Object>>() {
                       @Nullable
                       @Override
                       public Map<String, Object> load(@NonNull String s) throws Exception {

                           Map<String, Object> map = new HashMap<>();
                           map.put("aaa", "aaa");
                           return map;
                       }
                   }
            );


    Map<String, Object> aaa = caches.get("aaa");
    System.out.println(aaa);
    Map<String, Object> bbb = caches.get("aaa");
    System.out.println(bbb);
    Map<String, Object> bbb1 = caches.get("aaa1");
    System.out.println(bbb1);

}
 
Example #13
Source File: ClaimContextCalculator.java    From GriefDefender with MIT License 6 votes vote down vote up
@Override
public void calculate(@NonNull Player player, @NonNull ContextConsumer contextSet) {
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getPlayerData(player.getWorld(), player.getUniqueId());
    if (playerData == null) {
        return;
    }
    if (playerData.ignoreActiveContexts) {
        playerData.ignoreActiveContexts = false;
        return;
    }

    GDClaim sourceClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
    if (sourceClaim != null) {
        if (playerData == null || playerData.canIgnoreClaim(sourceClaim)) {
            return;
        }

        if (sourceClaim.parent != null && sourceClaim.getData().doesInheritParent()) {
            contextSet.accept(sourceClaim.parent.getContext().getKey(), sourceClaim.parent.getContext().getValue());
        } else {
            contextSet.accept(sourceClaim.getContext().getKey(), sourceClaim.getContext().getValue());
        }
        contextSet.accept("server", GriefDefenderPlugin.getInstance().getPermissionProvider().getServerName());
    }
}
 
Example #14
Source File: CFAccessorCacheCaffeine.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Override
public @NonNull CompletableFuture<ListSpacesResponse> asyncLoad(@NonNull String key,
		@NonNull Executor executor) {
	Mono<ListSpacesResponse> mono = parent.retrieveSpaceIdsInOrg(key)
			.subscribeOn(Schedulers.fromExecutor(executor))
			.cache();
	return mono.toFuture();
}
 
Example #15
Source File: CFAccessorCacheCaffeine.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Override
public @NonNull CompletableFuture<ListSpacesResponse> asyncLoad(@NonNull CacheKeySpace key,
		@NonNull Executor executor) {
	Mono<ListSpacesResponse> mono = parent.retrieveSpaceId(key.getOrgId(), key.getSpaceName())
			.subscribeOn(Schedulers.fromExecutor(executor))
			.cache();
	return mono.toFuture();
}
 
Example #16
Source File: CFAccessorCacheCaffeine.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Override
public @NonNull CompletableFuture<ListOrganizationsResponse> asyncLoad(@NonNull String key,
		@NonNull Executor executor) {
	
	Mono<ListOrganizationsResponse> mono = parent.retrieveAllOrgIds()
			.subscribeOn(Schedulers.fromExecutor(executor))
			.cache();
	return mono.toFuture();
}
 
Example #17
Source File: FakePluginManager.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public @NonNull Optional<PluginContainer> getPlugin(@NonNull String id) {
  switch (id) {
    case "a":
      return Optional.of(PC_A);
    case "b":
      return Optional.of(PC_B);
    default:
      return Optional.empty();
  }
}
 
Example #18
Source File: CaffeineAsyncLoadingTest.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Override
public @NonNull CompletableFuture<Integer> asyncLoad(@NonNull String key,
		@NonNull Executor executor) {

	log.info(String.format("Request loading iteration %d for request %s", this.executionNumber, key));
	Mono<Integer> result = null;
	
	synchronized(this) {
		result = Mono.just(executionNumber++);
	}
	
	result = result.subscribeOn(Schedulers.fromExecutor(executor));
	
	if (this.executionNumber > 1) {
		result = result.map( x-> {
			log.info(String.format("Starting to delay - iteration: %d", x));
			return x;
		}).delayElement(Duration.ofMillis(200))
		.map( x-> {
			log.info(String.format("Finished delaying - iteration: %d", x));
			return x;
		});
	}
	
	result = result.cache();
	
	return result.toFuture();
}
 
Example #19
Source File: VelocityCommand.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (args.length != 0) {
    source.sendMessage(TextComponent.of("/velocity version", TextColor.RED));
    return;
  }

  ProxyVersion version = server.getVersion();

  TextComponent velocity = TextComponent.builder(version.getName() + " ")
      .decoration(TextDecoration.BOLD, true)
      .color(TextColor.DARK_AQUA)
      .append(TextComponent.of(version.getVersion()).decoration(TextDecoration.BOLD, false))
      .build();
  TextComponent copyright = TextComponent
      .of("Copyright 2018-2020 " + version.getVendor() + ". " + version.getName()
          + " is freely licensed under the terms of the MIT License.");
  source.sendMessage(velocity);
  source.sendMessage(copyright);

  if (version.getName().equals("Velocity")) {
    TextComponent velocityWebsite = TextComponent.builder()
        .content("Visit the ")
        .append(TextComponent.builder("Velocity website")
            .color(TextColor.GREEN)
            .clickEvent(
                ClickEvent.openUrl("https://www.velocitypowered.com"))
            .build())
        .append(TextComponent.of(" or the "))
        .append(TextComponent.builder("Velocity GitHub")
            .color(TextColor.GREEN)
            .clickEvent(ClickEvent.openUrl(
                "https://github.com/VelocityPowered/Velocity"))
            .build())
        .build();
    source.sendMessage(velocityWebsite);
  }
}
 
Example #20
Source File: FakePluginManager.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public @NonNull Optional<PluginContainer> fromInstance(@NonNull Object instance) {
  if (instance == PLUGIN_A) {
    return Optional.of(PC_A);
  } else if (instance == PLUGIN_B) {
    return Optional.of(PC_B);
  } else {
    return Optional.empty();
  }
}
 
Example #21
Source File: VelocityCommand.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public boolean hasPermission(CommandSource source, String @NonNull [] args) {
  if (args.length == 0) {
    return subcommands.values().stream().anyMatch(e -> e.hasPermission(source, args));
  }
  Command command = subcommands.get(args[0].toLowerCase(Locale.US));
  if (command == null) {
    return true;
  }
  @SuppressWarnings("nullness")
  String[] actualArgs = Arrays.copyOfRange(args, 1, args.length);
  return command.hasPermission(source, actualArgs);
}
 
Example #22
Source File: VelocityServer.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public @NonNull BossBar createBossBar(
    @NonNull Component title,
    @NonNull BossBarColor color,
    @NonNull BossBarOverlay overlay,
    float progress) {
  return new VelocityBossBar(title, color, overlay, progress);
}
 
Example #23
Source File: CFAccessorCacheCaffeine.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Override
public @NonNull CompletableFuture<ListApplicationsResponse> asyncLoad(
		@NonNull CacheKeyAppsInSpace key, @NonNull Executor executor) {
	Mono<ListApplicationsResponse> mono = parent.retrieveAllApplicationIdsInSpace(key.getOrgId(), key.getSpaceId())
			.subscribeOn(Schedulers.fromExecutor(executor))
			.cache();
	return mono.toFuture();
}
 
Example #24
Source File: CFAccessorCacheCaffeine.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Override
public @NonNull CompletableFuture<GetSpaceSummaryResponse> asyncLoad(@NonNull String key,
		@NonNull Executor executor) {
	Mono<GetSpaceSummaryResponse> mono = parent.retrieveSpaceSummary(key)
			.subscribeOn(Schedulers.fromExecutor(executor))
			.cache();
	return mono.toFuture();
}
 
Example #25
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
@Override
public @NonNull Predicate<DataType> getTypeFilter(@NonNull Identifier identifier) {
    if (identifier.getType() == Identifier.GROUP_TYPE && identifier.getName().equalsIgnoreCase("default")) {
        return DataTypeFilter.NONE;
    }
    return DataTypeFilter.NORMAL_ONLY;
}
 
Example #26
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
@Override
public @NonNull Predicate<DataType> getTypeFilter(@NonNull Identifier identifier) {
    if (identifier.getType() == Identifier.GROUP_TYPE && identifier.getName().equalsIgnoreCase("default")) {
        return DataTypeFilter.NORMAL_ONLY;
    }
    return DataTypeFilter.ALL;
}
 
Example #27
Source File: Target.java    From promregator with Apache License 2.0 5 votes vote down vote up
/**
 * @return the preferredRouteRegex
 * This will never return a null value
 */
public @NonNull List<String> getPreferredRouteRegex() {
	if (this.preferredRouteRegex == null) {
		return Collections.emptyList();
	}
	
	return new ArrayList<>(preferredRouteRegex);
}
 
Example #28
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
@Override
public @NonNull Predicate<DataType> getTypeFilter(@NonNull Identifier identifier) {
    if (identifier.getType() == Identifier.GROUP_TYPE && identifier.getName().equalsIgnoreCase("default")) {
        return DataTypeFilter.TRANSIENT_ONLY;
    }
    return DataTypeFilter.ALL;
}
 
Example #29
Source File: LuckPermsProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
@Override
public @NonNull Predicate<DataType> getTypeFilter(@NonNull Identifier identifier) {
    if (identifier.getType() == Identifier.GROUP_TYPE && identifier.getName().equalsIgnoreCase("default")) {
        return DataTypeFilter.NONE;
    }
    return DataTypeFilter.NORMAL_ONLY;
}
 
Example #30
Source File: GlistCommand.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (args.length == 0) {
    sendTotalProxyCount(source);
    source.sendMessage(
        TextComponent.builder("To view all players on servers, use ", TextColor.YELLOW)
            .append("/glist all", TextColor.DARK_AQUA)
            .append(".", TextColor.YELLOW)
            .build());
  } else if (args.length == 1) {
    String arg = args[0];
    if (arg.equalsIgnoreCase("all")) {
      for (RegisteredServer server : server.getAllServers()) {
        sendServerPlayers(source, server, true);
      }
      sendTotalProxyCount(source);
    } else {
      Optional<RegisteredServer> registeredServer = server.getServer(arg);
      if (!registeredServer.isPresent()) {
        source.sendMessage(
            TextComponent.of("Server " + arg + " doesn't exist.", TextColor.RED));
        return;
      }
      sendServerPlayers(source, registeredServer.get(), false);
    }
  } else {
    source.sendMessage(TextComponent.of("Too many arguments.", TextColor.RED));
  }
}