Example usage for com.google.common.base Strings emptyToNull

List of usage examples for com.google.common.base Strings emptyToNull

Introduction

In this page you can find the example usage for com.google.common.base Strings emptyToNull.

Prototype

@Nullable
public static String emptyToNull(@Nullable String string) 

Source Link

Document

Returns the given string if it is nonempty; null otherwise.

Usage

From source file:io.druid.query.groupby.epinephelinae.GroupByQueryEngineV2.java

public static Sequence<Row> process(final GroupByQuery query, final StorageAdapter storageAdapter,
        final StupidPool<ByteBuffer> intermediateResultsBufferPool, final GroupByQueryConfig config) {
    if (storageAdapter == null) {
        throw new ISE(
                "Null storage adapter found. Probably trying to issue a query against a segment being memory unmapped.");
    }/*from   w ww. java 2  s.  c o  m*/

    final List<Interval> intervals = query.getQuerySegmentSpec().getIntervals();
    if (intervals.size() != 1) {
        throw new IAE("Should only have one interval, got[%s]", intervals);
    }

    final Sequence<Cursor> cursors = storageAdapter.makeCursors(Filters.toFilter(query.getDimFilter()),
            intervals.get(0), query.getGranularity(), false);

    final Grouper.KeySerde<ByteBuffer> keySerde = new GroupByEngineKeySerde(query.getDimensions().size());
    final ResourceHolder<ByteBuffer> bufferHolder = intermediateResultsBufferPool.take();

    final String fudgeTimestampString = Strings
            .emptyToNull(query.getContextValue(GroupByStrategyV2.CTX_KEY_FUDGE_TIMESTAMP, ""));

    final DateTime fudgeTimestamp = fudgeTimestampString == null ? null
            : new DateTime(Long.parseLong(fudgeTimestampString));

    return Sequences
            .concat(new ResourceClosingSequence<>(Sequences.map(cursors, new Function<Cursor, Sequence<Row>>() {
                @Override
                public Sequence<Row> apply(final Cursor cursor) {
                    return new BaseSequence<>(new BaseSequence.IteratorMaker<Row, GroupByEngineIterator>() {
                        @Override
                        public GroupByEngineIterator make() {
                            return new GroupByEngineIterator(query, config, cursor, bufferHolder.get(),
                                    keySerde, fudgeTimestamp);
                        }

                        @Override
                        public void cleanup(GroupByEngineIterator iterFromMake) {
                            iterFromMake.close();
                        }
                    });
                }
            }), new Closeable() {
                @Override
                public void close() throws IOException {
                    CloseQuietly.close(bufferHolder);
                }
            }));
}

From source file:org.obm.sync.calendar.EventExtId.java

public EventExtId(String extId) {
    this.extId = Strings.emptyToNull(extId);
}

From source file:org.n52.shetland.ogc.wps.Format.java

public Format(String mimeType, String encoding, String schema) {
    this(Optional.ofNullable(Strings.emptyToNull(mimeType)), Optional.ofNullable(Strings.emptyToNull(encoding)),
            Optional.ofNullable(Strings.emptyToNull(schema)));
}

From source file:org.n52.janmayen.http.QueryBuilder.java

public QueryBuilder setListSeperator(String seperator) {
    this.listSeperator = Objects.requireNonNull(Strings.emptyToNull(seperator));
    return this;
}

From source file:com.facebook.tsdb.tsdash.server.TsdbServlet.java

