com.twitter.hbc.core.endpoint.Location Java Examples

The following examples show how to use com.twitter.hbc.core.endpoint.Location. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationUtil.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param input a comma-separated list of longitude,latitude pairs specifying a set of bounding boxes,
 *              with the southwest corner of the bounding box coming first
 *
 * @return a list of the Location instances represented by the provided input
 */
public static List<Location> parseLocations(final String input) {
    final List<Location> locations = new ArrayList<>();
    final Matcher locationsMatcher = LOCATIONS_PATTERN.matcher(input);
    if (locationsMatcher.matches()) {
        Matcher locationMatcher = LOCATION_PATTERN.matcher(input);
        while (locationMatcher.find()) {
            final String location = locationMatcher.group();
            locations.add(parseLocation(location));
        }
    } else {
        throw new IllegalStateException("The provided location string was invalid.");
    }

    return locations;
}
 
Example #2
Source File: TestLocationUtil.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseLocationsSingle() {
    final String swLon = "-122.75";
    final String swLat = "36.8";
    final String neLon = "-121.75";
    final String neLat = "37.8";

    final String locationString = swLon + "," + swLat + "," + neLon + "," + neLat;
    List<Location> locations = LocationUtil.parseLocations(locationString);
    Assert.assertEquals(1, locations.size());

    Location location = locations.get(0);
    Assert.assertEquals(new Double(location.southwestCoordinate().longitude()), Double.valueOf(swLon));
    Assert.assertEquals(new Double(location.southwestCoordinate().latitude()), Double.valueOf(swLat));
    Assert.assertEquals(new Double(location.northeastCoordinate().longitude()), Double.valueOf(neLon));
    Assert.assertEquals(new Double(location.northeastCoordinate().latitude()), Double.valueOf(neLat));
}
 
Example #3
Source File: LocationUtil.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param input a comma-separated list of longitude,latitude pairs specifying a set of bounding boxes,
 *              with the southwest corner of the bounding box coming first
 *
 * @return a list of the Location instances represented by the provided input
 */
public static List<Location> parseLocations(final String input) {
    final List<Location> locations = new ArrayList<>();
    final Matcher locationsMatcher = LOCATIONS_PATTERN.matcher(input);
    if (locationsMatcher.matches()) {
        Matcher locationMatcher = LOCATION_PATTERN.matcher(input);
        while (locationMatcher.find()) {
            final String location = locationMatcher.group();
            locations.add(parseLocation(location));
        }
    } else {
        throw new IllegalStateException("The provided location string was invalid.");
    }

    return locations;
}
 
Example #4
Source File: TestLocationUtil.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseLocationsSingle() {
    final String swLon = "-122.75";
    final String swLat = "36.8";
    final String neLon = "-121.75";
    final String neLat = "37.8";

    final String locationString = swLon + "," + swLat + "," + neLon + "," + neLat;
    List<Location> locations = LocationUtil.parseLocations(locationString);
    Assert.assertEquals(1, locations.size());

    Location location = locations.get(0);
    Assert.assertEquals(new Double(location.southwestCoordinate().longitude()), Double.valueOf(swLon));
    Assert.assertEquals(new Double(location.southwestCoordinate().latitude()), Double.valueOf(swLat));
    Assert.assertEquals(new Double(location.northeastCoordinate().longitude()), Double.valueOf(neLon));
    Assert.assertEquals(new Double(location.northeastCoordinate().latitude()), Double.valueOf(neLat));
}
 
Example #5
Source File: LocationUtil.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param location a comma-separated list of longitude,latitude pairs specifying one location
 *
 * @return the Location instance for the provided input
 */
public static Location parseLocation(final String location) {
    final String[] corSplit = location.split(",");

    final double swLon = Double.parseDouble(corSplit[0]) ;
    final double swLat = Double.parseDouble(corSplit[1]) ;

    final double neLon = Double.parseDouble(corSplit[2]) ;
    final double neLat = Double.parseDouble(corSplit[3]) ;

    Location.Coordinate sw = new Location.Coordinate(swLon, swLat) ;
    Location.Coordinate ne = new Location.Coordinate(neLon, neLat) ;
    return new Location(sw, ne) ;
}
 
