Tabnine Logo
Utils
Code IndexAdd Tabnine to your IDE (free)

How to use
Utils
in
com.ecwid.consul

Best Java code snippets using com.ecwid.consul.Utils (Showing top 20 results out of 315)

origin: Ecwid/consul-api

ConsulRawClient(HttpTransport httpTransport, String agentHost, int agentPort, String path) {
  this.httpTransport = httpTransport;
  // check that agentHost has scheme or not
  String agentHostLowercase = agentHost.toLowerCase();
  if (!agentHostLowercase.startsWith("https://") && !agentHostLowercase.startsWith("http://")) {
    // no scheme in host, use default 'http'
    agentHost = "http://" + agentHost;
  }
  this.agentAddress = Utils.assembleAgentAddress(agentHost, agentPort, path);
}
origin: com.ecwid.consul/consul-api

private String prepareUrl(String url) {
  if (url.contains(" ")) {
    // temp hack for old clients who did manual encoding and just use %20
    return Utils.encodeUrl(url);
  } else {
    return url;
  }
}
origin: com.ecwid.consul/consul-api

public static String generateUrl(String baseUrl, UrlParameters... params) {
  return generateUrl(baseUrl, Arrays.asList(params));
}
origin: Ecwid/consul-api

  @Override
  public List<String> toUrlParameters() {
    List<String> params = new ArrayList<String>();

    // add basic params
    if (datacenter != null) {
      params.add("dc=" + Utils.encodeValue(datacenter));
    }

    if (consistencyMode != ConsistencyMode.DEFAULT) {
      params.add(consistencyMode.name().toLowerCase());
    }

    if (waitTime != -1) {
      params.add("wait=" + Utils.toSecondsString(waitTime));
    }

    if (index != -1) {
      params.add("index=" + Utils.toUnsignedString(index));
    }

    if (near != null) {
      params.add("near=" + Utils.encodeValue(near));
    }

    return params;
  }
}
origin: Ecwid/consul-api

private void checkUnsignedLongRange(long start, long end) throws Exception {
  for (long l = start; l < end; l++) {
    String str = Utils.toUnsignedString(l);
    long l2 = Utils.parseUnsignedLong(str);
    assertEquals(l, l2);
    if (l >= 0) {
      assertEquals(Long.toString(l), str);
      assertEquals(l, l2);
    }
  }
}
origin: com.ecwid.consul/consul-api

  @Override
  public List<String> toUrlParameters() {
    if (value != null) {
      return Collections.singletonList(key + "=" + Utils.encodeValue(value));
    } else {
      return Collections.singletonList(key);
    }
  }
}
origin: Ecwid/consul-api

@Test
public void testToSecondsString() throws Exception {
  assertEquals("1000s", Utils.toSecondsString(1000L));
}
origin: com.ecwid.consul/consul-api

private Long parseUnsignedLong(Header header) {
  if (header == null) {
    return null;
  }
  String value = header.getValue();
  if (value == null) {
    return null;
  }
  try {
    return Utils.parseUnsignedLong(value);
  } catch (Exception e) {
    return null;
  }
}
origin: Ecwid/consul-api

public static long parseUnsignedLong(String s) {
  if (s.charAt(0) == '-') {
    throw new NumberFormatException("An unsigned long was expected. Cannot parse negative number " + s);
  }
  int length = s.length();
  // Long.MAX_VALUE is 19 digits in length so anything
  // shorter than that is trivial to parse.
  if (length < 19) {
    return Long.parseLong(s);
  }
  long front = Long.parseLong(s.substring(0, length - 1));
  int onesDigit = Character.digit(s.charAt(length - 1), 10);
  if (onesDigit < 0) {
    throw new NumberFormatException("Invalid last digit for " + onesDigit);
  }
  long result = front * 10 + onesDigit;
  if (compareLong(result + Long.MIN_VALUE, front + Long.MIN_VALUE) < 0) {
    throw new NumberFormatException("The number " + s + " is greater than 2^64");
  }
  return result;
}
origin: com.ecwid.consul/consul-api

  @Override
  public List<String> toUrlParameters() {
    List<String> params = new ArrayList<String>();

    // add basic params
    if (datacenter != null) {
      params.add("dc=" + Utils.encodeValue(datacenter));
    }

    if (consistencyMode != ConsistencyMode.DEFAULT) {
      params.add(consistencyMode.name().toLowerCase());
    }

    if (waitTime != -1) {
      params.add("wait=" + Utils.toSecondsString(waitTime));
    }

    if (index != -1) {
      params.add("index=" + Utils.toUnsignedString(index));
    }

    if (near != null) {
      params.add("near=" + Utils.encodeValue(near));
    }

    return params;
  }
}
origin: Ecwid/consul-api

  @Override
  public List<String> toUrlParameters() {
    if (value != null) {
      return Collections.singletonList(key + "=" + Utils.encodeValue(value));
    } else {
      return Collections.singletonList(key);
    }
  }
}
origin: Ecwid/consul-api

  @Test
  public void queryParamsToUrlParameters_ShouldContainSetQueryParams_WithCorrectValuesApplied() {
    // Given
    final String EXPECTED_DATACENTER = "testDC";
    final ConsistencyMode EXPECTED_MODE = ConsistencyMode.CONSISTENT;
    final long EXPECTED_WAIT = 1000L;
    final long EXPECTED_INDEX = 2000L;
    final String EXPECTED_NEAR = "_agent";

    // When
    List<String> urlParameters = Builder.builder()
        .setDatacenter(EXPECTED_DATACENTER)
        .setConsistencyMode(EXPECTED_MODE)
        .setWaitTime(EXPECTED_WAIT)
        .setIndex(EXPECTED_INDEX)
        .setNear(EXPECTED_NEAR)
        .build()
        .toUrlParameters();

    // Then
    assertThat(urlParameters, hasItem("dc=" + EXPECTED_DATACENTER));
    assertThat(urlParameters, hasItem(EXPECTED_MODE.name().toLowerCase()));
    assertThat(urlParameters, hasItem("wait=" + Utils.toSecondsString(EXPECTED_WAIT)));
    assertThat(urlParameters, hasItem("index=" + EXPECTED_INDEX));
    assertThat(urlParameters, hasItem("near=" + EXPECTED_NEAR));
  }
}
origin: Ecwid/consul-api