@Override
public final void init(ServletConfig config) throws ServletException {
    String tsdashFile = config.getInitParameter("TSDASH_PROPERTIES_FILE");
    tsdashFile = Objects.firstNonNull(Strings.emptyToNull(tsdashFile), PROPERTIES_FILE);

    String log4jFile = config.getInitParameter("LOG4J_PROPERTIES_FILE");
    log4jFile = Objects.firstNonNull(Strings.emptyToNull(log4jFile), LOG4J_PROPERTIES_FILE);

    try {/*  w  w w  .  j  a v a2  s  .co  m*/
        PropertyConfigurator.configure(log4jFile);

        Properties tsdbConf = new Properties();
        tsdbConf.load(new FileInputStream(tsdashFile));

        HBaseConnection.configure(tsdbConf);

        URLPattern = tsdbConf.getProperty(URL_PATTERN_PARAM, DEFAULT_URL_PATTERN);
        logger.info("URL pattern: " + URLPattern);
        plotsDir = tsdbConf.getProperty(PLOTS_DIR_PARAM, DEFAULT_PLOTS_DIR);
        logger.info("Plots are being written to: " + plotsDir);

        serveImagesLocally = Boolean
                .parseBoolean(tsdbConf.getProperty(SERVE_IMAGES_LOCALLY_PARAM, DEFAULT_SERVE_IMAGES_LOCALLY));

        if (serveImagesLocally) {
            logger.info("Serving plot images locally.");
        }
    } catch (IOException e) {
        throw new ServletException("Unable to load TsDash properties file(s).", e);
    }
}

From source file:com.codeabovelab.dm.cluman.ds.nodes.DiscoveryNodeController.java

@Autowired
public DiscoveryNodeController(NodeStorage storage, @Value("${dm.nodesDiscovery.secret:}") String nodeSecret) {
    this.storage = storage;
    this.nodeSecret = Strings.emptyToNull(nodeSecret);
}

From source file:com.reprezen.swagedit.json.references.JsonReferenceFactory.java

/**
 * Returns a simple reference if the value node points to a definition inside the same document.
 * /*  w  ww. j  a  va  2 s .c o m*/
 * @param baseURI
 * @param value
 * @return reference
 */
public JsonReference createSimpleReference(URI baseURI, AbstractNode valueNode) {
    if (valueNode.isArray() || valueNode.isObject()) {
        return null;
    }

    final Object value = valueNode.asValue().getValue();
    if (!(value instanceof String)) {
        return null;
    }

    String stringValue = (String) value;
    if (Strings.emptyToNull(stringValue) == null || stringValue.startsWith("#") || stringValue.contains("/")) {
        return null;
    }

    final Model model = valueNode.getModel();
    if (model != null) {
        JsonPointer ptr = JsonPointer.compile("/definitions/" + value);
        AbstractNode target = model.find(ptr);
        if (target != null) {
            return new JsonReference.SimpleReference(baseURI, ptr, valueNode);
        }
    }

    return null;
}

From source file:fathom.rest.security.aop.ControllerInterceptor.java

protected Account checkRequireToken(Method method) {
    Account account = getAccount();/*from  w  w  w. j  a va  2  s. com*/

    RequireToken requireToken = ClassUtil.getAnnotation(method, RequireToken.class);
    if (requireToken != null) {

        String tokenName = requireToken.value();

        Context context = RouteDispatcher.getRouteContext();
        // extract the named token from a header or a query parameter
        String token = Strings.emptyToNull(context.getRequest().getHeader(tokenName));
        token = Optional.fromNullable(token).or(context.getParameter(tokenName).toString(""));

        if (Strings.isNullOrEmpty(token)) {
            throw new AuthorizationException("Missing '{}' token", tokenName);
        }

        if (account.isGuest()) {
            // authenticate by token
            TokenCredentials credentials = new TokenCredentials(token);
            account = securityManager.get().authenticate(credentials);
            if (account == null) {
                throw new AuthorizationException("Invalid '{}' value '{}'", tokenName, token);
            }
            context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account);
            log.debug("'{}' account authenticated by token '{}'", account.getUsername(), token);
        } else {
            // validate token
            account.checkToken(token);
        }
    }

    return account;
}

From source file:org.killbill.billing.plugin.dao.PluginDao.java

protected String getProperty(final String key, final Map additionalData) {
    return Strings.emptyToNull(additionalData == null || additionalData.get(key) == null ? null
            : String.valueOf(additionalData.get(key)));
}

From source file:org.n52.sos.util.Reference.java

public Reference setArcrole(String arcrole) {
    this.arcrole = Optional.fromNullable(Strings.emptyToNull(arcrole));
    return this;
}