org.ff4j.core.Feature.setFlippingStrategy()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(141)

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

Feature.setFlippingStrategy介绍

[英]Setter accessor for attribute 'flippingStrategy'.
[中]属性“flippingStrategy”的Setter访问器。

代码示例

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

private static void updateFlippingStrategy(Feature fp, String strategy, String strategyParams) {
  
  if (null != strategy && !strategy.isEmpty()) {
    try {
      Class<?> strategyClass = Class.forName(strategy);
      FlippingStrategy fstrategy = (FlippingStrategy) strategyClass.newInstance();
            if (null != strategyParams && !strategyParams.isEmpty()) {
        Map<String, String> initParams = new HashMap<String, String>();
        String[] params = strategyParams.split(";");
        for (String currentP : params) {
          String[] cur = currentP.split("=");
          if (cur.length < 2) {
            throw new IllegalArgumentException("Invalid Syntax : param1=val1,val2;param2=val3,val4");
          }
          initParams.put(cur[0], cur[1]);
        }
        fstrategy.init(fp.getUid(), initParams);
      }
      fp.setFlippingStrategy(fstrategy);
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException("Cannot find strategy class", e);
    } catch (InstantiationException e) {
      throw new IllegalArgumentException("Cannot instantiate strategy", e);
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException("Cannot instantiate : no public constructor", e);
    }
  }
}

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

/** {@inheritDoc} */
@Override
public Feature mapRow(ResultSet rs, int rowNum) throws SQLException {
  String featUid = rs.getString(COL_FEAT_UID);
  
  Feature f = new Feature(featUid, rs.getInt(COL_FEAT_ENABLE) > 0);
  f.setDescription(rs.getString(COL_FEAT_DESCRIPTION));
  f.setGroup(rs.getString(COL_FEAT_GROUPNAME));
  // Build Flipping Strategy From DataBase
  String strategy = rs.getString(COL_FEAT_STRATEGY);
  if (strategy != null && !"".equals(strategy)) {
    Map < String, String > initParams = MappingUtil.toMap(rs.getString(COL_FEAT_EXPRESSION));
    FlippingStrategy flipStrategy = MappingUtil.instanceFlippingStrategy(featUid, strategy, initParams);
    f.setFlippingStrategy(flipStrategy);
  }
  return f;
  
 
}

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

/**
 * Map feature result to bean.
 * 
 * @param rs
 *            current resultSet
 * @return current Feature without roles
 * @throws SQLException
 *             error accured when parsing resultSet
 */
public Feature mapFeature(ResultSet rs) throws SQLException {
  // Feature
  Feature f;
  boolean enabled = rs.getInt(COL_FEAT_ENABLE) > 0;
  String featUid = rs.getString(COL_FEAT_UID);
  f = new Feature(featUid, enabled, rs.getString(COL_FEAT_DESCRIPTION), rs.getString(COL_FEAT_GROUPNAME));
  // Strategy
  String strategy = rs.getString(COL_FEAT_STRATEGY);
  if (strategy != null && !"".equals(strategy)) {
    Map < String, String > initParams = toMap(rs.getString(COL_FEAT_EXPRESSION));
    f.setFlippingStrategy(instanceFlippingStrategy(featUid, strategy, initParams));
  }
  return f;
}

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

f.setFlippingStrategy(parseFlipStrategy((Element) flipStrategies.item(0), f.getUid()));

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

fp.setFlippingStrategy(fstrategy);

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

@SuppressWarnings("unchecked")
private static Feature parseFeatureMap(Map<String, Object> fMap) {
  Feature f = new Feature((String) fMap.get("uid"));
  f.setEnable((Boolean) fMap.get("enable"));
  f.setDescription((String) fMap.get("description"));
  f.setGroup((String) fMap.get("group"));
  // permissions
  List<String> perm = (ArrayList<String>) fMap.get("permissions");
  f.setPermissions(new HashSet<String>());
  if (perm != null) {
    f.getPermissions().addAll(perm);
  }
  // flipping strategy
  f.setFlippingStrategy(parseFlipStrategy(f.getUid(), (LinkedHashMap<String, Object>) fMap.get("flippingStrategy")));
  // custom properties
  Map <String, Object > propertyMap = (Map < String, Object >) fMap.get("customProperties");
  f.setCustomProperties(parseCustomProperties(propertyMap));
  return f;
}

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

Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_ROLES))));
fout.setFlippingStrategy(FeatureJsonParser.parseFlipStrategyAsJson(uid,
    Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_STRATEGY))));

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

Map<String, String> initParams = (Map<String, String>) flippingStrategyParameters.get("initParams");
feature.setFlippingStrategy(MappingUtil.instanceFlippingStrategy(uid, flippingStrategyType, initParams));

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

