/** * Checks that the provided access token is not empty or null, and that it starts with * the right prefixes. Note that this method does not check Mapbox servers to verify that * it actually belongs to an account. * * @param accessToken A Mapbox access token. * @return true if the provided access token is valid, false otherwise. * @since 1.0.0 */ public static boolean isAccessTokenValid(String accessToken) { return !TextUtils.isEmpty(accessToken) && !(!accessToken.startsWith("pk.") && !accessToken.startsWith("sk.") && !accessToken.startsWith("tk.")); } }
/** * Computes a full user agent header of the form: * {@code MapboxJava/1.2.0 Mac OS X/10.11.5 (x86_64)}. * * @param clientAppName Application Name * @return {@link String} representing the header user agent * @since 1.0.0 */ public static String getHeaderUserAgent(@Nullable String clientAppName) { String osName = System.getProperty("os.name"); String osVersion = System.getProperty("os.version"); String osArch = System.getProperty("os.arch"); if (TextUtils.isEmpty(osName) || TextUtils.isEmpty(osVersion) || TextUtils.isEmpty(osArch)) { return Constants.HEADER_USER_AGENT; } else { return getHeaderUserAgent(clientAppName, osName, osVersion, osArch); } }
/** * Computes a full user agent header of the form: * {@code MapboxJava/1.2.0 Mac OS X/10.11.5 (x86_64)}. * * @param clientAppName Application Name * @param osName OS name * @param osVersion OS version * @param osArch OS Achitecture * @return {@link String} representing the header user agent * @since 1.0.0 */ public static String getHeaderUserAgent(@Nullable String clientAppName, @NonNull String osName, @NonNull String osVersion, @NonNull String osArch) { osName = osName.replaceAll(ONLY_PRINTABLE_CHARS, ""); osVersion = osVersion.replaceAll(ONLY_PRINTABLE_CHARS, ""); osArch = osArch.replaceAll(ONLY_PRINTABLE_CHARS, ""); String baseUa = String.format( Locale.US, "%s %s/%s (%s)", Constants.HEADER_USER_AGENT, osName, osVersion, osArch); return TextUtils.isEmpty(clientAppName) ? baseUa : String.format(Locale.US, "%s %s", clientAppName, baseUa); } }
/** * Enforce expectations about types of GeoJson objects for Turf. * * @param value any GeoJson object * @param type expected GeoJson type * @param name name of calling function * @see <a href="http://turfjs.org/docs/#geojsontype">Turf geojsonType documentation</a> * @since 1.2.0 */ public static void geojsonType(GeoJson value, String type, String name) { if (TextUtils.isEmpty(type) || TextUtils.isEmpty(name)) { throw new TurfException("Type and name required"); } if (value == null || !value.type().equals(type)) { throw new TurfException("Invalid input to " + name + ": must be a " + type + ", given " + (value != null ? value.type() : " null")); } }
/** * This uses the provided parameters set using the {@link Builder} and first checks that all * values are valid, formats the values as strings for easier consumption by the API, and lastly * creates a new {@link MapboxSpeech} object with the values provided. * * @return a new instance of Mapbox Speech * @throws ServicesException when a provided parameter is detected to be incorrect * @since 3.0.0 */ public MapboxSpeech build() { MapboxSpeech mapboxSpeech = autoBuild(); if (TextUtils.isEmpty(mapboxSpeech.instruction())) { throw new ServicesException("Non-null, non-empty instruction text is required."); } return mapboxSpeech; } }
/** * This uses the provided parameters set using the {@link Builder} and first checks that all * values are valid, formats the values as strings for easier consumption by the API, and lastly * creates a new {@link MapboxSpeech} object with the values provided. * * @return a new instance of Mapbox Speech * @throws ServicesException when a provided parameter is detected to be incorrect * @since 3.0.0 */ public MapboxSpeech build() { MapboxSpeech mapboxSpeech = autoBuild(); if (TextUtils.isEmpty(mapboxSpeech.instruction())) { throw new ServicesException("Non-null, non-empty instruction text is required."); } return mapboxSpeech; } }
/** * This uses the provided parameters set using the {@link Builder} and first checks that all * values are valid, formats the values as strings for easier consumption by the API, and lastly * creates a new {@link MapboxSpeech} object with the values provided. * * @return a new instance of Mapbox Speech * @throws ServicesException when a provided parameter is detected to be incorrect * @since 3.0.0 */ public MapboxSpeech build() { MapboxSpeech mapboxSpeech = autoBuild(); if (TextUtils.isEmpty(mapboxSpeech.instruction())) { throw new ServicesException("Non-null, non-empty instruction text is required."); } return mapboxSpeech; } }
/** * Enforce expectations about types of {@link Feature} inputs for Turf. Internally this uses * {@link Feature#type()} to judge geometry types. * * @param feature with an expected geometry type * @param type type expected GeoJson type * @param name name of calling function * @see <a href="http://turfjs.org/docs/#featureof">Turf featureOf documentation</a> * @since 1.2.0 */ public static void featureOf(Feature feature, String type, String name) { if (TextUtils.isEmpty(name)) { throw new TurfException(".featureOf() requires a name"); } if (feature == null || !feature.type().equals("Feature") || feature.geometry() == null) { throw new TurfException(String.format( "Invalid input to %s, Feature with geometry required", name)); } if (feature.geometry() == null || !feature.geometry().type().equals(type)) { throw new TurfException(String.format( "Invalid input to %s: must be a %s, given %s", name, type, feature.geometry().type())); } }
if (TextUtils.isEmpty(name)) { throw new TurfException("collectionOf() requires a name");
/** * <em>Used Internally.</em> * * @return a String representing the marker part of the URL * @since 2.1.0 */ @RestrictTo(LIBRARY) public String url() { String url; if (iconUrl() != null) { return String.format( Locale.US, "url-%s(%f,%f)", iconUrl(), lnglat().longitude(), lnglat().latitude()); } if (color() != null && !TextUtils.isEmpty(label())) { url = String.format(Locale.US, "%s-%s+%s", name(), label(), color()); } else if (!TextUtils.isEmpty(label())) { url = String.format(Locale.US, "%s-%s", name(), label()); } else if (color() != null) { url = String.format(Locale.US, "%s+%s", name(), color()); } else { url = name(); } return String.format(Locale.US, "%s(%f,%f)", url, lnglat().longitude(), lnglat().latitude()); }
/** * <em>Used Internally.</em> * * @return a String representing the marker part of the URL * @since 2.1.0 */ @RestrictTo(LIBRARY) public String url() { String url; if (iconUrl() != null) { return String.format( Locale.US, "url-%s(%f,%f)", iconUrl(), lnglat().longitude(), lnglat().latitude()); } if (color() != null && !TextUtils.isEmpty(label())) { url = String.format(Locale.US, "%s-%s+%s", name(), label(), color()); } else if (!TextUtils.isEmpty(label())) { url = String.format(Locale.US, "%s-%s", name(), label()); } else if (color() != null) { url = String.format(Locale.US, "%s+%s", name(), color()); } else { url = name(); } return String.format(Locale.US, "%s(%f,%f)", url, lnglat().longitude(), lnglat().latitude()); }
/** * <em>Used Internally.</em> * * @return a String representing the marker part of the URL * @since 2.1.0 */ @RestrictTo(LIBRARY) public String url() { String url; if (iconUrl() != null) { return String.format( Locale.US, "url-%s(%f,%f)", iconUrl(), lnglat().longitude(), lnglat().latitude()); } if (color() != null && !TextUtils.isEmpty(label())) { url = String.format(Locale.US, "%s-%s+%s", name(), label(), color()); } else if (!TextUtils.isEmpty(label())) { url = String.format(Locale.US, "%s-%s", name(), label()); } else if (color() != null) { url = String.format(Locale.US, "%s+%s", name(), color()); } else { url = name(); } return String.format(Locale.US, "%s(%f,%f)", url, lnglat().longitude(), lnglat().latitude()); }
@Test public void sanity() throws Exception { MapboxStaticMap staticMap = MapboxStaticMap.builder() .accessToken(ACCESS_TOKEN) .build(); assertNotNull(staticMap); assertTrue(!TextUtils.isEmpty(staticMap.url().toString())); }