Example #6
Source File: TestLocationUtil.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseLocationsMultiple() {
    final Location location1 = new Location(new Location.Coordinate(-122.75, 36.8), new Location.Coordinate(-121.75,37.8));
    final Location location2 = new Location(new Location.Coordinate(-74, 40), new Location.Coordinate(-73, 41));
    final Location location3 = new Location(new Location.Coordinate(-64, 30), new Location.Coordinate(-63, 31));
    final Location location4 = new Location(new Location.Coordinate(-54, 20), new Location.Coordinate(-53, 21));

    final List<Location> expectedLocations = Arrays.asList(location1, location2, location3, location4);

    final String locationString = "-122.75,36.8,-121.75,37.8,-74,40,-73,41,-64,30,-63,31,-54,20,-53,21";
    List<Location> locations = LocationUtil.parseLocations(locationString);
    Assert.assertEquals(expectedLocations.size(), locations.size());

    for (Location expectedLocation : expectedLocations) {
        boolean found = false;
        for (Location location : locations) {
            if (location.northeastCoordinate().longitude() == expectedLocation.northeastCoordinate().longitude()
                    && location.northeastCoordinate().latitude() == expectedLocation.northeastCoordinate().latitude()
                    && location.southwestCoordinate().longitude() == expectedLocation.southwestCoordinate().longitude()
                    && location.southwestCoordinate().latitude() == expectedLocation.southwestCoordinate().latitude()) {
                found = true;
                break;
            }
        }
        Assert.assertTrue(found);
    }

}
 
Example #7
Source File: GeoTwitterSource.java    From OSTMap with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeConnection() {
    if (LOG.isInfoEnabled()) {
        LOG.info("Initializing Twitter Streaming API connection");
    }

    this.queue = new LinkedBlockingQueue(this.queueSize);
    StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(false)
            .locations(Arrays.asList(
                            new Location(
                                    // europa: -32.0 34.0 40.0 75.0
                                    new Location.Coordinate(-32.0, 34.0), // south west
                                    new Location.Coordinate(40.0, 75.0))
                     //       new Location(
                     //               // north america: -168.48633, 13.23995 -50.36133, 72.76406
                     //               new Location.Coordinate(-168.48633, 13.23995), // south west
                     //               new Location.Coordinate(-50.36133, 72.76406))
                    )
            );
    endpoint.stallWarnings(false);
    OAuth1 auth = this.authenticate();

    this.initializeClient(endpoint, auth);
    if (LOG.isInfoEnabled()) {
        LOG.info("Twitter Streaming API connection established successfully");
    }

}
 
Example #8
Source File: LocationUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param location a comma-separated list of longitude,latitude pairs specifying one location
 *
 * @return the Location instance for the provided input
 */
public static Location parseLocation(final String location) {
    final String[] corSplit = location.split(",");

    final double swLon = Double.parseDouble(corSplit[0]) ;
    final double swLat = Double.parseDouble(corSplit[1]) ;

    final double neLon = Double.parseDouble(corSplit[2]) ;
    final double neLat = Double.parseDouble(corSplit[3]) ;

    Location.Coordinate sw = new Location.Coordinate(swLon, swLat) ;
    Location.Coordinate ne = new Location.Coordinate(neLon, neLat) ;
    return new Location(sw, ne) ;
}
 