try {
  Map<String, String> initparams = flipApiBean.getInitParams();
  feat.setFlippingStrategy(MappingUtil.instanceFlippingStrategy(id, flipApiBean.getType(), initparams));
} catch (Exception e) {
  String errMsg = "Cannot read Flipping Strategy, does not seems to have a DEFAULT constructor, " + e.getMessage();

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

case FF4J_FLIPPING_STRATEGY:
  FlippingStrategy fs = fromNode2FlippingStrategy(targetFeature.getUid(), nodeOther);
  targetFeature.setFlippingStrategy(fs);
break;
case FF4J_FEATURE_PROPERTY:

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

private void initFlippingStrategy(FeatureApiBean featureApiBean, Feature feature) {
  FlippingStrategyApiBean flipApiBean = featureApiBean.getFlippingStrategy();
  if (null != flipApiBean) {
    try {
      Map<String, String> initParams = flipApiBean.getInitParams();
      feature.setFlippingStrategy(MappingUtil.instanceFlippingStrategy(featureApiBean.getUid(), flipApiBean.getType(), initParams));
    } catch (FeatureAccessException exception) {
      throw new FlippingStrategyBadRequestException(exception);
    }
  }
}

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

/**
 * TDD.
 */
@Test
public void testUpdateRemoveFlippingStrategy() {
  // Given
  assertFf4j.assertThatFeatureExist(F3);
  Feature myFeature = ff4j.getFeatureStore().read(F3);
  myFeature.setFlippingStrategy(new PonderationStrategy(0.1));
  testedStore.update(myFeature);
  assertFf4j.assertThatFeatureHasFlippingStrategy(F3);
  // When
  Feature myFeature2 = ff4j.getFeatureStore().read(F3);
  myFeature2.setFlippingStrategy(null);
  testedStore.update(myFeature2);
  // Then
  assertFf4j.assertThatFeatureDoesNotHaveFlippingStrategy(F3);
}

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

/**
 * TDD.
 */
@Test
public void testUpdateEditFlippingStrategy() {
  // Given
  assertFf4j.assertThatFeatureExist(F3);
  // When
  Feature myFeature = ff4j.getFeatureStore().read(F3);
  myFeature.setFlippingStrategy(new PonderationStrategy(0.1));
  testedStore.update(myFeature);
  // Then
  assertFf4j.assertThatFeatureHasFlippingStrategy(F3);
}

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

/**
 * TDD.
 */
@Test
public void testUpdateFeatureCoreData() {
  // Parameters
  String newDescription = "new-description";
  FlippingStrategy newStrategy = new PonderationStrategy(0.12);
  // Given
  assertFf4j.assertThatFeatureExist(F1);
  Assert.assertFalse(newDescription.equals(testedStore.read(F1).getDescription()));
  // When
  Feature fpBis = testedStore.read(F1);
  fpBis.setDescription(newDescription);
  fpBis.setFlippingStrategy(newStrategy);
  testedStore.update(fpBis);
  // Then
  Feature updatedFeature = testedStore.read(F1);
  Assert.assertTrue(newDescription.equals(updatedFeature.getDescription()));
  Assert.assertNotNull(updatedFeature.getFlippingStrategy());
  Assert.assertEquals(newStrategy.toString(), updatedFeature.getFlippingStrategy().toString());
}

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

f.setFlippingStrategy(FeatureJsonParser.parseFlipStrategyAsJson(f.getUid(), jsonFlippingStrategy));

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

/**
 * TDD.
 */
@Test
public void testUpdateAddFlippingStrategy() {
  // Given
  assertFf4j.assertThatFeatureExist(F2);
  assertFf4j.assertThatFeatureDoesNotHaveFlippingStrategy(F2);
  // When
  Feature myFeature = ff4j.getFeatureStore().read(F2);
  myFeature.setFlippingStrategy(new PonderationStrategy(0.1));
  testedStore.update(myFeature);
  // Then
  assertFf4j.assertThatFeatureHasFlippingStrategy(F2);
}

代码示例来源: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

/** {@inheritDoc} */
@Override
public Feature fromStore(Document document) {
  String featUid = document.getString(FEATURE_UUID);
  boolean status = document.getBoolean(FEATURE_ENABLE);
  Feature f = new Feature(featUid, status);
  f.setDescription(document.getString(FEATURE_DESCRIPTION));
  f.setGroup(document.getString(FEATURE_GROUPNAME));
  f.setPermissions(mapAuthorization(document));
  f.setFlippingStrategy(mapStrategy(featUid, document));
  f.setCustomProperties(mapCustomProperties(document));
  return f;
}

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

/**
 * Convert {@link DBObject} to {@link Feature}.
 * 
 * @param dbObject
 *            document in mongodb.
 * @return
 */
public Feature mapFeature(DBObject dbObject) {
  String featUid = (String) dbObject.get(UUID);
  boolean status = (Boolean) dbObject.get(ENABLE);
  Feature f = new Feature(featUid, status);
  f.setDescription((String) dbObject.get(DESCRIPTION));
  f.setGroup((String) dbObject.get(GROUPNAME));
  f.setPermissions(mapAuthorization(dbObject));
  f.setFlippingStrategy(mapStrategy(featUid, dbObject));
  f.setCustomProperties(mapCustomProperties(dbObject));
  return f;
}

相关文章