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

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

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

Distance.getMetric介绍

暂无

代码示例

代码示例来源: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: 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: 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[]>> 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,
    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: 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-mongodb

@Override
  public Document convert(Circle source) {
    if (source == null) {
      return null;
    }
    Document result = new Document();
    result.put("center", PointToDocumentConverter.INSTANCE.convert(source.getCenter()));
    result.put("radius", source.getRadius().getNormalizedValue());
    result.put("metric", source.getRadius().getMetric().toString());
    return result;
  }
}

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

@Override
  public Document convert(Sphere source) {
    if (source == null) {
      return null;
    }
    Document result = new Document();
    result.put("center", PointToDocumentConverter.INSTANCE.convert(source.getCenter()));
    result.put("radius", source.getRadius().getNormalizedValue());
    result.put("metric", source.getRadius().getMetric().toString());
    return result;
  }
}

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

@SuppressWarnings({ "unchecked", "rawtypes" })
protected Flux<GeoResult<Object>> doExecuteQuery(@Nullable Query query, Class<?> type, String collection) {
  Point nearLocation = accessor.getGeoNearLocation();
  NearQuery nearQuery = NearQuery.near(nearLocation);
  if (query != null) {
    nearQuery.query(query);
  }
  Range<Distance> distances = accessor.getDistanceRange();
  distances.getUpperBound().getValue().ifPresent(it -> nearQuery.maxDistance(it).in(it.getMetric()));
  distances.getLowerBound().getValue().ifPresent(it -> nearQuery.minDistance(it).in(it.getMetric()));
  Pageable pageable = accessor.getPageable();
  nearQuery.with(pageable);
  return (Flux) operations.geoNear(nearQuery, type, collection);
}

代码示例来源: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: 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<V>> convert(GeoResults<GeoLocation<byte[]>> source) {
    List<GeoResult<GeoLocation<V>>> values = new ArrayList<>(source.getContent().size());
    for (GeoResult<GeoLocation<byte[]>> value : source.getContent()) {
      values.add(new GeoResult<>(
          new GeoLocation<>(serializer.deserialize(value.getContent().getName()), value.getContent().getPoint()),
          value.getDistance()));
    }
    return new GeoResults<>(values, source.getAverageDistance().getMetric());
  }
}

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

@SuppressWarnings("unchecked")
GeoResults<Object> doExecuteQuery(Query query) {
  Point nearLocation = accessor.getGeoNearLocation();
  NearQuery nearQuery = NearQuery.near(nearLocation);
  if (query != null) {
    nearQuery.query(query);
  }
  Range<Distance> distances = accessor.getDistanceRange();
  distances.getLowerBound().getValue().ifPresent(it -> nearQuery.minDistance(it).in(it.getMetric()));
  distances.getUpperBound().getValue().ifPresent(it -> nearQuery.maxDistance(it).in(it.getMetric()));
  Pageable pageable = accessor.getPageable();
  nearQuery.with(pageable);
  return (GeoResults<Object>) operation.near(nearQuery).all();
}

代码示例来源: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());
}

相关文章