Example usage for org.springframework.util StringUtils isEmpty

List of usage examples for org.springframework.util StringUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util StringUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable Object str) 

Source Link

Document

Check whether the given object (possibly a String ) is empty.

Usage

From source file:org.terasoluna.gfw.web.el.ObjectToMapConverter.java

/**
 * Convert the given map to the flatten map
 * @param prefix prefix of the key/*  ww w.ja  va  2  s . c  o  m*/
 * @param value map instance to convert
 * @return converted map. all keys are prefixed with the given key
 */
private Map<String, String> convert(String prefix, Map value) {
    Map<String, String> map = new LinkedHashMap<String, String>();
    for (Object entry : value.entrySet()) {
        Map.Entry e = (Map.Entry) entry;
        if (StringUtils.isEmpty(prefix)) {
            map.putAll(this.convert(e.getKey().toString(), e.getValue()));
        } else {
            map.putAll(this.convert(prefix + "[" + e.getKey() + "]", e.getValue()));
        }
    }
    return map;
}

From source file:net.opentsdb.contrib.tsquare.ExtendedTsdbMetricParser.java

private Aggregator determineAggregator(final String metricName, final String aggregatorName) {
    Aggregator agg;//from www  .j  av a 2s . co m

    if (StringUtils.isEmpty(aggregatorName) || AUTO_AGGREGATOR.equals(aggregatorName)) {
        agg = aggregatorFactory.getAggregatorForMetric(metricName);
        agg = (agg == null) ? defaultAggregator : agg;
    } else {
        agg = aggregatorFactory.getAggregatorByName(aggregatorName);
        Preconditions.checkState(agg != null, "Unknown aggregator: %s", aggregatorName);
    }

    return agg;
}

From source file:de.dlopes.stocks.facilitator.data.StockInfo.java

public void setKPI(StockKPI.TYPE type, BigDecimal value) throws IllegalArgumentException {

    boolean found = false;

    // guard: we can only accept non-null providers
    if (type == null) {
        throw new IllegalArgumentException("type must not be null");
    }//from  w  w w. j a v a 2s  . c o m

    // guard: we can only accept non-empty values       
    if (StringUtils.isEmpty(value)) {
        return;
    }

    // if the list of KPIs does not exist yet, then we have to create it in order to 
    // avoid a NPE in the next step
    if (kpis == null) {
        kpis = new ArrayList<StockKPI>();
    }

    // try to find an existing KPI entry in order to carry out an update 
    for (StockKPI tmp : kpis) {
        if (type.equals(tmp.getType())) {
            tmp.setValue(value);
            found = true;
            break; // leave the as we have updated the KPI already
        }
    }

    // Guard: if existing KPI was found, then skip further processing
    if (found) {
        return;
    }

    // create and add a new KPI entry
    StockKPI kpi = new StockKPI(type, value, this);
    kpis.add(kpi);

}

From source file:com.scf.core.EnvTest.java

public static List<Date> getSelectableDateTimeList() {
    String deliveryCycle = "7";

    if (StringUtils.isEmpty(deliveryCycle)) {
        throw new AppException(ExCode.SYS_002);
    }//from  w w  w  .  ja  v  a2s. c om

    Date curDate = DatetimeUtilies.currentDay();

    List<Date> selectableDateList = new ArrayList<Date>(Integer.valueOf(deliveryCycle));
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.setTime(curDate);

    int i = 0;
    String[] d = { "07", "16" };
    while (i < Integer.valueOf(deliveryCycle)) {
        tomorrow.add(Calendar.DATE, 1);
        for (String deliveryHour : d) {
            Calendar tomorrowDetail = Calendar.getInstance();
            tomorrowDetail.setTime(tomorrow.getTime());
            tomorrowDetail.set(Calendar.HOUR_OF_DAY, Integer.parseInt(deliveryHour));
            selectableDateList.add(tomorrowDetail.getTime());
        }
        i++;
    }

    return selectableDateList;
}

From source file:org.appverse.web.framework.backend.frontfacade.mvc.schema.services.presentation.SchemaGeneratorServiceImpl.java

