当前位置: 首页>>代码示例>>Java>>正文


Java Country类代码示例

本文整理汇总了Java中com.maxmind.geoip2.record.Country的典型用法代码示例。如果您正苦于以下问题:Java Country类的具体用法?Java Country怎么用?Java Country使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Country类属于com.maxmind.geoip2.record包,在下文中一共展示了Country类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCountry

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
public Optional<Country> getCountry(InetAddress address) {
    if (geoReader == null) {
        return Optional.empty();
    }

    try {
        return Optional.of(geoReader.country(address).getCountry());
    } catch (AddressNotFoundException notFoundEx) {
        //ignore
    } catch (IOException | GeoIp2Exception ex) {
        logger.error("Failed to lookup country of {}", address, ex);
    }

    return Optional.empty();
}
 
开发者ID:games647,项目名称:Minefana,代码行数:16,代码来源:AnalyticsCore.java

示例2: run

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
@Override
public void run() {
    addFields(AnalyticsType.PROTOCOL, players.values().stream()
            .map(AnalyticsPlayer::getProtocol)
            .filter(Objects::nonNull)
            .map(ProtocolVersion::name)
            .collect(Collectors.groupingBy(
                    Function.identity(), Collectors.counting()
            )));

    addFields(AnalyticsType.LOCALE, players.values().stream()
            .map(AnalyticsPlayer::getLocale)
            .collect(Collectors.groupingBy(
                    Function.identity(), Collectors.counting()
            )));

    addFields(AnalyticsType.COUNTRY, players.values().stream()
            .map(AnalyticsPlayer::getAddress)
            .map(core::getCountry)
            .map(country -> country.map(Country::getName).orElse("Unknown"))
            .collect(Collectors.groupingBy(
                    Function.identity(), Collectors.counting()
            )));

    send(AnalyticsType.PLAYERS.newPoint()
            .addField("online", players.size())
            .addField("max", getMaxPlayers()));

    send(AnalyticsType.USERS.newPoint().addField("new", newPlayers));
    newPlayers = 0;
}
 
开发者ID:games647,项目名称:Minefana,代码行数:32,代码来源:PlayerCollector.java

示例3: getCityCountry

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
/**
 * 获取city库的城市地理信息
 *
 * @param ip
 * @return
 */
public Country getCityCountry(String ip) {
    try {
        // "128.101.101.101"
        InetAddress ipAddress = InetAddress.getByName(ip);
        CityResponse response = cityReader.city(ipAddress);
        Country country = response.getCountry();
        return country;
    } catch (IOException | GeoIp2Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:zerosoft,项目名称:CodeBroker,代码行数:19,代码来源:GeoIPService.java

示例4: execute

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, GeoipPermissions.UC_GEOIP_COUNTRY_BASE);
    if (!GeoipHandler.isLoaded()) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "geoip.command.country.notenabled"));
    }

    Player t = args.<Player>getOne("player").get();
    Country country = GeoipHandler.getCountry(t.getConnection().getAddress().getAddress()).orElse(null);
    if (country == null) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "geoip.command.country.failed", "%player%", t));
    }
    Messages.send(sender, "geoip.command.country.success", "%player%", t, "%country%", country.getName());
    return CommandResult.success();
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:16,代码来源:CountryCommand.java

