org.springframework.data.geo.Distance.getValue()方法的使用及代码示例

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

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

Distance.getValue介绍

暂无

代码示例

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

/**
 * Creates a Sphere around the given center {@link Point} with the given radius.
 *
 * @param center must not be {@literal null}.
 * @param radius must not be {@literal null}.
 */
@PersistenceConstructor
public Sphere(Point center, Distance radius) {
  Assert.notNull(center, "Center point must not be null!");
  Assert.notNull(radius, "Radius must not be null!");
  Assert.isTrue(radius.getValue() >= 0, "Radius must not be negative!");
  this.center = center;
  this.radius = radius;
}

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

/**
 * extract the distance string from a {@link org.springframework.data.geo.Distance} object.
 *
 * @param distance distance object to extract string from
 * @param sb StringBuilder to build the distance string
 */
private void extractDistanceString(Distance distance, StringBuilder sb) {
  // handle Distance object
  sb.append((int) distance.getValue());
  Metrics metric = (Metrics) distance.getMetric();
  switch (metric) {
    case KILOMETERS:
      sb.append("km");
      break;
    case MILES:
      sb.append("mi");
      break;
  }
}

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

/**
 * Returns the {@link Shape} as a list of usually {@link Double} or {@link List}s of {@link Double}s. Wildcard bound
 * to allow implementations to return a more concrete element type.
 *
 * @return
 */
public List<? extends Object> asList() {
  return Arrays.asList(Arrays.asList(center.getX(), center.getY()), this.radius.getValue());
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
  return read(key, ByteArrayCodec.INSTANCE, GEORADIUSBYMEMBER, key, member, radius.getValue(), radius.getMetric().getAbbreviation());
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
  return read(key, ByteArrayCodec.INSTANCE, GEORADIUSBYMEMBER, key, member, radius.getValue(), radius.getMetric().getAbbreviation());
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
    GeoRadiusCommandArgs args) {
  List<Object> params = new ArrayList<Object>();
  params.add(key);
  params.add(member);
  params.add(radius.getValue());
  params.add(radius.getMetric().getAbbreviation());
  
  RedisCommand<GeoResults<GeoLocation<byte[]>>> command;
  if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
    command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", postitionDecoder);
    params.add("WITHCOORD");
  } else {
    MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder(new GeoDistanceDecoder(), new GeoResultsDecoder(radius.getMetric()));
    command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", distanceDecoder);
    params.add("WITHDIST");
  }
  
  if (args.getLimit() != null) {
    params.add("COUNT");
    params.add(args.getLimit());
  }
  if (args.getSortDirection() != null) {
    params.add(args.getSortDirection().name());
  }
  
  return read(key, ByteArrayCodec.INSTANCE, command, params.toArray());
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
    GeoRadiusCommandArgs args) {
  List<Object> params = new ArrayList<Object>();
  params.add(key);
  params.add(member);
  params.add(radius.getValue());
  params.add(radius.getMetric().getAbbreviation());
  
  RedisCommand<GeoResults<GeoLocation<byte[]>>> command;
  if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
    command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", postitionDecoder);
    params.add("WITHCOORD");
  } else {
    MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder(new GeoDistanceDecoder(), new GeoResultsDecoder(radius.getMetric()));
    command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUSBYMEMBER", distanceDecoder);
    params.add("WITHDIST");
  }
  
  if (args.getLimit() != null) {
    params.add("COUNT");
    params.add(args.getLimit());
  }
  if (args.getSortDirection() != null) {
    params.add(args.getSortDirection().name());
  }
  
  return read(key, ByteArrayCodec.INSTANCE, command, params.toArray());
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
  List<Object> params = new ArrayList<Object>();
  params.add(key);
  params.add(convert(within.getCenter().getX()));
  params.add(convert(within.getCenter().getY()));
  params.add(within.getRadius().getValue());
  params.add(within.getRadius().getMetric().getAbbreviation());
  
  RedisCommand<GeoResults<GeoLocation<byte[]>>> command;
  if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
    command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder);
    params.add("WITHCOORD");
  } else {
    MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder(new GeoDistanceDecoder(), new GeoResultsDecoder(within.getRadius().getMetric()));
    command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder);
    params.add("WITHDIST");
  }
  
  if (args.getLimit() != null) {
    params.add("COUNT");
    params.add(args.getLimit());
  }
  if (args.getSortDirection() != null) {
    params.add(args.getSortDirection().name());
  }
  
  return read(key, ByteArrayCodec.INSTANCE, command, params.toArray());
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
  List<Object> params = new ArrayList<Object>();
  params.add(key);
  params.add(convert(within.getCenter().getX()));
  params.add(convert(within.getCenter().getY()));
  params.add(within.getRadius().getValue());
  params.add(within.getRadius().getMetric().getAbbreviation());
  
  RedisCommand<GeoResults<GeoLocation<byte[]>>> command;
  if (args.getFlags().contains(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
    command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", postitionDecoder);
    params.add("WITHCOORD");
  } else {
    MultiDecoder<GeoResults<GeoLocation<byte[]>>> distanceDecoder = new ListMultiDecoder(new GeoDistanceDecoder(), new GeoResultsDecoder(within.getRadius().getMetric()));
    command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", distanceDecoder);
    params.add("WITHDIST");
  }
  
  if (args.getLimit() != null) {
    params.add("COUNT");
    params.add(args.getLimit());
  }
  if (args.getSortDirection() != null) {
    params.add(args.getSortDirection().name());
  }
  
  return read(key, ByteArrayCodec.INSTANCE, command, params.toArray());
}

