Java Code Examples for org.checkerframework.checker.nullness.qual.Nullable

The following examples show how to use org.checkerframework.checker.nullness.qual.Nullable. 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: hadoop-ozone   Source File: ThrottledAsyncChecker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Register a callback to cache the result of a check.
 * @param target
 * @param lf
 */
private void addResultCachingCallback(
    Checkable<K, V> target, ListenableFuture<V> lf) {
  Futures.addCallback(lf, new FutureCallback<V>() {
    @Override
    public void onSuccess(@Nullable V result) {
      synchronized (ThrottledAsyncChecker.this) {
        checksInProgress.remove(target);
        completedChecks.put(target, new LastCheckResult<>(
            result, timer.monotonicNow()));
      }
    }

    @Override
    public void onFailure(@Nonnull Throwable t) {
      synchronized (ThrottledAsyncChecker.this) {
        checksInProgress.remove(target);
        completedChecks.put(target, new LastCheckResult<>(
            t, timer.monotonicNow()));
      }
    }
  }, MoreExecutors.directExecutor());
}
 
Example 2
public void setKnownProperties(@Nullable ObservableList<PropertyDescriptorSpec> props) {
    ObservableList<PropertyDescriptorSpec> safe = defaultToEmpty(props);
    getNonDefault().forEach((k, v) -> {
        if (safe.stream().noneMatch(it -> it.getName().equals(k))) {
            orphanProperties.put(k, v);
        }
    });
    knownPropsImpl.setValue(props); // we need to keep a null value in there for it to be replaced later on
    mapping.forEach((k, v) -> {
        String orphan = orphanProperties.get(k.getName());
        if (orphan != null) {
            orphanProperties.remove(k.getName());
            v.setValue(orphan);
        }
    });
}
 
Example 3
Source Project: pmd-designer   Source File: SimplePopups.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Nullable
private static Node getIconLiteral(AlertType type) {
    @Nullable String iconLit;
    switch (type) {
    case ERROR:
        iconLit = "fas-times";
        break;
    case CONFIRMATION:
        iconLit = "fas-check";
        break;
    case INFORMATION:
        iconLit = "fas-info";
        break;
    case WARNING:
        iconLit = "fas-exclamation";
        break;
    default:
        iconLit = null;
        break;
    }

    return iconLit == null ? null : new FontIcon(iconLit);
}
 
Example 4
private void updateAttr(@Nullable Attribute attr) {
    if (tooltip != null) {
        Tooltip.uninstall(this, tooltip);
        getStyleClass().remove(DEPRECATED_CSS_CLASS);
        tooltip = null;
    }

    if (attr == null) {
        return;
    }

    String replacement = attr.replacementIfDeprecated();
    if (replacement != null) {
        String txt = "This attribute is deprecated";
        if (!replacement.isEmpty()) {
            txt += ", please use " + replacement + " instead";
        }
        Tooltip t = new Tooltip(txt);
        tooltip = t;
        getStyleClass().add(DEPRECATED_CSS_CLASS);
        Tooltip.install(this, t);
    }
}
 
Example 5
@Nullable
private Tuple2<Integer, String> getInsertionPointAndQuery(int searchPoint) {
    String input = myCodeArea.getText();

    int insertionPoint = getInsertionPoint(searchPoint, input);

    if (searchPoint > input.length()) {
        searchPoint = input.length();
    }
    if (insertionPoint > searchPoint) {
        new StringIndexOutOfBoundsException("Cannot extract query from subtext \"" + input.substring(0, insertionPoint) + "\"").printStackTrace();
        return null;
    }

    // don't trim, if there is any whitespace we abort
    input = input.substring(insertionPoint, searchPoint);

    return StringUtils.isAlpha(input) ? Tuples.t(insertionPoint, input.trim()) : null;
}
 