Example #9
Source File: TestLocationUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseLocationsMultiple() {
    final Location location1 = new Location(new Location.Coordinate(-122.75, 36.8), new Location.Coordinate(-121.75,37.8));
    final Location location2 = new Location(new Location.Coordinate(-74, 40), new Location.Coordinate(-73, 41));
    final Location location3 = new Location(new Location.Coordinate(-64, 30), new Location.Coordinate(-63, 31));
    final Location location4 = new Location(new Location.Coordinate(-54, 20), new Location.Coordinate(-53, 21));

    final List<Location> expectedLocations = Arrays.asList(location1, location2, location3, location4);

    final String locationString = "-122.75,36.8,-121.75,37.8,-74,40,-73,41,-64,30,-63,31,-54,20,-53,21";
    List<Location> locations = LocationUtil.parseLocations(locationString);
    Assert.assertEquals(expectedLocations.size(), locations.size());

    for (Location expectedLocation : expectedLocations) {
        boolean found = false;
        for (Location location : locations) {
            if (location.northeastCoordinate().longitude() == expectedLocation.northeastCoordinate().longitude()
                    && location.northeastCoordinate().latitude() == expectedLocation.northeastCoordinate().latitude()
                    && location.southwestCoordinate().longitude() == expectedLocation.southwestCoordinate().longitude()
                    && location.southwestCoordinate().latitude() == expectedLocation.southwestCoordinate().latitude()) {
                found = true;
                break;
            }
        }
        Assert.assertTrue(found);
    }

}
 
Example #10
Source File: GetTwitter.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    try {
        final List<Location> locations = LocationUtil.parseLocations(input);
        for (final Location location : locations) {
            final Coordinate sw = location.southwestCoordinate();
            final Coordinate ne = location.northeastCoordinate();

            if (sw.longitude() > ne.longitude()) {
                return new ValidationResult.Builder().input(input).subject(subject).valid(false)
                        .explanation("SW Longitude (" + sw.longitude() + ") must be less than NE Longitude ("
                                + ne.longitude() + ").").build();
            }

            if (sw.longitude() == ne.longitude()) {
                return new ValidationResult.Builder().input(input).subject(subject).valid(false)
                        .explanation("SW Longitude (" + sw.longitude() + ") can not be equal to NE Longitude ("
                                + ne.longitude() + ").").build();
            }

            if (sw.latitude() > ne.latitude()) {
                return new ValidationResult.Builder().input(input).subject(subject).valid(false)
                        .explanation("SW Latitude (" + sw.latitude() + ") must be less than NE Latitude ("
                                + ne.latitude() + ").").build();
            }

            if (sw.latitude() == ne.latitude()) {
                return new ValidationResult.Builder().input(input).subject(subject).valid(false)
                        .explanation("SW Latitude (" + sw.latitude() + ") can not be equal to NE Latitude ("
                                + ne.latitude() + ").").build();
            }
        }

        return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();

    } catch (IllegalStateException e) {
        return new ValidationResult.Builder()
                .input(input).subject(subject).valid(false)
                .explanation("Must be a comma-separated list of longitude,latitude pairs specifying one or more bounding boxes.")
                .build();
    }
}
 
Example #11
Source File: GetTwitter.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    try {
        final List<Location> locations = LocationUtil.parseLocations(input);
        for (final Location location : locations) {
            final Coordinate sw = location.southwestCoordinate();
            final Coordinate ne = location.northeastCoordinate();

            if (sw.longitude() > ne.longitude()) {
                return new ValidationResult.Builder().input(input).subject(subject).valid(false)
                        .explanation("SW Longitude (" + sw.longitude() + ") must be less than NE Longitude ("
                                + ne.longitude() + ").").build();
            }

            if (sw.longitude() == ne.longitude()) {
                return new ValidationResult.Builder().input(input).subject(subject).valid(false)
                        .explanation("SW Longitude (" + sw.longitude() + ") can not be equal to NE Longitude ("
                                + ne.longitude() + ").").build();
            }

            if (sw.latitude() > ne.latitude()) {
                return new ValidationResult.Builder().input(input).subject(subject).valid(false)
                        .explanation("SW Latitude (" + sw.latitude() + ") must be less than NE Latitude ("
                                + ne.latitude() + ").").build();
            }

            if (sw.latitude() == ne.latitude()) {
                return new ValidationResult.Builder().input(input).subject(subject).valid(false)
                        .explanation("SW Latitude (" + sw.latitude() + ") can not be equal to NE Latitude ("
                                + ne.latitude() + ").").build();
            }
        }

        return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();

    } catch (IllegalStateException e) {
        return new ValidationResult.Builder()
                .input(input).subject(subject).valid(false)
                .explanation("Must be a comma-separated list of longitude,latitude pairs specifying one or more bounding boxes.")
                .build();
    }
}