org.springframework.core.convert.converter.Converter类的使用及代码示例

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

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

Converter介绍

[英]A converter converts a source object of type S to a target of type T.

Implementations of this interface are thread-safe and can be shared.

Implementations may additionally implement ConditionalConverter.
[中]转换器将S类型的源对象转换为T类型的目标对象。
此接口的实现是线程安全的,可以共享。
实现还可以实现ConditionalConverter。

代码示例

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(member, "Member must not be null!");
  Assert.notNull(radius, "Radius must not be null!");
  GeoUnit geoUnit = JedisConverters.toGeoUnit(radius.getMetric());
  try {
    return JedisConverters.geoRadiusResponseToGeoResultsConverter(radius.getMetric())
        .convert(connection.getCluster().georadiusByMember(key, member, radius.getValue(), geoUnit));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(member1, "Member1 must not be null!");
  Assert.notNull(member2, "Member2 must not be null!");
  Assert.notNull(metric, "Metric must not be null!");
  GeoUnit geoUnit = JedisConverters.toGeoUnit(metric);
  try {
    return JedisConverters.distanceConverterForMetric(metric)
        .convert(connection.getCluster().geodist(key, member1, member2, geoUnit));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(member1, "Member1 must not be null!");
  Assert.notNull(member2, "Member2 must not be null!");
  try {
    return JedisConverters.distanceConverterForMetric(DistanceUnit.METERS)
        .convert(connection.getCluster().geodist(key, member1, member2));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-security

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Object> convert(Map<String, Object> claims) {
  Assert.notNull(claims, "claims cannot be null");
  Map<String, Object> mappedClaims = new HashMap<>(claims);
  for (Map.Entry<String, Converter<Object, ?>> entry : this.claimConverters.entrySet()) {
    String claimName = entry.getKey();
    Converter<Object, ?> converter = entry.getValue();
    if (converter != null) {
      Object claim = claims.get(claimName);
      Object mappedClaim = converter.convert(claim);
      mappedClaims.compute(claimName, (key, value) -> mappedClaim);
    }
  }
  Instant issuedAt = (Instant) mappedClaims.get(JwtClaimNames.IAT);
  Instant expiresAt = (Instant) mappedClaims.get(JwtClaimNames.EXP);
  if (issuedAt == null && expiresAt != null) {
    mappedClaims.put(JwtClaimNames.IAT, expiresAt.minusSeconds(1));
  }
  return mappedClaims;
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
    GeoRadiusCommandArgs args) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(member, "Member must not be null!");
  Assert.notNull(radius, "Radius must not be null!");
  Assert.notNull(args, "Args must not be null!");
  GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(radius.getMetric());
  GeoArgs geoArgs = LettuceConverters.toGeoArgs(args);
  Converter<List<GeoWithin<byte[]>>, GeoResults<GeoLocation<byte[]>>> geoResultsConverter = LettuceConverters
      .geoRadiusResponseToGeoResultsConverter(radius.getMetric());
  try {
    if (isPipelined()) {
      pipeline(connection.newLettuceResult(
          getAsyncConnection().georadiusbymember(key, member, radius.getValue(), geoUnit, geoArgs),
          geoResultsConverter));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newLettuceResult(
          getAsyncConnection().georadiusbymember(key, member, radius.getValue(), geoUnit, geoArgs),
          geoResultsConverter));
      return null;
    }
    return geoResultsConverter
        .convert(getConnection().georadiusbymember(key, member, radius.getValue(), geoUnit, geoArgs));
  } catch (Exception ex) {
    throw convertLettuceAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(member, "Member must not be null!");
  Assert.notNull(radius, "Radius must not be null!");
  GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(radius.getMetric());
  Converter<Set<byte[]>, GeoResults<GeoLocation<byte[]>>> converter = LettuceConverters
      .bytesSetToGeoResultsConverter();
  try {
    if (isPipelined()) {
      pipeline(connection.newLettuceResult(
          getAsyncConnection().georadiusbymember(key, member, radius.getValue(), geoUnit), converter));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newLettuceResult(
          getAsyncConnection().georadiusbymember(key, member, radius.getValue(), geoUnit), converter));
      return null;
    }
    return converter.convert(getConnection().georadiusbymember(key, member, radius.getValue(), geoUnit));
  } catch (Exception ex) {
    throw convertLettuceAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public List<ByteRecord> xRange(byte[] key, Range<String> range, Limit limit) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(range, "Range must not be null!");
  Assert.notNull(limit, "Limit must not be null!");
  io.lettuce.core.Range<String> lettuceRange = RangeConverter.toRange(range, Function.identity());
  io.lettuce.core.Limit lettuceLimit = LettuceConverters.toLimit(limit);
  try {
    if (isPipelined()) {
      pipeline(connection.newLettuceResult(getAsyncConnection().xrange(key, lettuceRange, lettuceLimit),
          StreamConverters.byteRecordListConverter()));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newLettuceResult(getAsyncConnection().xrange(key, lettuceRange, lettuceLimit),
          StreamConverters.byteRecordListConverter()));
      return null;
    }
    return StreamConverters.byteRecordListConverter()
        .convert(getConnection().xrange(key, lettuceRange, lettuceLimit));
  } catch (Exception ex) {
    throw convertLettuceAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Boolean setBit(byte[] key, long offset, boolean value) {
  Assert.notNull(key, "Key must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newLettuceResult(getAsyncConnection().setbit(key, offset, LettuceConverters.toInt(value)),
          LettuceConverters.longToBooleanConverter()));
      return null;
    }
    if (isQueueing()) {
      transaction(
          connection.newLettuceResult(getAsyncConnection().setbit(key, offset, LettuceConverters.toInt(value)),
              LettuceConverters.longToBooleanConverter()));
      return null;
    }
    return LettuceConverters.longToBooleanConverter()
        .convert(getConnection().setbit(key, offset, LettuceConverters.toInt(value)));
  } catch (Exception ex) {
    throw convertLettuceAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(range, "Range for ZRANGEBYLEX must not be null!");
  Assert.notNull(limit, "Limit must not be null!");
      if (limit.isUnlimited()) {
        pipeline(
            connection.newLettuceResult(getAsyncConnection().zrangebylex(key, LettuceConverters.toRange(range, true)),
            LettuceConverters.bytesListToBytesSet()));
      } else {
        pipeline(connection.newLettuceResult(
            getAsyncConnection().zrangebylex(key, LettuceConverters.toRange(range, true),
                LettuceConverters.toLimit(limit)),
            LettuceConverters.bytesListToBytesSet()));
      return LettuceConverters.bytesListToBytesSet()
          .convert(getConnection().zrangebylex(key, LettuceConverters.toRange(range, true)));
    return LettuceConverters.bytesListToBytesSet().convert(
        getConnection().zrangebylex(key, LettuceConverters.toRange(range, true), LettuceConverters.toLimit(limit)));

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(member1, "Member1 must not be null!");
  Assert.notNull(member2, "Member2 must not be null!");
  Assert.notNull(metric, "Metric must not be null!");
  GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(metric);
  Converter<Double, Distance> distanceConverter = LettuceConverters.distanceConverterForMetric(metric);
  try {
    if (isPipelined()) {
      pipeline(connection.newLettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit),
          distanceConverter));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newLettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit),
          distanceConverter));
      return null;
    }
    return distanceConverter.convert(getConnection().geodist(key, member1, member2, geoUnit));
  } catch (Exception ex) {
    throw convertLettuceAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Boolean exists(byte[] key) {
  Assert.notNull(key, "Key must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newLettuceResult(getAsyncConnection().exists(new byte[][] { key }),
          LettuceConverters.longToBooleanConverter()));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newLettuceResult(getAsyncConnection().exists(new byte[][] { key }),
          LettuceConverters.longToBooleanConverter()));
      return null;
    }
    return LettuceConverters.longToBooleanConverter().convert(getConnection().exists(new byte[][] { key }));
  } catch (Exception ex) {
    throw convertLettuceAccessException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    return convertNullSource(sourceType, targetType);
  }
  return this.converter.convert(source);
}