代码示例来源: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!");
  GeoUnit geoUnit = JedisConverters.toGeoUnit(radius.getMetric());
  redis.clients.jedis.params.GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(args);
  try {
    return JedisConverters.geoRadiusResponseToGeoResultsConverter(radius.getMetric())
        .convert(connection.getCluster().georadiusByMember(key, member, radius.getValue(), geoUnit, geoRadiusParam));
  } catch (Exception ex) {
    throw convertJedisAccessException(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 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());
  Converter<List<redis.clients.jedis.GeoRadiusResponse>, GeoResults<GeoLocation<byte[]>>> converter = JedisConverters
      .geoRadiusResponseToGeoResultsConverter(radius.getMetric());
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(
          connection.getRequiredPipeline().georadiusByMember(key, member, radius.getValue(), geoUnit), converter));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(
          connection.getRequiredTransaction().georadiusByMember(key, member, radius.getValue(), geoUnit), converter));
      return null;
    }
    return converter.convert(connection.getJedis().georadiusByMember(key, member, radius.getValue(), geoUnit));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

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

@Override
public Flux<CommandResponse<GeoRadiusByMemberCommand, Flux<GeoResult<GeoLocation<ByteBuffer>>>>> geoRadiusByMember(
    Publisher<GeoRadiusByMemberCommand> commands) {
  return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
    Assert.notNull(command.getKey(), "Key must not be null!");
    Assert.notNull(command.getMember(), "Member must not be null!");
    Assert.notNull(command.getDistance(), "Distance must not be null!");
    GeoArgs geoArgs = command.getArgs().isPresent() ? LettuceConverters.toGeoArgs(command.getArgs().get())
        : new GeoArgs();
    Flux<GeoResult<GeoLocation<ByteBuffer>>> result = cmd
        .georadiusbymember(command.getKey(), command.getMember(), command.getDistance().getValue(),
            LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()), geoArgs)
        .map(converter(command.getDistance().getMetric())::convert);
    return Mono.just(new CommandResponse<>(command, result));
  }));
}

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

@Override
public Flux<CommandResponse<GeoRadiusCommand, Flux<GeoResult<GeoLocation<ByteBuffer>>>>> geoRadius(
    Publisher<GeoRadiusCommand> commands) {
  return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
    Assert.notNull(command.getKey(), "Key must not be null!");
    Assert.notNull(command.getPoint(), "Point must not be null!");
    Assert.notNull(command.getDistance(), "Distance must not be null!");
    GeoArgs geoArgs = command.getArgs().isPresent() ? LettuceConverters.toGeoArgs(command.getArgs().get())
        : new GeoArgs();
    Flux<GeoResult<GeoLocation<ByteBuffer>>> result = cmd
        .georadius(command.getKey(), command.getPoint().getX(), command.getPoint().getY(),
            command.getDistance().getValue(), LettuceConverters.toGeoArgsUnit(command.getDistance().getMetric()),
            geoArgs) //
        .map(converter(command.getDistance().getMetric())::convert);
    return Mono.just(new CommandResponse<>(command, result));
  }));
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(within, "Within must not be null!");
  Assert.notNull(args, "Args must not be null!");
  GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(args);
  try {
    return JedisConverters.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric())
        .convert(connection.getCluster().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
            within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric()),
            geoRadiusParam));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(within, "Within must not be null!");
  try {
    return JedisConverters.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric())
        .convert(connection.getCluster().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
            within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())));
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
  RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder());
  return read(key, ByteArrayCodec.INSTANCE, command, key, 
          convert(within.getCenter().getX()), convert(within.getCenter().getY()), 
          within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation());
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
  RedisCommand<GeoResults<GeoLocation<byte[]>>> command = new RedisCommand<GeoResults<GeoLocation<byte[]>>>("GEORADIUS", new GeoResultsDecoder());
  return read(key, ByteArrayCodec.INSTANCE, command, key, 
          convert(within.getCenter().getX()), convert(within.getCenter().getY()), 
          within.getRadius().getValue(), within.getRadius().getMetric().getAbbreviation());
}

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

@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
  Assert.notNull(key, "Key must not be null!");
  Assert.notNull(within, "Within must not be null!");
  Assert.notNull(args, "Args must not be null!");
  GeoArgs geoArgs = LettuceConverters.toGeoArgs(args);
  Converter<List<GeoWithin<byte[]>>, GeoResults<GeoLocation<byte[]>>> geoResultsConverter = LettuceConverters
      .geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric());
  try {
    if (isPipelined()) {
      pipeline(connection.newLettuceResult(getAsyncConnection().georadius(key, within.getCenter().getX(),
          within.getCenter().getY(), within.getRadius().getValue(),
          LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric()), geoArgs), geoResultsConverter));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newLettuceResult(getAsyncConnection().georadius(key, within.getCenter().getX(),
          within.getCenter().getY(), within.getRadius().getValue(),
          LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric()), geoArgs), geoResultsConverter));
      return null;
    }
    return geoResultsConverter
        .convert(getConnection().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
            within.getRadius().getValue(), LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric()), geoArgs));
  } catch (Exception ex) {
    throw convertLettuceAccessException(ex);
  }
}

相关文章