org.ff4j.utils.Util.hasLength()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.ff4j.utils.Util.hasLength()方法的一些代码示例,展示了Util.hasLength()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.hasLength()方法的具体详情如下:
包路径:org.ff4j.utils.Util
类名称:Util
方法名:hasLength

Util.hasLength介绍

[英]Check that expression is true.
[中]检查表达式是否正确。

代码示例

代码示例来源:origin: ff4j/ff4j

/**
 * Check parameter for date.
 *
 * @param req
 *      current http request.
 * @param param
 *      parameter name
 * @return
 *      if the param exist and is not null
 */
protected boolean isValidParam(HttpServletRequest req, String param) {
  String pValue = req.getParameter(param);
  return (Util.hasLength(pValue) && !"null".equals(pValue));
}

代码示例来源:origin: ff4j/ff4j

public boolean matchHost(String host) {
  return (hostFilters.isEmpty()) || (Util.hasLength(host) && hostFilters.contains(host));
}

代码示例来源:origin: ff4j/ff4j

public boolean matchAction(String action) {
  return (actionFilters.isEmpty()) || (Util.hasLength(action) && actionFilters.contains(action));
}

代码示例来源:origin: ff4j/ff4j

public boolean matchSource(String source) {
  return (sourceFilters.isEmpty()) || (Util.hasLength(source) && sourceFilters.contains(source));
}

代码示例来源:origin: ff4j/ff4j

public boolean matchName(String name) {
  return (namesFilter.isEmpty()) || (Util.hasLength(name) && namesFilter.contains(name));
}

代码示例来源:origin: ff4j/ff4j

/**
 * Create Flipping Strategy from parameters.
 *
 * @param req
 *            current http query
 * @param uid
 *      unique feature identifier
 * @return instance of strategy
 */
private FlippingStrategy buildFlippingStrategy(HttpServletRequest req, String uid) {
  String strategy = req.getParameter(STRATEGY);
  String strategyParams = req.getParameter(STRATEGY_INIT);
  FlippingStrategy fstrategy = null;
  Map<String, String> initParams = new HashMap<String, String>();
  if (Util.hasLength(strategy)) {
    if (Util.hasLength(strategyParams)) {
      String[] params = strategyParams.split(";");
      for (String currentP : params) {
        String[] cur = currentP.split("=");
        String value = (cur.length < 2) ? "" : cur[1];
        initParams.put(cur[0], value);
      }
    }
    fstrategy = MappingUtil.instanceFlippingStrategy(uid, strategy, initParams);
  }
  return fstrategy;
}

代码示例来源:origin: ff4j/ff4j

/**
 * Put authentication header if relevant.
 *
 * @param webTarget
 * @param auth
 * @return
 */