代码示例来源:origin: spring-projects/spring-data-mongodb

public Mono<String> ensureIndex(final IndexDefinition indexDefinition) {
  return mongoOperations.execute(collectionName, collection -> {
    Document indexOptions = indexDefinition.getIndexOptions();
    IndexOptions ops = IndexConverters.indexDefinitionToIndexOptionsConverter().convert(indexDefinition);
    if (indexOptions.containsKey(PARTIAL_FILTER_EXPRESSION_KEY)) {
      Assert.isInstanceOf(Document.class, indexOptions.get(PARTIAL_FILTER_EXPRESSION_KEY));
      MongoPersistentEntity<?> entity = type
          .map(val -> (MongoPersistentEntity) queryMapper.getMappingContext().getRequiredPersistentEntity(val))
          .orElseGet(() -> lookupPersistentEntity(collectionName));
      ops = ops.partialFilterExpression(
          queryMapper.getMappedObject(indexOptions.get(PARTIAL_FILTER_EXPRESSION_KEY, Document.class), entity));
    }
    return collection.createIndex(indexDefinition.getIndexKeys(), ops);
  }).next();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public int compare(S o1, S o2) {
  T c1 = this.converter.convert(o1);
  T c2 = this.converter.convert(o2);
  return this.comparator.compare(c1, c2);
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
  public GeoResult<GeoLocation<byte[]>> convert(redis.clients.jedis.GeoRadiusResponse source) {
    Point point = GEO_COORDINATE_TO_POINT_CONVERTER.convert(source.getCoordinate());
    return new GeoResult<>(new GeoLocation<>(source.getMember(), point),
        new Distance(source.getDistance(), metric));
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@SuppressWarnings("unchecked")
private static <T> Range.Boundary<T> upperBoundaryOf(
    org.springframework.data.redis.connection.RedisZSetCommands.Range range, boolean convertNumberToBytes) {
  return (Range.Boundary<T>) rangeToBoundaryArgumentConverter(true, convertNumberToBytes).convert(range);
}

代码示例来源:origin: spring-projects/spring-data-redis

public static List<RedisClientInfo> toListOfRedisClientInformation(String clientList) {
  return stringToRedisClientListConverter().convert(clientList);
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Object> exec() {
  isMulti = false;
  try {
    if (isPipelined()) {
      RedisFuture<TransactionResult> exec = getAsyncDedicatedRedisCommands().exec();
      LettuceTransactionResultConverter resultConverter = new LettuceTransactionResultConverter(
          new LinkedList<>(txResults), LettuceConverters.exceptionConverter());
      pipeline(newLettuceResult(exec, source -> resultConverter
          .convert(LettuceConverters.transactionResultUnwrapper().convert((TransactionResult) source))));
      return null;
    }
    TransactionResult transactionResult = (getDedicatedRedisCommands()).exec();
    List<Object> results = LettuceConverters.transactionResultUnwrapper().convert(transactionResult);
    return convertPipelineAndTxResults
        ? new LettuceTransactionResultConverter(txResults, LettuceConverters.exceptionConverter()).convert(results)
        : results;
  } catch (Exception ex) {
    throw convertLettuceAccessException(ex);
  } finally {
    txResults.clear();
  }
}

代码示例来源:origin: spring-projects/spring-data-examples

String redisVersion = LettuceConverters.stringToProps().convert(infoServer).getProperty("redis_version");
Version runningVersion = Version.parse(redisVersion);

代码示例来源:origin: spring-projects/spring-data-redis

<T> Function<Throwable, Throwable> translateException() {
  return throwable -> {
    if (throwable instanceof RuntimeException) {
      DataAccessException convertedException = LettuceConverters.exceptionConverter()
          .convert((RuntimeException) throwable);
      return convertedException != null ? convertedException : throwable;
    }
    return throwable;
  };
}

相关文章

Converter类方法