@RequestMapping(value = "/entity/{entity}.schema.json", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<JsonSchema> generateSchemaByEntityName2(@PathVariable("entity") String entity) {
    JsonSchema schema = null;//from ww w. j a  v a  2 s  .  c om
    if (StringUtils.isEmpty(entity)) {
        throw new PresentationException("invalid content");
    }
    try {
        Class<?> clazz = Class.forName(entity);
        schema = entityConverter.convert(clazz, TypeDescriptor.valueOf(String.class),
                TypeDescriptor.valueOf(JsonSchema.class));

    } catch (ClassNotFoundException nsme) {
        throw new PresentationException("invalid class:" + entity, nsme);
    } catch (NullPointerException npe) {
        // workarround where entity have a setter without getter it fails to parse
        throw new PresentationException("entity have setter without getter", npe);
    }
    return ResponseEntity.ok().contentType(APPLICATION_SCHEMA_JSON).body(schema);
}

From source file:com.sastix.cms.server.services.cache.hazelcast.HazelcastCacheService.java

@Override
public CacheDTO getCachedResource(QueryCacheDTO queryCacheDTO) throws DataNotFound, CacheValidationException {
    LOG.info("HazelcastCacheService->getCachedResource ({})",
            queryCacheDTO != null ? queryCacheDTO.toString() : "null");
    nullValidationChecker(queryCacheDTO, QueryCacheDTO.class);
    String cacheKey = queryCacheDTO.getCacheKey();

    if (cacheKey == null) {
        throw new CacheValidationException("You cannot get a cache a resource with a null key");
    }/*from   www.  jav a 2s  .co  m*/

    String cacheRegion = queryCacheDTO.getCacheRegion();
    CacheDTO cacheDTO;
    if (!StringUtils.isEmpty(cacheRegion)) { // GET from cache region
        ConcurrentMap<String, CacheDTO> cMap = cm.getCache(cacheRegion);
        cacheDTO = cMap.get(cacheKey);
    } else {// GET from default cache
        cacheDTO = this.cache.get(cacheKey);
    }

    boolean hasExpired = cacheFileUtilsService.isExpiredCachedResource(cacheDTO);

    if (hasExpired) {
        // Delete from cache silently and return null
        RemoveCacheDTO removeCacheDTO = new RemoveCacheDTO();
        removeCacheDTO.setCacheKey(cacheKey);
        removeCacheDTO.setCacheRegion(cacheRegion);
        removeCachedResource(removeCacheDTO);
        cacheDTO = null;
    }

    if (cacheDTO == null) {
        throw new DataNotFound("A cached resource could not be found with the given key: " + cacheKey);
    }
    return cacheDTO;
}

From source file:burstcoin.jminer.core.network.Network.java

public void checkNetworkState() {
    String server = poolMining ? poolServer : soloServer;
    if (!StringUtils.isEmpty(server)) {
        NetworkRequestMiningInfoTask networkRequestMiningInfoTask = context
                .getBean(NetworkRequestMiningInfoTask.class);
        networkRequestMiningInfoTask.init(server, blockNumber, poolMining, connectionTimeout,
                defaultTargetDeadline, devPool);
        networkPool.execute(networkRequestMiningInfoTask);
    }/* w  w w .j  a v  a 2 s  . c  o  m*/
}

From source file:org.venice.piazza.servicecontroller.data.mongodb.accessors.MongoAccessor.java

@PostConstruct
private void initialize() {
    try {// w  ww.  jav a  2  s  .  com
        MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
        // Enable SSL if the `mongossl` Profile is enabled
        if (Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> env.equalsIgnoreCase("mongossl"))) {
            builder.sslEnabled(true);
            builder.sslInvalidHostNameAllowed(true);
        }
        // If a username and password are provided, then associate these credentials with the connection
        if ((!StringUtils.isEmpty(DATABASE_USERNAME)) && (!StringUtils.isEmpty(DATABASE_CREDENTIAL))) {
            mongoClient = new MongoClient(new ServerAddress(DATABASE_HOST, DATABASE_PORT),
                    Arrays.asList(MongoCredential.createCredential(DATABASE_USERNAME, DATABASE_NAME,
                            DATABASE_CREDENTIAL.toCharArray())),
                    builder.threadsAllowedToBlockForConnectionMultiplier(mongoThreadMultiplier).build());
        } else {
            mongoClient = new MongoClient(new ServerAddress(DATABASE_HOST, DATABASE_PORT),
                    builder.threadsAllowedToBlockForConnectionMultiplier(mongoThreadMultiplier).build());
        }

    } catch (Exception exception) {
        LOGGER.error(String.format("Error connecting to MongoDB Instance. %s", exception.getMessage()),
                exception);

    }
}

From source file:com.github.springfox.loader.SpringfoxLoaderConfig.java

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    if (!StringUtils.isEmpty(springfoxLoader.swaggerUiBasePath())) {
        registry.addRedirectViewController(resourcePath("/v2/api-docs"), "/v2/api-docs");
        registry.addRedirectViewController(resourcePath("/swagger-resources/configuration/ui"),
                "/swagger-resources/configuration/ui");
        registry.addRedirectViewController(resourcePath("/swagger-resources/configuration/security"),
                "/swagger-resources/configuration/security");
        registry.addRedirectViewController(resourcePath("/swagger-resources"), "/swagger-resources");
    }//from   www.j a  v a2  s  . co m
}

From source file:com.reactivetechnologies.platform.Configurator.java

/**
 * Jar module loader./*www.  j a va2 s . c  o m*/
 * @return
 */
@Bean
@Conditional(RestEnabledCondition.class)
public JarModuleLoader dllLoader() {
    try {
        if (StringUtils.isEmpty(dllRoot))
            throw new BeanCreationException("'restserver.jaxrs.extDir' path not found");
        File f = ResourceLoaderHelper.loadFromFileOrClassPath(dllRoot, false);
        return new JarModuleLoader(f);
    } catch (IOException e) {
        throw new BeanCreationException("'restserver.jaxrs.extDir' path not found", e);
    }
}