List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:org.attribyte.wp.model.User.java
/** * The display name, if set, otherwise the username. * @return The display name to use.//from w w w . ja va 2 s. c o m */ public final String displayName() { return Strings.nullToEmpty(displayName).trim().isEmpty() ? username : displayName; }
From source file:org.sonar.db.ce.CeActivityDto.java
public CeActivityDto(CeQueueDto queueDto) { this.uuid = queueDto.getUuid(); this.taskType = queueDto.getTaskType(); this.componentUuid = queueDto.getComponentUuid(); this.isLastKey = format("%s%s", taskType, Strings.nullToEmpty(componentUuid)); this.submitterLogin = queueDto.getSubmitterLogin(); this.workerUuid = queueDto.getWorkerUuid(); this.executionCount = queueDto.getExecutionCount(); this.submittedAt = queueDto.getCreatedAt(); this.startedAt = queueDto.getStartedAt(); }
From source file:com.kegare.caveworld.core.CaveVeinManager.java
@Override public boolean addCaveVein(ICaveVein vein) { String block = vein == null ? null : GameData.getBlockRegistry().getNameForObject(vein.getBlock().getBlock()); int blockMetadata = vein == null ? -1 : vein.getBlock().getMetadata(); int count = vein == null ? -1 : vein.getGenBlockCount(); int weight = vein == null ? -1 : vein.getGenWeight(); int rate = vein == null ? -1 : vein.getGenRate(); int min = vein == null ? -1 : vein.getGenMinHeight(); int max = vein == null ? -1 : vein.getGenMaxHeight(); String target = vein == null ? null : GameData.getBlockRegistry().getNameForObject(vein.getGenTargetBlock().getBlock()); int targetMetadata = vein == null ? -1 : vein.getGenTargetBlock().getMetadata(); int[] biomes = vein == null ? null : vein.getGenBiomes(); String name = Integer.toString(CAVE_VEINS.size()); if (vein == null && !Config.veinsCfg.hasCategory(name)) { return false; }/*w w w. j ava2 s .co m*/ String category = "veins"; Property prop; List<String> propOrder = Lists.newArrayList(); prop = Config.veinsCfg.get(name, "block", GameData.getBlockRegistry().getNameForObject(Blocks.stone)); prop.setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()) .setConfigEntryClass(Config.selectBlockEntryClass); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); if (!Strings.isNullOrEmpty(block)) prop.set(block); propOrder.add(prop.getName()); block = prop.getString(); if (!GameData.getBlockRegistry().containsKey(Strings.nullToEmpty(block))) return false; prop = Config.veinsCfg.get(name, "blockMetadata", 0); prop.setMinValue(0).setMaxValue(15).setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); prop.comment += " [range: " + prop.getMinValue() + " ~ " + prop.getMaxValue() + ", default: " + prop.getDefault() + "]"; if (blockMetadata >= 0) prop.set(MathHelper.clamp_int(blockMetadata, Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue()))); propOrder.add(prop.getName()); blockMetadata = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue())); prop = Config.veinsCfg.get(name, "genBlockCount", 1); prop.setMinValue(1).setMaxValue(500) .setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); prop.comment += " [range: " + prop.getMinValue() + " ~ " + prop.getMaxValue() + ", default: " + prop.getDefault() + "]"; if (count >= 0) prop.set(MathHelper.clamp_int(count, Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue()))); propOrder.add(prop.getName()); count = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue())); prop = Config.veinsCfg.get(name, "genWeight", 1); prop.setMinValue(1).setMaxValue(100) .setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); prop.comment += " [range: " + prop.getMinValue() + " ~ " + prop.getMaxValue() + ", default: " + prop.getDefault() + "]"; if (weight >= 0) prop.set(MathHelper.clamp_int(weight, Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue()))); propOrder.add(prop.getName()); weight = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue())); prop = Config.veinsCfg.get(name, "genRate", 100); prop.setMinValue(1).setMaxValue(100) .setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); prop.comment += " [range: " + prop.getMinValue() + " ~ " + prop.getMaxValue() + ", default: " + prop.getDefault() + "]"; if (rate >= 0) prop.set(MathHelper.clamp_int(rate, Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue()))); propOrder.add(prop.getName()); rate = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue())); prop = Config.veinsCfg.get(name, "genMinHeight", 0); prop.setMinValue(0).setMaxValue(254) .setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); prop.comment += " [range: " + prop.getMinValue() + " ~ " + prop.getMaxValue() + ", default: " + prop.getDefault() + "]"; if (min >= 0) prop.set(MathHelper.clamp_int(min, Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue()))); propOrder.add(prop.getName()); min = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue())); prop = Config.veinsCfg.get(name, "genMaxHeight", 255); prop.setMinValue(1).setMaxValue(255) .setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); prop.comment += " [range: " + prop.getMinValue() + " ~ " + prop.getMaxValue() + ", default: " + prop.getDefault() + "]"; if (max >= 0) prop.set(MathHelper.clamp_int(max, min + 1, Integer.parseInt(prop.getMaxValue()))); propOrder.add(prop.getName()); max = MathHelper.clamp_int(prop.getInt(), min + 1, Integer.parseInt(prop.getMaxValue())); prop = Config.veinsCfg.get(name, "genTargetBlock", GameData.getBlockRegistry().getNameForObject(Blocks.stone)); prop.setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); prop.comment += " [default: " + prop.getDefault() + "]"; if (!Strings.isNullOrEmpty(target)) prop.set(target); if (!GameData.getBlockRegistry().containsKey(prop.getString())) prop.setToDefault(); propOrder.add(prop.getName()); target = prop.getString(); prop = Config.veinsCfg.get(name, "genTargetBlockMetadata", 0); prop.setMinValue(0).setMaxValue(15).setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); prop.comment += " [range: " + prop.getMinValue() + " ~ " + prop.getMaxValue() + ", default: " + prop.getDefault() + "]"; if (targetMetadata >= 0) prop.set(MathHelper.clamp_int(targetMetadata, Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue()))); propOrder.add(prop.getName()); targetMetadata = MathHelper.clamp_int(prop.getInt(), Integer.parseInt(prop.getMinValue()), Integer.parseInt(prop.getMaxValue())); prop = Config.veinsCfg.get(name, "genBiomes", new int[0]); prop.setLanguageKey(Caveworld.CONFIG_LANG + category + '.' + prop.getName()); prop.comment = StatCollector.translateToLocal(prop.getLanguageKey() + ".tooltip"); if (biomes != null) prop.set(biomes); propOrder.add(prop.getName()); biomes = prop.getIntList(); Config.veinsCfg.setCategoryPropertyOrder(name, propOrder); if (vein == null) { vein = new CaveVein(new BlockEntry(block, blockMetadata), count, weight, rate, min, max, new BlockEntry(target, targetMetadata), biomes); } return CAVE_VEINS.addIfAbsent(vein); }
From source file:com.capitaltg.bbcodeguard.hooks.PreMergeVerifyCheck.java
private Optional<Comment> findLatestVerifyComment(PullRequest pullRequest) { int repoId = pullRequest.getToRef().getRepository().getId(); long prid = pullRequest.getId(); PageRequest pageRequest = new PageRequestImpl(0, 1000); Page<PullRequestActivity> activities = pullRequestService.getActivities(repoId, prid, pageRequest); List<Comment> comments = (StreamSupport.stream(activities.getValues().spliterator(), false) .filter(isPullRequestCommentActivity).map(a -> ((PullRequestCommentActivity) a).getComment()) .filter(c -> Strings.nullToEmpty(c.getText()).toLowerCase().contains("verification job")) .sorted(compareByReverseDate).collect(Collectors.toList())); Optional<Comment> optional = comments.stream().findFirst(); return optional; }
From source file:io.janusproject.kernel.bic.LoggingSkill.java
@Override public void error(Object message) { if (this.logger.isLoggable(Level.SEVERE)) { String m = Strings.nullToEmpty(message == null ? null : message.toString()); this.logger.log(Level.SEVERE, m); }//from w w w .jav a 2 s. c om }
From source file:com.google.gerrit.server.change.PutAssignee.java
@Override public AccountInfo apply(ChangeResource rsrc, AssigneeInput input) throws RestApiException, UpdateException, OrmException, IOException, PermissionBackendException { rsrc.permissions().check(ChangePermission.EDIT_ASSIGNEE); input.assignee = Strings.nullToEmpty(input.assignee).trim(); if (input.assignee.isEmpty()) { throw new BadRequestException("missing assignee field"); }//from www . j a v a2 s . c o m IdentifiedUser assignee = accounts.parse(input.assignee); if (!assignee.getAccount().isActive()) { throw new UnprocessableEntityException(input.assignee + " is not active"); } try { rsrc.permissions().database(db).user(assignee).check(ChangePermission.READ); } catch (AuthException e) { throw new AuthException("read not permitted for " + input.assignee); } try (BatchUpdate bu = batchUpdateFactory.create(db.get(), rsrc.getChange().getProject(), rsrc.getControl().getUser(), TimeUtil.nowTs())) { SetAssigneeOp op = assigneeFactory.create(assignee); bu.addOp(rsrc.getId(), op); PostReviewers.Addition reviewersAddition = addAssigneeAsCC(rsrc, input.assignee); bu.addOp(rsrc.getId(), reviewersAddition.op); bu.execute(); return accountLoaderFactory.create(true).fillOne(assignee.getAccountId()); } }
From source file:com.demonwav.mcdev.buildsystem.gradle.AbstractDataService.java
public static void setupModules(@NotNull Set<Module> goodModules, @NotNull Set<Module> allModules, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull AbstractModuleType<?> type) { // So the way the Gradle plugin sets it up is with 3 modules. There's the parent module, which the Gradle // dependencies don't apply to, then submodules under it, normally main and test, which the Gradle dependencies // do apply to. We're interested (when setting the module type) in the parent, which is what we do here. The // first module should be the parent, but we check to make sure anyways ApplicationManager.getApplication().runReadAction(() -> { Set<Module> checkedModules = new HashSet<>(); Set<Module> badModules = new HashSet<>(); checkedModules.addAll(goodModules); goodModules.stream().filter(m -> m != null) .forEach(m -> findParent(m, modelsProvider, type, checkedModules, badModules)); // Reset all other modules back to JavaModule && remove the type for (Module module : allModules) { if (module == null) { continue; }/*from w w w.jav a 2s. com*/ if (!checkedModules.contains(module) || badModules.contains(module)) { if (Strings.nullToEmpty(module.getOptionValue("type")).equals(type.getId())) { module.setOption("type", JavaModuleType.getModuleType().getId()); } MinecraftModuleType.removeOption(module, type.getId()); } } }); }
From source file:org.jboss.errai.ui.rebind.DataFieldCodeDecorator.java
private String getTemplateDataFieldName(DataField annotation, String deflt) { String value = Strings.nullToEmpty(annotation.value()).trim(); return value.isEmpty() ? deflt : value; }
From source file:org.zenoss.metrics.reporter.ZenossMetricsReporter.java
private ZenossMetricsReporter(MetricsRegistry registry, String name, MetricPoster poster, MetricPredicate filter, String metricPrefix, Map<String, String> tags, Clock clock, VirtualMachineMetrics vm, boolean reportJvmMetrics, long period, TimeUnit periodUnit, long shutdownTimeout, TimeUnit shutdownTimeoutUnit) { super(registry, name); this.poster = poster; this.filter = filter; this.clock = clock; this.reportJvmMetrics = reportJvmMetrics; this.metricPrefix = Strings.nullToEmpty(metricPrefix).trim(); this.tags = Maps.newHashMap(tags); this.vm = vm; this.period = period; this.periodUnit = periodUnit; this.shutdownTimeout = shutdownTimeout; this.shutdownTimeoutUnit = shutdownTimeoutUnit; }
From source file:com.google.gerrit.server.git.AbandonOp.java
@Inject AbandonOp(AbandonedSender.Factory abandonedSenderFactory, ChangeMessagesUtil cmUtil, PatchSetUtil psUtil, ChangeAbandoned changeAbandoned, @Assisted @Nullable Account account, @Assisted @Nullable String msgTxt, @Assisted NotifyHandling notifyHandling, @Assisted ListMultimap<RecipientType, Account.Id> accountsToNotify) { this.abandonedSenderFactory = abandonedSenderFactory; this.cmUtil = cmUtil; this.psUtil = psUtil; this.changeAbandoned = changeAbandoned; this.account = account; this.msgTxt = Strings.nullToEmpty(msgTxt); this.notifyHandling = notifyHandling; this.accountsToNotify = accountsToNotify; }