org.apache.commons.collections.Transformer.transform()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(110)

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

Transformer.transform介绍

[英]Transforms the input object (leaving it unchanged) into some output object.
[中]将输入对象(保持不变)转换为某个输出对象。

代码示例

代码示例来源:origin: commons-collections/commons-collections

/**
 * Transforms the input to result via each decorated transformer
 * 
 * @param object  the input object passed to the first transformer
 * @return the transformed result
 */
public Object transform(Object object) {
  for (int i = 0; i < iTransformers.length; i++) {
    object = iTransformers[i].transform(object);
  }
  return object;
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Transforms an object.
 * <p>
 * The transformer itself may throw an exception if necessary.
 * 
 * @param object  the object to transform
 * @return a transformed object
 */
protected Object transform(Object object) {
  return transformer.transform(object);
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Override to transform the value when using <code>setValue</code>.
 * 
 * @param value  the value to transform
 * @return the transformed value
 * @since Commons Collections 3.1
 */
protected Object checkSetValue(Object value) {
  return valueTransformer.transform(value);
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Executes the closure by calling the decorated transformer.
 * 
 * @param input  the input object
 */
public void execute(Object input) {
  iTransformer.transform(input);
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Transforms a key.
 * <p>
 * The transformer itself may throw an exception if necessary.
 * 
 * @param object  the object to transform
 * @throws the transformed object
 */
protected Object transformKey(Object object) {
  if (keyTransformer == null) {
    return object;
  }
  return keyTransformer.transform(object);
}

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

/**
 * Transforms the input to result via each decorated transformer
 * 
 * @param object  the input object passed to the first transformer
 * @return the transformed result
 */
public Object transform(Object object) {
  for (int i = 0; i < iTransformers.length; i++) {
    object = iTransformers[i].transform(object);
  }
  return object;
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Returns the result of comparing the values from the transform operation.
 * 
 * @param obj1  the first object to transform then compare
 * @param obj2  the second object to transform then compare
 * @return negative if obj1 is less, positive if greater, zero if equal
 */
public int compare(Object obj1, Object obj2) {
  Object value1 = this.transformer.transform(obj1);
  Object value2 = this.transformer.transform(obj2);
  return this.decorated.compare(value1, value2);
}

代码示例来源:origin: commons-collections/commons-collections

public Object get(Object key) {
  // create value for key if key is not currently in the map
  if (map.containsKey(key) == false) {
    if (value instanceof Transformer) {
      return ((Transformer) value).transform(key);
    }
    return value;
  }
  return map.get(key);
}

代码示例来源:origin: commons-collections/commons-collections

public Object get(Object key) {
  // create value for key if key is not currently in the map
  if (map.containsKey(key) == false) {
    Object value = factory.transform(key);
    map.put(key, value);
    return value;
  }
  return map.get(key);
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Evaluates the predicate returning the result of the decorated predicate
 * once the input has been transformed
 * 
 * @param object  the input object which will be transformed
 * @return true if decorated predicate returns true
 */
public boolean evaluate(Object object) {
  Object result = iTransformer.transform(object);
  return iPredicate.evaluate(result);
}

代码示例来源:origin: commons-collections/commons-collections

public void testMapTransformer() {
  Map map = new HashMap();
  map.put(null, new Integer(0));
  map.put(cObject, new Integer(1));
  map.put(cString, new Integer(2));
  assertEquals(new Integer(0), TransformerUtils.mapTransformer(map).transform(null));
  assertEquals(new Integer(1), TransformerUtils.mapTransformer(map).transform(cObject));
  assertEquals(new Integer(2), TransformerUtils.mapTransformer(map).transform(cString));
  assertEquals(null, TransformerUtils.mapTransformer(map).transform(cInteger));
  assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.mapTransformer(null));
}

代码示例来源:origin: commons-collections/commons-collections

public void testStringValueTransformer() {
  assertNotNull( "StringValueTransformer should NEVER return a null value.",
    TransformerUtils.stringValueTransformer().transform(null));
  assertEquals( "StringValueTransformer should return \"null\" when given a null argument.", "null",
    TransformerUtils.stringValueTransformer().transform(null));
  assertEquals( "StringValueTransformer should return toString value", "6",
    TransformerUtils.stringValueTransformer().transform(new Integer(6)));
}

代码示例来源:origin: commons-collections/commons-collections

public void testCloneTransformer() {
  assertEquals(null, TransformerUtils.cloneTransformer().transform(null));
  assertEquals(cString, TransformerUtils.cloneTransformer().transform(cString));
  assertEquals(cInteger, TransformerUtils.cloneTransformer().transform(cInteger));
  try {
    assertEquals(cObject, TransformerUtils.cloneTransformer().transform(cObject));
  } catch (IllegalArgumentException ex) {
    return;
  }
  fail();
}

代码示例来源:origin: commons-collections/commons-collections

public void testConstantTransformer() {
  assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(null));
  assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cObject));
  assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cString));
  assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cInteger));
  assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.constantTransformer(null));
}

