org.geotools.util.Converters.convert()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(164)

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

Converters.convert介绍

[英]Converts an object of a particular type into an object of a different type.

Convenience for #convert(Object,Class,Hints)
[中]将特定类型的对象转换为其他类型的对象。
方便#转换(对象、类、提示)

代码示例

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

/**
 * returns the value asociated with <code>key</code> on the set of key/value pairs of this
 * request reader
 *
 * @param key DOCUMENT ME!
 * @return DOCUMENT ME!
 */
protected String getValue(String key) {
  return Converters.convert(kvpPairs.get(key), String.class);
}

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

public <T> T get(String key, Class<T> clazz) {
  Object obj = get(key);
  if (obj == null) {
    return null;
  }
  return Converters.convert(obj, clazz);
}

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

/** Parses the string into a numberic value. */
  public Object parse(String value) throws Exception {
    return Converters.convert(value, getBinding());
  }
}

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

@SuppressWarnings("unchecked")
@Override
public <T> T get(Object object, String xpath, Class<T> target) throws IllegalArgumentException {
  Object value = getProperty(object, xpath);
  T result;
  if (null != target && null != value) {
    result = Converters.convert(value, target);
  } else {
    result = (T) value;
  }
  return result;
}

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

public void imprt(File dir) throws Exception {
  LegacyServicesReader reader = reader(dir);
  Map<String, Object> global = reader.global();
  configFileName = (String) global.get("log4jConfigFile");
  logFile = (String) global.get("logLocation");
  suppressStdOutLogging =
      Converters.convert(global.get("suppressStdOutLogging"), Boolean.class);
}

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

@Override
public <T> T evaluate(Object object, Class<T> context) {
  // Selection of the first expression
  Expression clazzExpression = parameters.get(0);
  // Getting the defined class
  Class clazz = clazzExpression.evaluate(object, Class.class);
  // Checking the result
  boolean result = false;
  // If the input class is Object, the function always returns true
  if (clazz != null) {
    if (clazz == Object.class) {
      result = true;
    } else {
      // Otherwise the function checks if the class is an instance of the
      // input class
      result = clazz.isAssignableFrom(object.getClass());
    }
  }
  // Finally the result is converted to the defined context class
  return Converters.convert(result, context);
}

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

protected void parseParameters() {
  if (myParameterMap != null) return;
  String contentType = myWrappedRequest.getContentType();
  if (myWrappedRequest.getMethod().equals("POST")
      && contentType != null
      && contentType.startsWith("application/x-www-form-urlencoded")) {
    parseFormBody();
  } else {
    myParameterMap = new HashMap(super.getParameterMap());
    for (Object key : myParameterMap.keySet()) {
      Object value = myParameterMap.get(key);
      if (value instanceof String[]) {
        myParameterMap.put(key, Arrays.asList(((String[]) value)));
      } else if (!(value instanceof List)) {
        myParameterMap.put(key, Converters.convert(value, List.class));
      }
    }
  }
}

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

public Collection<Object> convertDimensionValue(String name, String value) {
  List<Object> result = new ArrayList<Object>();
  try {
    String typeName = getDomainDatatype(name);
    if (typeName != null) {
      Class<?> type = Class.forName(typeName);
      if (type == java.util.Date.class) {
        result.addAll(new TimeParser().parse(value));
      } else if (Number.class.isAssignableFrom(type) && !value.contains(",")) {
        result.add(parseNumberOrRange(value));
      } else {
        for (String element : value.split(",")) {
          result.add(Converters.convert(element, type));
        }
      }
    } else {
      result.add(value);
    }
  } catch (Exception e) {
    LOGGER.log(Level.WARNING, "Failed to convert dimension value: ", e);
    result.add(value);
  }
  return result;
}

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

Object converted = Converters.convert(value, target);
if (converted != null) {
  value = converted;

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

value = params.get(key);
if (value != null) {
  Object converted = Converters.convert(value, target);
  if (converted == null) {
    throw new RuntimeException(

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

String complexTypeId = getComplexTypeId(value.getClass());
if (complexTypeId == null) {
  String str = Converters.convert(value, String.class);
  if (str == null) {
    str = value.toString();

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

public void modifyFeatures(AttributeDescriptor[] type, Object[] values, Filter filter)
    throws IOException {
  SimpleFeatureType original = typeMap.getOriginalFeatureType();
  // map back attribute types and values to the original values
  AttributeDescriptor[] originalTypes = new AttributeDescriptor[type.length];
  Object[] originalValues = new Object[values.length];
  for (int i = 0; i < values.length; i++) {
    originalTypes[i] = original.getDescriptor(type[i].getName());
    if (values[i] != null) {
      Class<?> target = originalTypes[i].getType().getBinding();
      originalValues[i] = Converters.convert(values[i], target);
      if (originalValues[i] == null)
        throw new IOException("Could not map back " + values[i] + " to type " + target);
    }
  }
  featureStore()
      .modifyFeatures(originalTypes, originalValues, store.retypeFilter(filter, typeMap));
}

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

type = geomType == null ? Geometry.class : geomType.getBinding();
} else if (reader.getNodeName().equals("srid")) {
  srid = Converters.convert(reader.getValue(), Integer.class);

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

final List<?> value = extractValue(p);
for (Object o : value) {
  final String s = Converters.convert(o, String.class);
  for (String filename : this.dataDirectory.list()) {
    if (isDataFile(filename)) {

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

/**
   * Default implementation delegates handling of context conversion to Converters utility class.
   *
   * <p>Subclasses are expected to make use of the {@linkplain Converters} utility class (as the
   * easiest way to provide value morphing in conformance with the Filter specification).
   */
  public <T> T evaluate(Object object, Class<T> context) {
    return Converters.convert(evaluate(object), context);
  }
}

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

public Object convert(Object source, Class target) throws Exception {
    if (source instanceof GeometryAttribute) {
      return Converters.convert(((GeometryAttribute) source).getValue(), target);
    }
    return null;
  }
};

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

public Object convert(Object source, Class target) {
    if (source instanceof Attribute) {
      // get the attribute value
      Attribute attribute = (Attribute) source;
      Object value = attribute.getValue();
      // let the available converters do their job
      return Converters.convert(value, target);
    }
    // this should not happen, anyway we can only handle attributes
    return null;
  }
};

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

public ColorMapEntryBuilder colorHex(String hex) {
  Color color = Converters.convert(hex, Color.class);
  if (color == null) {
    throw new IllegalArgumentException(
        "The provided expression could not be turned into a color: " + hex);
  }
  return color(color);
}

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

public FillBuilder colorHex(String hex) {
  Color color = Converters.convert(hex, Color.class);
  if (color == null) {
    throw new IllegalArgumentException(
        "The provided expression could not be turned into a color: " + hex);
  }
  return color(color);
}

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

public boolean evaluate(Object feature) {
  Geometry other = Converters.convert(property.evaluate(feature), Geometry.class);
  if (other == null) return false;
  return get3DEnvelope(other).intersects(envelope);
}

相关文章