List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:org.obm.push.mail.greenmail.ExternalProcess.java
public ExternalProcess(String executablePath, long processTimeout, long processStartTimeNeeded) { Preconditions.checkNotNull(Strings.emptyToNull(executablePath)); Preconditions.checkArgument(processTimeout > 0); this.cli = new CommandLine(executablePath); this.environment = Maps.newHashMap(); this.processTimeout = processTimeout; this.processStartTimeNeeded = processStartTimeNeeded; this.processOutputStream = new ByteArrayOutputStream(); this.streamHandler = new PumpStreamHandler(processOutputStream, System.err); }
From source file:org.sosy_lab.solver.mathsat5.Mathsat5NativeApi.java
private static boolean processSolveResult(long e, int resultCode) throws IllegalStateException { switch (resultCode) { case MSAT_SAT: return true; case MSAT_UNSAT: return false; default:/*from w w w.j a v a 2 s. c o m*/ String msg = Strings.emptyToNull(msat_last_error_message(e)); String code = (resultCode == MSAT_UNKNOWN) ? "\"unknown\"" : resultCode + ""; throw new IllegalStateException("msat_solve returned " + code + (msg != null ? ": " + msg : "")); } }
From source file:com.google.gerrit.server.project.ConfigInfo.java
public ConfigInfo(boolean serverEnableSignedPush, ProjectControl control, TransferConfig config, DynamicMap<ProjectConfigEntry> pluginConfigEntries, PluginConfigFactory cfgFactory, AllProjectsNameProvider allProjects, DynamicMap<RestView<ProjectResource>> views) { ProjectState projectState = control.getProjectState(); Project p = control.getProject();/*from w w w. ja v a 2 s. c om*/ this.description = Strings.emptyToNull(p.getDescription()); InheritedBooleanInfo useContributorAgreements = new InheritedBooleanInfo(); InheritedBooleanInfo useSignedOffBy = new InheritedBooleanInfo(); InheritedBooleanInfo useContentMerge = new InheritedBooleanInfo(); InheritedBooleanInfo requireChangeId = new InheritedBooleanInfo(); InheritedBooleanInfo createNewChangeForAllNotInTarget = new InheritedBooleanInfo(); InheritedBooleanInfo enableSignedPush = new InheritedBooleanInfo(); InheritedBooleanInfo requireSignedPush = new InheritedBooleanInfo(); useContributorAgreements.value = projectState.isUseContributorAgreements(); useSignedOffBy.value = projectState.isUseSignedOffBy(); useContentMerge.value = projectState.isUseContentMerge(); requireChangeId.value = projectState.isRequireChangeID(); createNewChangeForAllNotInTarget.value = projectState.isCreateNewChangeForAllNotInTarget(); useContributorAgreements.configuredValue = p.getUseContributorAgreements(); useSignedOffBy.configuredValue = p.getUseSignedOffBy(); useContentMerge.configuredValue = p.getUseContentMerge(); requireChangeId.configuredValue = p.getRequireChangeID(); createNewChangeForAllNotInTarget.configuredValue = p.getCreateNewChangeForAllNotInTarget(); enableSignedPush.configuredValue = p.getEnableSignedPush(); requireSignedPush.configuredValue = p.getRequireSignedPush(); ProjectState parentState = Iterables.getFirst(projectState.parents(), null); if (parentState != null) { useContributorAgreements.inheritedValue = parentState.isUseContributorAgreements(); useSignedOffBy.inheritedValue = parentState.isUseSignedOffBy(); useContentMerge.inheritedValue = parentState.isUseContentMerge(); requireChangeId.inheritedValue = parentState.isRequireChangeID(); createNewChangeForAllNotInTarget.inheritedValue = parentState.isCreateNewChangeForAllNotInTarget(); enableSignedPush.inheritedValue = projectState.isEnableSignedPush(); requireSignedPush.inheritedValue = projectState.isRequireSignedPush(); } this.useContributorAgreements = useContributorAgreements; this.useSignedOffBy = useSignedOffBy; this.useContentMerge = useContentMerge; this.requireChangeId = requireChangeId; this.createNewChangeForAllNotInTarget = createNewChangeForAllNotInTarget; if (serverEnableSignedPush) { this.enableSignedPush = enableSignedPush; this.requireSignedPush = requireSignedPush; } MaxObjectSizeLimitInfo maxObjectSizeLimit = new MaxObjectSizeLimitInfo(); maxObjectSizeLimit.value = config.getEffectiveMaxObjectSizeLimit(projectState) == config .getMaxObjectSizeLimit() ? config.getFormattedMaxObjectSizeLimit() : p.getMaxObjectSizeLimit(); maxObjectSizeLimit.configuredValue = p.getMaxObjectSizeLimit(); maxObjectSizeLimit.inheritedValue = config.getFormattedMaxObjectSizeLimit(); this.maxObjectSizeLimit = maxObjectSizeLimit; this.submitType = p.getSubmitType(); this.state = p.getState() != com.google.gerrit.extensions.client.ProjectState.ACTIVE ? p.getState() : null; this.commentlinks = Maps.newLinkedHashMap(); for (CommentLinkInfo cl : projectState.getCommentLinks()) { this.commentlinks.put(cl.name, cl); } pluginConfig = getPluginConfig(control.getProjectState(), pluginConfigEntries, cfgFactory, allProjects); actions = Maps.newTreeMap(); for (UiAction.Description d : UiActions.from(views, new ProjectResource(control), Providers.of(control.getUser()))) { actions.put(d.getId(), new ActionInfo(d)); } this.theme = projectState.getTheme(); }
From source file:org.obiba.onyx.quartz.core.engine.questionnaire.question.Attributes.java
/** * @param namespace//from w ww .ja va2 s. co m * @param name * @param locale * @return */ public static Predicate<Attribute> predicate(final String namespace, final String name, final Locale locale) { final String nullIfEmptyNamespace = Strings.emptyToNull(namespace); return new Predicate<Attribute>() { @Override public boolean apply(Attribute input) { return input.getName().equals(name) && (input.getNamespace() == null ? nullIfEmptyNamespace == null : input.getNamespace().equals(nullIfEmptyNamespace)) && (input.getLocale() == null ? locale == null : input.getLocale().equals(locale)); } }; }
From source file:org.gbif.pubindex.service.impl.ArticleIndexerImpl.java
@Inject public ArticleIndexerImpl(PubindexConfig cfg, ArticleService articleService, HttpUtil http, HttpClient client, NameFoundService nameFoundService) { this.articleService = articleService; this.nameFoundService = nameFoundService; this.http = http; this.client = client; this.finderWS = Strings.emptyToNull(cfg.nameFinderWs); if (finderWS == null) { LOG.warn("No Name Finder Webservice configured! Skipping article indexing"); } else {//from w w w .j a v a 2 s .c o m LOG.info("Using Name Finder Webservice at {}", finderWS); } }
From source file:fr.obeo.releng.targetplatform.resolved.ResolvedTargetPlatform.java
public static ResolvedTargetPlatform create(TargetPlatform targetPlatform, LocationIndexBuilder indexBuilder) throws URISyntaxException { Preconditions.checkArgument(targetPlatform != null); LinkedList<ResolvedLocation> locations = Lists.newLinkedList(); ListMultimap<String, Location> locationIndex = indexBuilder.getLocationIndex(targetPlatform); for (String locationUri : locationIndex.keySet()) { List<UnresolvedIU> ius = Lists.newArrayList(); Set<String> ids = Sets.newHashSet(); List<Location> list = locationIndex.get(locationUri); for (Location location : list) { EList<IU> iuList = location.getIus(); for (IU iu : iuList) { if (!ids.contains(iu.getID())) { ids.add(iu.getID()); ius.add(new UnresolvedIU(iu.getID(), Strings.emptyToNull(iu.getVersion()))); }/* w w w . j a v a2 s . c o m*/ } } Location firstLocation = locationIndex.get(locationUri).get(0); ResolvedLocation resolvedLocation = new ResolvedLocation(firstLocation.getID(), firstLocation.getUri(), ius, getOptionSet(firstLocation.getOptions())); locations.addFirst(resolvedLocation); } final EnumSet<Option> options = getOptionSet(targetPlatform.getOptions()); return new ResolvedTargetPlatform(targetPlatform.getName(), locations, options, Environment.create(targetPlatform)); }
From source file:email.schaal.ocreader.api.json.ItemTypeAdapter.java
@Override public Item fromJson(JsonReader in) throws IOException { if (in.peek() == JsonReader.Token.NULL) { in.nextNull();//from w ww . j a v a 2 s .c om return null; } final NullableJsonReader reader = new NullableJsonReader(in); final Item.Builder builder = new Item.Builder(); in.beginObject(); while (in.hasNext()) { String name = in.nextName(); switch (name) { case "id": builder.setId(in.nextLong()); break; case "guid": builder.setGuid(in.nextString()); break; case "guidHash": builder.setGuidHash(in.nextString()); break; case "url": builder.setUrl(reader.nextString()); break; case "title": builder.setTitle(StringUtils.cleanString(in.nextString())); break; case "author": builder.setAuthor(Strings.emptyToNull(in.nextString())); break; case "pubDate": builder.setPubDate(new Date(in.nextLong() * 1000)); break; case "body": builder.setBody(in.nextString()); break; case "enclosureMime": if (in.peek() != JsonReader.Token.NULL) builder.setEnclosureMime(Strings.emptyToNull(in.nextString())); else in.skipValue(); break; case "enclosureLink": if (in.peek() != JsonReader.Token.NULL) builder.setEnclosureLink(Strings.emptyToNull(in.nextString())); else in.skipValue(); break; case "publishedAt": builder.setPubDate(parseDate(in.nextString())); break; case "updatedAt": builder.setUpdatedAt(parseDate(in.nextString())); break; case "enclosure": parseEnclosure(reader, builder); break; case "feedId": builder.setFeedId(in.nextLong()); break; case "isUnread": case "unread": builder.setUnread(in.nextBoolean()); break; case "starred": case "isStarred": builder.setStarred(in.nextBoolean()); break; case "lastModified": builder.setLastModified(in.nextLong()); break; case "rtl": in.skipValue(); break; case "fingerprint": builder.setFingerprint(in.nextString()); break; case "contentHash": // ignore for now, old items don't have this set yet. //item.setContentHash(in.nextString()); in.skipValue(); break; case "updatedDate": if (in.peek() == JsonReader.Token.NUMBER) builder.setUpdatedAt(new Date(in.nextLong() * 1000)); else in.skipValue(); break; default: Log.w(TAG, "Unknown value in item json: " + name); in.skipValue(); break; } } in.endObject(); return builder.build(); }
From source file:io.druid.server.lookup.LoadingLookup.java
@Override public String apply(final String key) { if (key == null) { return null; }// w w w. ja v a 2 s . c om final String presentVal; try { presentVal = loadingCache.get(key, new applyCallable(key)); return Strings.emptyToNull(presentVal); } catch (ExecutionException e) { LOGGER.debug("value not found for key [%s]", key); return null; } }
From source file:io.druid.server.listener.announcer.ListeningAnnouncerConfig.java
/** * Build a path for the particular named listener. The first implementation of this is used with zookeeper, but * there is nothing restricting its use in a more general pathing (example: http endpoint proxy for raft) * @param listenerName The key for the listener. * @return A path appropriate for use in zookeeper to discover the listeners with the particular listener name *//* w ww . ja v a2 s . c o m*/ public String getAnnouncementPath(String listenerName) { return ZKPaths.makePath(getListenersPath(), Preconditions.checkNotNull(Strings.emptyToNull(listenerName), "Listener name cannot be null")); }
From source file:org.dcache.gplazma.roles.RolesPlugin.java
private static Long getGidForRole(Properties properties, String name) { String property = Strings.emptyToNull(properties.getProperty(name)); if (property == null) { return null; }//from www . j ava 2 s . c o m try { return Long.parseLong(property, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException("Badly formatted " + name + " value: " + e); } }