示例5: getValue

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
@Override
public Optional<Text> getValue(@Nullable Object player) {
    //TODO offline player support with last known ip
    if (player instanceof Player) {
        Player p = (Player) player;
        Country c = GeoipHandler.getCountry(p.getConnection().getAddress().getAddress()).orElse(null);
        if (c == null) return Optional.empty();
        return Optional.of(Text.of(c.getName()));
    }
    return Optional.empty();
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:12,代码来源:GeoipVariable.java

示例6: getCountry

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
public static Optional<Country> getCountry(InetAddress ip) {
    if (dbr == null) return Optional.empty();
    try {
        return Optional.ofNullable(dbr.country(ip).getCountry());
    } catch (Exception ex) {
        return Optional.empty();
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:9,代码来源:GeoipHandler.java

示例7: createDocFromInsightsService

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
public static NutchDocument createDocFromInsightsService(String serverIp,
    NutchDocument doc, WebServiceClient client) throws UnknownHostException,
    IOException, GeoIp2Exception {
  doc.add("ip", serverIp);
  InsightsResponse response = client
      .insights(InetAddress.getByName(serverIp));
  // CityResponse response = client.city(InetAddress.getByName(serverIp));

  City city = response.getCity();
  doc.add("cityName", city.getName()); // 'Minneapolis'
  doc.add("cityConfidence", city.getConfidence()); // 50
  doc.add("cityGeoNameId", city.getGeoNameId());

  Continent continent = response.getContinent();
  doc.add("continentCode", continent.getCode());
  doc.add("continentGeoNameId", continent.getGeoNameId());
  doc.add("continentName", continent.getName());

  Country country = response.getCountry();
  doc.add("countryIsoCode", country.getIsoCode()); // 'US'
  doc.add("countryName", country.getName()); // 'United States'
  doc.add("countryConfidence", country.getConfidence()); // 99
  doc.add("countryGeoName", country.getGeoNameId());

  Location location = response.getLocation();
  doc.add("latLon", location.getLatitude() + "," + location.getLongitude()); // 44.9733,
                                                                             // -93.2323
  doc.add("accRadius", location.getAccuracyRadius()); // 3
  doc.add("timeZone", location.getTimeZone()); // 'America/Chicago'
  doc.add("metroCode", location.getMetroCode());

  Postal postal = response.getPostal();
  doc.add("postalCode", postal.getCode()); // '55455'
  doc.add("postalConfidence", postal.getConfidence()); // 40

  RepresentedCountry rCountry = response.getRepresentedCountry();
  doc.add("countryType", rCountry.getType());

  Subdivision subdivision = response.getMostSpecificSubdivision();
  doc.add("subDivName", subdivision.getName()); // 'Minnesota'
  doc.add("subDivIdoCode", subdivision.getIsoCode()); // 'MN'
  doc.add("subDivConfidence", subdivision.getConfidence()); // 90
  doc.add("subDivGeoNameId", subdivision.getGeoNameId());

  Traits traits = response.getTraits();
  doc.add("autonSystemNum", traits.getAutonomousSystemNumber());
  doc.add("autonSystemOrg", traits.getAutonomousSystemOrganization());
  doc.add("domain", traits.getDomain());
  doc.add("isp", traits.getIsp());
  doc.add("org", traits.getOrganization());
  doc.add("userType", traits.getUserType());
  doc.add("isAnonProxy", traits.isAnonymousProxy());
  doc.add("isSatelliteProv", traits.isSatelliteProvider());
  return doc;
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:56,代码来源:GeoIPDocumentCreator.java

示例8: makeCountry

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
private static Place makeCountry(final Country where) {
    return isValid(where) ? new Place(Place.Type.COUNTRY, where.getName(), where.getIsoCode()) : null;
}
 
开发者ID:workshare,项目名称:ms-nos,代码行数:4,代码来源:Location.java

示例9: response

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
private OmniResponse response(Country country) {
    return response(null, country, null, null);
}
 
开发者ID:workshare,项目名称:ms-nos,代码行数:4,代码来源:LocationTest.java

示例10: mockCountry

import com.maxmind.geoip2.record.Country; //导入依赖的package包/类
private static Country mockCountry(String code, String name) {
    Country country = mock(Country.class);
    when(country.getIsoCode()).thenReturn(code);
    when(country.getName()).thenReturn(name);
    return country;
}
 
开发者ID:workshare,项目名称:ms-nos,代码行数:7,代码来源:LocationTest.java


注:本文中的com.maxmind.geoip2.record.Country类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。