public static Invocation.Builder createRequest(WebTarget webTarget, String auth, MediaType mediaType) {
  Util.assertNotNull(webTarget);
  Invocation.Builder invocationBuilder = null;
  if (mediaType != null) {
    invocationBuilder = webTarget.request();
  } else {
    invocationBuilder = webTarget.request(mediaType);
  }
  if (Util.hasLength(auth)) {
    invocationBuilder.header(HEADER_AUTHORIZATION, auth);
  }
  return invocationBuilder;
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public Map<String, MutableHitCount> getUserHitCount(EventQueryDefinition query) {
  Map<String, MutableHitCount> hitRatio = new TreeMap<String, MutableHitCount>();
  for (Event event : searchFeatureUsageEvents(query)) {
    String user = Util.hasLength(event.getUser()) ? event.getUser() : "anonymous";
    if (!hitRatio.containsKey(user)) {
      hitRatio.put(user, new MutableHitCount());
     }
     hitRatio.get(user).inc();
  }
  return hitRatio;
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public Set<String> readAllGroups() {
  Set<String> setOFGroup = new HashSet<String>();
  Connection sqlConn = null;
  PreparedStatement ps = null;
  ResultSet rs = null;
  try {
    // Returns features
    sqlConn = dataSource.getConnection();
    ps = sqlConn.prepareStatement(getQueryBuilder().getAllGroups());
    rs = ps.executeQuery();
    while (rs.next()) {
      String groupName = rs.getString(COL_FEAT_GROUPNAME);
      if (Util.hasLength(groupName)) {
        setOFGroup.add(groupName);
      }
    }
    return setOFGroup;
  } catch (SQLException sqlEX) {
    throw new FeatureAccessException("Cannot list groups, error related to database", sqlEX);
  } finally {
    closeResultSet(rs);
    closeStatement(ps);
    closeConnection(sqlConn);
  }
}

代码示例来源:origin: ff4j/ff4j

/**
 * Initialize Audit Bucket. If Features and properties have the same name, need to check.
 */

public void initAuditBucket() {
  if (ff4jAuditBucket == null) {
    if (Util.hasLength(ff4jAuditBucketPassword)) {
      ff4jAuditBucket = getCluster().openBucket(ff4jAuditBucketName, ff4jAuditBucketPassword);
    } else {
      ff4jAuditBucket = getCluster().openBucket(ff4jAuditBucketName);
    }
  }
}

代码示例来源:origin: ff4j/ff4j

/**
 * Initialize Property Bucket. If Features and properties have the same name, need to check.
 */
public void initPropertyBucket() {
  if (ff4jPropertyBucket == null) {
    if (Util.hasLength(ff4jPropertyBucketPassword)) {
      ff4jPropertyBucket = getCluster().openBucket(ff4jPropertyBucketName, ff4jPropertyBucketPassword);
    } else {
      ff4jPropertyBucket = getCluster().openBucket(ff4jPropertyBucketName);
    }
  }
}

代码示例来源:origin: ff4j/ff4j

/**
 * Initiliazing Buckets.
 */
public void initFeatureBuckets() {
  if (ff4jFeatureBucket == null) {
    if (Util.hasLength(ff4jFeatureBucketPassword)) {
      ff4jFeatureBucket = getCluster().openBucket(ff4jFeatureBucketName, ff4jFeatureBucketPassword);
    } else {
      ff4jFeatureBucket = getCluster().openBucket(ff4jFeatureBucketName);
    }
  }
}

代码示例来源:origin: ff4j/ff4j

/**
 * Create new property in store.
 *
 * @param ff4j
 *      current ff4j instance.
 * @param req
 *      current http request
 */
public static void createProperty(FF4j ff4j, HttpServletRequest req) {
  String name         = req.getParameter("name");
  String type         = req.getParameter("pType");
  String description  = req.getParameter("desc");
  String value        = req.getParameter("pValue");
  String featureId    = req.getParameter(WebConstants.FEATURE_UID);
  Property<?> ap = PropertyFactory.createProperty(name, type, value);
  ap.setDescription(description);
  
  if (Util.hasLength(featureId)) {
    Feature current = ff4j.getFeatureStore().read(featureId);
    current.addProperty(ap);
    ff4j.getFeatureStore().update(current);
  } else {
    ff4j.getPropertiesStore().createProperty(ap);
  }
}

代码示例来源:origin: ff4j/ff4j

if (!Util.hasLength(alterBean) && !Util.isValidClass(alterClazz) && !isFeatureToggled) {
  return null;
  if (Util.hasLength(alterBean)

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx)
throws IOException {
  String operation    = req.getParameter(WebConstants.OPERATION);
  String propertyName = req.getParameter(WebConstants.FEATID);
  String msgType = "success";
  String msg = null;
  if (Util.hasLength(operation) && Util.hasLength(propertyName) && 
      getFf4j().getPropertiesStore().existProperty(propertyName)) {
        if (OP_DELETE_FIXEDVALUE.equalsIgnoreCase(operation)) {
      String fixedValue = req.getParameter(PARAM_FIXEDVALUE);
      Property<?> ap = getFf4j().getPropertiesStore().readProperty(propertyName);
      // Need to convert back to object to use the remove()
      ap.getFixedValues().remove(ap.fromString(fixedValue));
      getFf4j().getPropertiesStore().updateProperty(ap);
      LOGGER.info("Property '" + propertyName + "' remove fixedValue '" + fixedValue + "'");
    }
    if (OP_ADD_FIXEDVALUE.equalsIgnoreCase(operation)) {
      String fixedValue = req.getParameter(PARAM_FIXEDVALUE);
      Property<?> ap = getFf4j().getPropertiesStore().readProperty(propertyName);
      ap.add2FixedValueFromString(fixedValue);
      getFf4j().getPropertiesStore().updateProperty(ap);
      LOGGER.info("Property '" + propertyName + "' add fixedValue '" + fixedValue + "'");
    }
  }
  ctx.setVariable("msgType", msgType);
  ctx.setVariable("msgInfo", msg);
  renderPage(ctx);
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx)
throws IOException {
  ctx.setVariable(KEY_TITLE, "Settings");
  String operation = req.getParameter(WebConstants.OPERATION);
  String msgType = "success";
  String msg = null;
  if (Util.hasLength(operation) && TOGGLE_AUDIT.equalsIgnoreCase(operation)) {
    if (getFf4j().isEnableAudit()) {
      getFf4j().audit(false);
      msg = "Audit is now DISABLED";
      LOGGER.info("Audit has been disabled");
    } else {
      getFf4j().audit(true);
      msg = "Audit is now ENABLED";
      LOGGER.info("Audit has been enabled");
    }
  }
  ctx.setVariable(KEY_AUDITENABLE, getFf4j().isEnableAudit());
  ctx.setVariable("msgType", msgType);
  ctx.setVariable("msgInfo", msg);
}

代码示例来源:origin: ff4j/ff4j

/**
 * Init Cassandra session from Cluster.s
 */
public void initSession() {
  if (null == cluster) {
    Builder builder = Cluster.builder().addContactPoint(hostName).withPort(port);
    if (Util.hasLength(userName)) {
      builder.withCredentials(userName, userPassword);
    }
    this.cluster = builder.build();
  }
  Metadata metadata = cluster.getMetadata();
  LOGGER.info("Connecting to cluster... '{}'",  metadata.getClusterName());
  for ( Host host : metadata.getAllHosts() ) {
    LOGGER.info("Datatacenter: '{}' Host: '{}' Rack '{}'", host.getDatacenter(), host.getAddress(), host.getRack());
  }
  this.session = cluster.connect();  
  LOGGER.info("Connection Successful.");
}

代码示例来源:origin: ff4j/ff4j

/**
 * Allow to update feature.
 *
 * @param featureId
 */
private void updateFeature(HttpServletRequest req, String featureId) {
  Feature old = ff4j.getFeatureStore().read(featureId);
  // Core
  Feature fp = new Feature(featureId, old.isEnable());
  fp.setPermissions(old.getPermissions());
  fp.setCustomProperties(old.getCustomProperties());
  fp.setFlippingStrategy(buildFlippingStrategy(req, fp.getUid()));
  
  // Description
  final String featureDesc = req.getParameter(DESCRIPTION);
  if (Util.hasLength(featureDesc)) {
    fp.setDescription(featureDesc);
  }
  // GroupName
  final String groupName = req.getParameter(GROUPNAME);
  if (Util.hasLength(groupName)) {
    fp.setGroup(groupName);
  }
  // Creation
  ff4j.getFeatureStore().update(fp);
}

代码示例来源:origin: ff4j/ff4j

if (Util.hasLength(jsonFlippingStrategy)) {
  f.setFlippingStrategy(FeatureJsonParser.parseFlipStrategyAsJson(f.getUid(), jsonFlippingStrategy));

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public <T> void createProperty(Property<T> value) {
  Util.assertNotNull(value);
  Util.hasLength(value.getName());
  if (existProperty(value.getName())) {
    throw new PropertyAlreadyExistException(value.getName());
  }
  conf().addProperty(value.getName(), value.asString());
}

相关文章