代码示例来源:origin: commons-collections/commons-collections

public void testNullTransformer() {
  assertNotNull(TransformerUtils.nullTransformer());
  assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer());
  assertEquals(null, TransformerUtils.nullTransformer().transform(null));
  assertEquals(null, TransformerUtils.nullTransformer().transform(cObject));
  assertEquals(null, TransformerUtils.nullTransformer().transform(cString));
  assertEquals(null, TransformerUtils.nullTransformer().transform(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testNopTransformer() {
  assertNotNull(TransformerUtils.nullTransformer());
  assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer());
  assertEquals(null, TransformerUtils.nopTransformer().transform(null));
  assertEquals(cObject, TransformerUtils.nopTransformer().transform(cObject));
  assertEquals(cString, TransformerUtils.nopTransformer().transform(cString));
  assertEquals(cInteger, TransformerUtils.nopTransformer().transform(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testExecutorTransformer() {
  assertEquals(null, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(null));
  assertEquals(cObject, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cObject));
  assertEquals(cString, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cString));
  assertEquals(cInteger, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cInteger));
  try {
    TransformerUtils.asTransformer((Closure) null);
  } catch (IllegalArgumentException ex) {
    return;
  }
  fail();
}

代码示例来源:origin: commons-collections/commons-collections

public void testPredicateTransformer() {
  assertEquals(Boolean.TRUE, TransformerUtils.asTransformer(PredicateUtils.truePredicate()).transform(null));
  assertEquals(Boolean.TRUE, TransformerUtils.asTransformer(PredicateUtils.truePredicate()).transform(cObject));
  assertEquals(Boolean.TRUE, TransformerUtils.asTransformer(PredicateUtils.truePredicate()).transform(cString));
  assertEquals(Boolean.TRUE, TransformerUtils.asTransformer(PredicateUtils.truePredicate()).transform(cInteger));
  try {
    TransformerUtils.asTransformer((Predicate) null);
  } catch (IllegalArgumentException ex) {
    return;
  }
  fail();
}

代码示例来源:origin: commons-collections/commons-collections

public void testFactoryTransformer() {
  assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(null));
  assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cObject));
  assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cString));
  assertEquals(null, TransformerUtils.asTransformer(FactoryUtils.nullFactory()).transform(cInteger));
  try {
    TransformerUtils.asTransformer((Factory) null);
  } catch (IllegalArgumentException ex) {
    return;
  }
  fail();
}

代码示例来源:origin: commons-collections/commons-collections

public void testExceptionTransformer() {
  assertNotNull(TransformerUtils.exceptionTransformer());
  assertSame(TransformerUtils.exceptionTransformer(), TransformerUtils.exceptionTransformer());
  try {
    TransformerUtils.exceptionTransformer().transform(null);
  } catch (FunctorException ex) {
    try {
      TransformerUtils.exceptionTransformer().transform(cString);
    } catch (FunctorException ex2) {
      return;
    }
  }
  fail();
}

相关文章

Transformer类方法