Example 6
Source Project: GriefDefender   Source File: GDCore.java    License: MIT License 6 votes vote down vote up
@Override
public @Nullable Claim getClaim(UUID uuid) {
    for (World world : Bukkit.getServer().getWorlds()) {
        final ClaimManager claimManager = this.getClaimManager(world.getUID());
        if (claimManager == null) {
            continue;
        }
        if (claimManager.getWildernessClaim().getUniqueId().equals(uuid)) {
            return claimManager.getWildernessClaim();
        }
        for (Claim claim : claimManager.getWorldClaims()) {
            if (claim.getUniqueId().equals(uuid)) {
                return claim;
            }
        }
    }

    return null;
}
 
Example 7
Source Project: GriefDefender   Source File: EconomyDataConfig.java    License: MIT License 6 votes vote down vote up
@Override
public @Nullable Vector3i getRentSignPosition() {
    if (this.rentSignPos == null) {
        return null;
    }

    if (this.rentSignVec == null) {
        try {
            this.rentSignVec = BlockUtil.getInstance().posFromString(this.rentSignPos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return this.rentSignVec;
}
 
Example 8
Source Project: GriefDefender   Source File: EconomyDataConfig.java    License: MIT License 6 votes vote down vote up
@Override
public @Nullable Vector3i getSaleSignPosition() {
    if (this.saleSignPos == null) {
        return null;
    }

    if (this.saleSignVec == null) {
        try {
            this.saleSignVec = BlockUtil.getInstance().posFromString(this.saleSignPos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return this.saleSignVec;
}
 
Example 9
Source Project: GriefDefender   Source File: CauseContextHelper.java    License: MIT License 6 votes vote down vote up
@Nullable
public static GDPermissionUser getEventUser(Location location, PlayerTracker.Type trackerType) {
    final GDPermissionUser user = GDCauseStackManager.getInstance().getCurrentCause().first(GDPermissionUser.class).orElse(null);
    if (user != null) {
        return user;
    }
    if (location == null) {
        return null;
    }

    final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getWorld().getUID());
    final GDChunk gdChunk = claimWorldManager.getChunk(location.getChunk());
    if (trackerType != null) {
        if (trackerType == PlayerTracker.Type.OWNER) {
            return gdChunk.getBlockOwner(location);
        }
        return gdChunk.getBlockNotifier(location);
    }

    return gdChunk.getBlockUser(location);
}
 
Example 10
Source Project: GriefDefender   Source File: PlayerUtil.java    License: MIT License 6 votes vote down vote up
@Nullable
public String getUserName(UUID uuid) {
    if (uuid.equals(GriefDefenderPlugin.PUBLIC_UUID)) {
        return "public";
    }
    if (uuid.equals(GriefDefenderPlugin.ADMIN_USER_UUID) || uuid.equals(GriefDefenderPlugin.WORLD_USER_UUID)) {
        return "administrator";
    }

    final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(uuid);
    if (user == null) {
        return "unknown";
    }
    if (user.getName() != null) {
        return user.getName();
    }
    // check offline player
    final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
    if (offlinePlayer == null) {
        return "unknown";
    }
    return offlinePlayer.getName();
}
 
Example 11
Source Project: GriefDefender   Source File: GDCore.java    License: MIT License 6 votes vote down vote up
@Override
public @Nullable Claim getClaim(UUID uuid) {
    for (World world : Sponge.getServer().getWorlds()) {
        final ClaimManager claimManager = this.getClaimManager(world.getUniqueId());
        if (claimManager == null) {
            continue;
        }
        if (claimManager.getWildernessClaim().getUniqueId().equals(uuid)) {
            return claimManager.getWildernessClaim();
        }
        for (Claim claim : claimManager.getWorldClaims()) {
            if (claim.getUniqueId().equals(uuid)) {
                return claim;
            }
        }
    }

    return null;
}
 
Example 12
Source Project: GriefDefender   Source File: EconomyDataConfig.java    License: MIT License 6 votes vote down vote up
@Override
public @Nullable Vector3i getRentSignPosition() {
    if (this.rentSignPos == null) {
        return null;
    }

    if (this.rentSignVec == null) {
        try {
            this.rentSignVec = BlockUtil.getInstance().posFromString(this.rentSignPos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return this.rentSignVec;
}
 
Example 13
Source Project: GriefDefender   Source File: EconomyDataConfig.java    License: MIT License 6 votes vote down vote up
@Override
public @Nullable Vector3i getSaleSignPosition() {
    if (this.saleSignPos == null) {
        return null;
    }

    if (this.saleSignVec == null) {
        try {
            this.saleSignVec = BlockUtil.getInstance().posFromString(this.saleSignPos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return this.saleSignVec;
}
 
Example 14
Source Project: hadoop-ozone   Source File: HddsVolumeChecker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param healthyVolumes set of healthy volumes. If the disk check is
 *                       successful, add the volume here.
 * @param failedVolumes  set of failed volumes. If the disk check fails,
 *                       add the volume here.
 * @param volumeCounter  volumeCounter used to trigger callback invocation.
 * @param callback       invoked when the volumeCounter reaches 0.
 */
ResultHandler(HddsVolume volume,
    Set<HddsVolume> healthyVolumes,
    Set<HddsVolume> failedVolumes,
    AtomicLong volumeCounter,
    @Nullable Callback callback) {
  this.volume = volume;
  this.healthyVolumes = healthyVolumes;
  this.failedVolumes = failedVolumes;
  this.volumeCounter = volumeCounter;
  this.callback = callback;
}
 
Example 15
Source Project: hadoop-ozone   Source File: HddsVolumeChecker.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(@Nullable VolumeCheckResult result) {
  if (result == null) {
    LOG.error("Unexpected empty health check result for volume {}", volume);
    markHealthy();
  } else {
    switch (result) {
    case HEALTHY:
    case DEGRADED:
      if (LOG.isDebugEnabled()) {
        LOG.debug("Volume {} is {}.", volume, result);
      }
      markHealthy();
      break;
    case FAILED:
      LOG.warn("Volume {} detected as being unhealthy", volume);
      markFailed();
      break;
    default:
      LOG.error("Unexpected health check result {} for volume {}", result,
          volume);
      markHealthy();
      break;
    }
  }
  cleanup();
}
 
Example 16
/**
 * Return the MediaLibraryStatistics saved on commit in the index. Ensures that each index reports the same data.
 * On invalid indices, returns null.
 */
public @Nullable MediaLibraryStatistics getStatistics() {
    Set<MediaLibraryStatistics> stats = EnumSet.allOf(IndexType.class).parallelStream().map(t -> {
        IndexSearcher searcher = getSearcher(t);
        if (searcher == null) {
            LOG.trace("No index for type {}", t);
            return null;
        }
        IndexReader indexReader = searcher.getIndexReader();
        if (!(indexReader instanceof DirectoryReader)) {
            LOG.warn("Unexpected index type {} for {}", indexReader.getClass(), t);
            return null;
        }
        try {
            Map<String, String> userData = ((DirectoryReader) indexReader).getIndexCommit().getUserData();
            return Util.stringMapToValidObject(MediaLibraryStatistics.class, userData);
        } catch (IOException | IllegalArgumentException e) {
            LOG.debug("Exception encountered while fetching index commit data for {}", t, e);
            return null;
        }
    }).distinct().collect(Collectors.toSet());

    if (stats.size() > 1) {
        LOG.warn("Differing stats data for different indices: {}", stats.stream().map(x -> Util.objectToStringMap(x)).collect(Collectors.toSet()));
        return null;
    }

    return stats.stream().map(x -> Optional.ofNullable(x)).findAny().flatMap(x -> x).orElse(null);
}
 
Example 17
Source Project: influx-proxy   Source File: ProxyMonitorService.java    License: Apache License 2.0 5 votes vote down vote up
public void onPing(ProxyInstance proxyInstance){
    @Nullable ProxyInstance existProxyInstance = proxyInstanceCache.getIfPresent(proxyInstance.toString());
    if(existProxyInstance==null){
       proxyInstanceCache.put(proxyInstance.toString(),proxyInstance);
    }
    existProxyInstance=proxyInstanceCache.getIfPresent(proxyInstance.toString());
    if(existProxyInstance!=null){
        existProxyInstance.setLastTimestamp(new Date());
    }
}
 
Example 18
Source Project: beihu-boot   Source File: Functions.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object o) {
    if (o instanceof ForMapWithAbsentFunction) {
        ForMapWithAbsentFunction<?, ?> that = (ForMapWithAbsentFunction<?, ?>) o;
        return map.equals(that.map) && Objects.equals(absentFunction, that.absentFunction);
    }
    return false;
}
 
Example 19
@Nullable
@Override
public ConverterConfig loadConfig(ConfigurationNode node) throws NullPointerException {
    ConverterConfig converterConfig = new ConverterConfig(
            node.getNode("com", "liumapp", "workable-converter", "libreofficePath").getString(),
            node.getNode("com", "liumapp", "workable-converter", "libreofficePort").getInt(),
            node.getNode("com", "liumapp", "workable-converter", "tmpPath").getString(),
            node.getNode("com","liumapp","workable-converter","fontsPath").getString()
    );
    return converterConfig;
}
 
Example 20
Source Project: pmd-designer   Source File: LiveTestCase.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public LiveTestCase(@Nullable ObservableRuleBuilder owner) {
    freeze();
    rule.setValue(owner);

    rule.values().subscribe(
        r -> liveProperties.setKnownProperties(r == null ? null : r.getRuleProperties())
    );
}
 
Example 21
Source Project: pmd-designer   Source File: TestXmlParser.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static LiveTestCase fromDescriptor(
    String code,
    String description,
    int expectedProblems,
    @Nullable LanguageVersion version,
    boolean ignored,
    List<String> messages,
    List<Integer> lineNumbers,
    Properties properties,
    ObservableRuleBuilder owner
) {

    LiveTestCase live = new LiveTestCase();
    live.setRule(owner);
    live.setSource(code);
    live.setDescription(description);
    live.setLanguageVersion(version);
    live.setIgnored(ignored);

    List<String> lines = Arrays.asList(code.split("\\r?\\n"));

    for (int i = 0; i < expectedProblems; i++) {
        String m = messages.size() > i ? messages.get(i) : null;
        int line = lineNumbers.size() > i ? lineNumbers.get(i) : -1;

        TextRange tr = line >= 0
                       ? TextRange.fullLine(line, lines.get(line - 1).length())
                       : null;

        live.getExpectedViolations().add(new LiveViolationRecord(tr, m, false));
    }
    properties.forEach((k, v) -> live.setProperty(k.toString(), v.toString()));
    return live;
}
 
Example 22
public TestCollection(@Nullable ObservableRuleBuilder owner, List<LiveTestCase> tests) {
    this.stash = new LiveArrayList<>(tests);
    this.owner = owner;
    if (owner != null) {
        stash.forEach(it -> it.setRule(this.owner));
    }
}
 
Example 23
/**
 * Opens a test case for write access.
 */
@Nullable
public LiveTestCase export(int i) {
    if (0 <= i && i < stash.size()) {
        stash.forEach(LiveTestCase::freeze);
        return stash.get(i).unfreeze();
    } else {
        return null;
    }
}
 
Example 24
public PropertyMapModel(@Nullable ObservableList<PropertyDescriptorSpec> knownProps) {
    ObservableList<PropertyDescriptorSpec> safe = defaultToEmpty(knownProps);
    Pair<ObservableMap<PropertyDescriptorSpec, Var<String>>, RebindSubscription<ObservableList<PropertyDescriptorSpec>>> mappingAndSub = localMapper(safe);
    this.mapping = mappingAndSub.getKey();

    this.knownPropsImpl.setValue(knownProps);

    knownPropsImpl.orElseConst(emptyObservableList()).values().subscribe(ps -> mappingAndSub.getValue().rebind(ps));
}
 
Example 25
Source Project: pmd-designer   Source File: SimplePopups.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Show a transient popup with a message, to let the user know an action
 * was performed.
 *
 * @param owner Node next to which the popup will be shown
 * @return
 */
public static EventStream<?> showActionFeedback(@NonNull Node owner,
                                                @Nullable Node graphic,
                                                @NonNull String message,
                                                double offsetX,
                                                boolean stick,
                                                String... cssClasses) {

    Popup popup = new Popup();
    Label label = new Label(message, graphic);
    StackPane pane = new StackPane();

    DesignerUtil.addCustomStyleSheets(pane, "designer");
    pane.getStyleClass().addAll("action-feedback");
    pane.getStyleClass().addAll(cssClasses);

    pane.getChildren().addAll(label);
    popup.getContent().addAll(pane);

    Animation fadeTransition = stick ? fadeInAnimation(pane) : bounceFadeAnimation(pane);
    EventSource<?> closeTick = new EventSource<>();
    if (stick) {
        pane.setOnMouseClicked(evt -> {
            popup.hide();
            closeTick.push(null);
        });
    } else {
        fadeTransition.setOnFinished(e -> {
            popup.hide();
            closeTick.push(null);
        });
    }

    popup.setOnShowing(e -> fadeTransition.play());

    Bounds screenBounds = owner.localToScreen(owner.getBoundsInLocal());
    popup.show(owner, screenBounds.getMaxX() + offsetX, screenBounds.getMinY());
    return closeTick;
}
 
Example 26
/**
 * Update the syntax highlighting to the specified value.
 * If null, syntax highlighting is stripped off.
 */
private void setCurrentSyntaxHighlight(final @Nullable StyleSpans<Collection<String>> newSyntax) {
    StyleSpans<Collection<String>> oldSyntaxHighlight = currentSyntaxHighlight.getValue();
    this.currentSyntaxHighlight.setValue(newSyntax);

    setStyleSpans(0, styleSyntaxHighlightChange(oldSyntaxHighlight, newSyntax));
}
 
Example 27
/**
 * Attempts to preserve the other layers when syntax highlighting changes. The result
 * misplaces some style classes, which is undesirable, but covered up by the subsequent
 * parsing update.
 */
@Override
@NonNull
protected final StyleSpans<Collection<String>> styleSyntaxHighlightChange(final @Nullable StyleSpans<Collection<String>> oldSyntax,
                                                                          final @Nullable StyleSpans<Collection<String>> newSyntax) {

    StyleSpans<Collection<String>> currentSpans = getStyleSpans(new IndexRange(0, getLength()));
    StyleSpans<Collection<String>> base = Optional.ofNullable(oldSyntax).map(s -> subtract(currentSpans, s)).orElse(currentSpans);

    return Optional.ofNullable(newSyntax)
                   .map(s -> base.overlay(s, SyntaxHighlightingCodeArea::additiveOverlay))
                   .orElse(base)
                   .subView(0, getLength());
}
 
Example 28
Source Project: pmd-designer   Source File: ReactfxUtil.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Add a hook on the owner window. It's not possible to do this statically,
 * since at construction time the window might not be set.
 */
public static <T> Subscription subscribeDisposable(ObservableValue<@Nullable ? extends T> node,
                                                   Function<@NonNull ? super T, Subscription> subscriber) {
    return ReactfxExtensions.dynamic(
        LiveList.wrapVal(node),
        (w, i) -> subscriber.apply(w)
    );
}
 
Example 29
@Nullable
public static synchronized LanguageVersion getLanguageVersionFromExtension(String filename) {
    if (extensionsToLanguage == null) {
        extensionsToLanguage = getExtensionsToLanguageMap();
    }

    if (filename.indexOf('.') > 0) {
        String[] tokens = filename.split("\\.");
        return extensionsToLanguage.get(tokens[tokens.length - 1]);
    }
    return null;
}
 
Example 30
Source Project: GriefDefender   Source File: GDClaimManager.java    License: MIT License 5 votes vote down vote up
@Nullable
public Set<Claim> getPlayerClaims(UUID playerUniqueId) {
    final GDPlayerData playerData = this.getPlayerDataMap().get(playerUniqueId);
    if (playerData == null) {
        return ImmutableSet.of();
    }
    return ImmutableSet.copyOf(this.getPlayerDataMap().get(playerUniqueId).getInternalClaims());
}