private Long parseUnsignedLong(Header header) {
  if (header == null) {
    return null;
  }
  String value = header.getValue();
  if (value == null) {
    return null;
  }
  try {
    return Utils.parseUnsignedLong(value);
  } catch (Exception e) {
    return null;
  }
}
origin: com.ecwid.consul/consul-api

public static long parseUnsignedLong(String s) {
  if (s.charAt(0) == '-') {
    throw new NumberFormatException("An unsigned long was expected. Cannot parse negative number " + s);
  }
  int length = s.length();
  // Long.MAX_VALUE is 19 digits in length so anything
  // shorter than that is trivial to parse.
  if (length < 19) {
    return Long.parseLong(s);
  }
  long front = Long.parseLong(s.substring(0, length - 1));
  int onesDigit = Character.digit(s.charAt(length - 1), 10);
  if (onesDigit < 0) {
    throw new NumberFormatException("Invalid last digit for " + onesDigit);
  }
  long result = front * 10 + onesDigit;
  if (compareLong(result + Long.MIN_VALUE, front + Long.MIN_VALUE) < 0) {
    throw new NumberFormatException("The number " + s + " is greater than 2^64");
  }
  return result;
}
origin: Ecwid/consul-api

public static String generateUrl(String baseUrl, UrlParameters... params) {
  return generateUrl(baseUrl, Arrays.asList(params));
}
origin: com.ecwid.consul/consul-api

ConsulRawClient(HttpTransport httpTransport, String agentHost, int agentPort, String path) {
  this.httpTransport = httpTransport;
  // check that agentHost has scheme or not
  String agentHostLowercase = agentHost.toLowerCase();
  if (!agentHostLowercase.startsWith("https://") && !agentHostLowercase.startsWith("http://")) {
    // no scheme in host, use default 'http'
    agentHost = "http://" + agentHost;
  }
  this.agentAddress = Utils.assembleAgentAddress(agentHost, agentPort, path);
}
origin: Ecwid/consul-api

private String prepareUrl(String url) {
  if (url.contains(" ")) {
    // temp hack for old clients who did manual encoding and just use %20
    return Utils.encodeUrl(url);
  } else {
    return url;
  }
}
origin: Ecwid/consul-api

  @Override
  public List<String> toUrlParameters() {
    List<String> result = new ArrayList<String>();

    if (name != null) {
      result.add("name=" + Utils.encodeValue(name));
    }

    if (service != null) {
      result.add("service=" + Utils.encodeValue(service));
    }

    if (tag != null) {
      result.add("tag=" + Utils.encodeValue(tag));
    }

    if (node != null) {
      result.add("node=" + Utils.encodeValue(node));
    }

    return result;
  }
}
origin: Ecwid/consul-api

public RawResponse makeDeleteRequest(String endpoint, UrlParameters... urlParams) {
  String url = prepareUrl(agentAddress + endpoint);
  url = Utils.generateUrl(url, urlParams);
  return httpTransport.makeDeleteRequest(url);
}
origin: Ecwid/consul-api

  @Test
  public void testAssembleAgentAddressWithoutPath() {
    // Given
    String expectedHost = "https://host";
    int expectedPort = 8888;

    // When
    String actualAddress = Utils.assembleAgentAddress(expectedHost, expectedPort, null);

    // Then
    assertEquals(
        String.format("%s:%d", expectedHost, expectedPort),
        actualAddress
    );
  }
}
com.ecwid.consulUtils

Most used methods

  • assembleAgentAddress
  • encodeUrl
  • generateUrl
  • parseUnsignedLong
  • toSecondsString
  • toUnsignedString
  • compareLong
  • encodeValue

Popular in Java

  • Parsing JSON documents to java classes using gson
  • onCreateOptionsMenu (Activity)
  • startActivity (Activity)
  • onRequestPermissionsResult (Fragment)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now