List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:com.ericsson.gerrit.plugins.highavailability.forwarder.rest.GsonParser.java
static Object fromJson(String cacheName, String json) { Gson gson = new GsonBuilder().create(); Object key;/*from ww w . j ava2 s. c o m*/ // Need to add a case for 'adv_bases' switch (cacheName) { case Constants.ACCOUNTS: key = gson.fromJson(Strings.nullToEmpty(json).trim(), Account.Id.class); break; case Constants.GROUPS: key = gson.fromJson(Strings.nullToEmpty(json).trim(), AccountGroup.Id.class); break; case Constants.GROUPS_BYINCLUDE: case Constants.GROUPS_MEMBERS: key = gson.fromJson(Strings.nullToEmpty(json).trim(), AccountGroup.UUID.class); break; case Constants.PROJECT_LIST: key = gson.fromJson(Strings.nullToEmpty(json), Object.class); break; default: try { key = gson.fromJson(Strings.nullToEmpty(json).trim(), String.class); } catch (Exception e) { key = gson.fromJson(Strings.nullToEmpty(json), Object.class); } } return key; }
From source file:org.graylog2.rest.models.alarmcallbacks.AlarmCallbackError.java
@JsonCreator public static AlarmCallbackError create(@JsonProperty("error") String error) { return new AutoValue_AlarmCallbackError(Strings.nullToEmpty(error)); }
From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.Parent.java
/** * The method that does create a new parent * @param id carries the system object's identifier * @param name is the related object's name * @param type is the related object's type * @param current indicates whether the parent is the current version * @return the matching parent//from www . j a va 2 s.c om */ public static Parent create(String id, String name, String type, boolean current) { return new Parent(Preconditions.checkNotNull(id, "null id supplied"), Strings.nullToEmpty(name), Preconditions.checkNotNull(type, "null type supplied"), current); }
From source file:io.macgyver.test.RequestUtil.java
public static Map<String, String> parseFormBody(String body, String encoding) { try {//from ww w .j a va2 s. co m Map<String, String> m = Maps.newHashMap(); for (String kv : Splitter.on("&").omitEmptyStrings().split(Strings.nullToEmpty(body))) { List<String> kvList = Splitter.on("=").omitEmptyStrings().splitToList(kv); if (kvList.size() == 2) { m.put(URLDecoder.decode(kvList.get(0), encoding), URLDecoder.decode(kvList.get(1), encoding)); } } return m; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:com.indeed.imhotep.sql.parser.PeriodParser.java
/** * Returns a JodaTime Period object representing the provided string period value. * Only first symbol of each field tag is mandatory, the rest of the tag is optional. e.g. 1d = 1 day * Spacing between the numbers and tags is optional. e.g. 1d = 1 d * Having a tag with no number implies quantity of 1. e.g. d = 1d * 'ago' suffix is optional.// ww w . ja v a 2s . co m * Commas can optionally separate the period parts. */ @Nullable public static Period parseString(String value) { final String cleanedValue = Strings.nullToEmpty(value).toLowerCase(); Matcher matcher = relativeDatePattern.matcher(cleanedValue); if (!matcher.matches()) { return null; } int years = getValueFromMatch(matcher, 1); int months = getValueFromMatch(matcher, 2); int weeks = getValueFromMatch(matcher, 3); int days = getValueFromMatch(matcher, 4); int hours = getValueFromMatch(matcher, 5); int minutes = getValueFromMatch(matcher, 6); int seconds = getValueFromMatch(matcher, 7); return new Period(years, months, weeks, days, hours, minutes, seconds, 0); }
From source file:com.ericsson.gerrit.plugins.evictcache.GsonParser.java
static Object fromJson(String cacheName, String json) { Gson gson = new GsonBuilder().create(); Object key;/*from w ww . j a v a2 s. c o m*/ // Need to add a case for 'adv_bases' switch (cacheName) { case ACCOUNTS: key = gson.fromJson(Strings.nullToEmpty(json).trim(), Account.Id.class); break; case GROUPS: key = gson.fromJson(Strings.nullToEmpty(json).trim(), AccountGroup.Id.class); break; case GROUPS_BYINCLUDE: case GROUPS_MEMBERS: key = gson.fromJson(Strings.nullToEmpty(json).trim(), AccountGroup.UUID.class); break; case PROJECT_LIST: key = gson.fromJson(Strings.nullToEmpty(json), Object.class); break; default: key = gson.fromJson(Strings.nullToEmpty(json).trim(), String.class); } return key; }
From source file:com.attribyte.relay.HTMLUtil.java
/** * Extracts links for external citations and images. * @param entry The entry.//from w w w . ja va 2 s.c om * @param baseURI The URI used to resolve relative links. */ public static void extractLinks(final ClientProtos.WireMessage.Entry.Builder entry, final String baseURI) { Document doc = Jsoup.parse(entry.getContent(), baseURI); Elements links = doc.select("a[href]"); for (Element link : links) { String href = Strings.nullToEmpty(link.attr("href")).trim(); if (!href.isEmpty()) { entry.addCitationsBuilder().setDirection(ClientProtos.WireMessage.Citation.Direction.OUT) .setLink(href); } } Set<String> imageSources = Sets.newHashSetWithExpectedSize(8); //Don't replace/duplicate any previously added images... if (entry.hasPrimaryImage()) { imageSources.add(entry.getPrimaryImage().getOriginalSrc()); } if (entry.getImagesCount() > 0) { entry.getImagesList().stream().forEach(image -> imageSources.add(image.getOriginalSrc())); } Elements images = doc.select("img[src]"); for (Element image : images) { String src = Strings.nullToEmpty(image.attr("src")).trim(); if (!src.isEmpty() && !imageSources.contains(src)) { imageSources.add(src); ClientProtos.WireMessage.Image.Builder imageBuilder = entry.addImagesBuilder().setOriginalSrc(src); String alt = Strings.nullToEmpty(image.attr("alt")).trim(); if (!alt.isEmpty()) { imageBuilder.setAltText(alt); } String title = Strings.nullToEmpty(image.attr("title")).trim(); if (!title.isEmpty()) { imageBuilder.setTitle(title); } imageBuilder.setSize("original"); String heightStr = Strings.nullToEmpty(image.attr("height")).trim(); String widthStr = Strings.nullToEmpty(image.attr("width")).trim(); if (!heightStr.isEmpty() && !widthStr.isEmpty()) { Integer height = Ints.tryParse(heightStr); Integer width = Ints.tryParse(widthStr); if (height != null && width != null) { imageBuilder.setHeight(height).setWidth(width); } } } } if (!entry.hasPrimaryImage() && entry.getImagesCount() > 0) { //Set the primary image as the first image. entry.setPrimaryImage(entry.getImages(0)); } }
From source file:com.kegare.frozenland.util.Version.java
private static void initialize() { CURRENT = Optional.of(Strings.nullToEmpty(Frozenland.metadata.version)); LATEST = Optional.fromNullable(CURRENT.orNull()); File file = FrozenUtils.getModContainer().getSource(); if (file != null && file.exists()) { if (file.isFile()) { String name = FilenameUtils.getBaseName(file.getName()); if (StringUtils.endsWithIgnoreCase(name, "dev")) { DEV_DEBUG = true;/*from w w w. j av a 2s. com*/ } } else if (file.isDirectory()) { DEV_DEBUG = true; } } else if (!FMLForgePlugin.RUNTIME_DEOBF) { DEV_DEBUG = true; } if (Frozenland.metadata.version.endsWith("dev")) { DEV_DEBUG = true; } else if (DEV_DEBUG) { Frozenland.metadata.version += "-dev"; } }
From source file:org.sonar.scanner.util.ScannerUtils.java
public static String encodeForUrl(@Nullable String url) { try {//from w w w . j a va 2 s .c om return URLEncoder.encode(Strings.nullToEmpty(url), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Encoding not supported", e); } }
From source file:ec.tss.tsproviders.utils.ParamBean.java
@Nonnull public static ImmutableSortedMap<String, String> toSortedMap(@Nullable ParamBean[] params) { if (params == null || params.length == 0) { return ImmutableSortedMap.of(); }/*from www . j a v a 2s . co m*/ ImmutableSortedMap.Builder<String, String> b = ImmutableSortedMap.naturalOrder(); for (ParamBean o : params) { b.put(Strings.nullToEmpty(o.key), Strings.nullToEmpty(o.value)); } return b.build(); }