コード例 #1
0
  public String encodeUriParameters(String baseUri) {
    StringBuffer buffer = baseUri != null ? new StringBuffer(baseUri) : new StringBuffer();

    boolean first = true;
    boolean needQueryStart = baseUri != null && baseUri.indexOf('?') == -1;

    for (KeyValuePair entry : parameterList) {
      String key = entry.getKey();
      String value = entry.getValue();

      if (key != null) {
        if (first) {
          first = false;
          if (needQueryStart) {
            buffer.append("?");
          }
        } else {
          buffer.append("&");
        }
        try {
          buffer.append(URLEncoder.encode(key, "UTF-8"));
          buffer.append("=");
          if (value != null) buffer.append(URLEncoder.encode(value, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
        }
      }
    }
    Log.d(TAG, "Generated = " + buffer.toString());
    return buffer.toString();
  }
コード例 #2
0
ファイル: KeyValuePairTest.java プロジェクト: pnnl/svf
  /** Test of getKey method, of class KeyValuePair. */
  @Test
  public void testGetKey() {
    final String key = "key";
    final Integer value = 137;
    final KeyValuePair<String, Integer> instance = new KeyValuePair<>(key, value);

    Assert.assertEquals(key, instance.getKey());
  }
コード例 #3
0
ファイル: KeyValuePairTest.java プロジェクト: pnnl/svf
  /** Test of getKey method, of class KeyValuePair. */
  @Test
  public void testGetKeyBuilder() {
    final String key = "key";
    final Integer value = 137;
    final KeyValuePair<String, Integer> instance =
        KeyValuePair.Builder.<String, Integer>construct().key(key).value(value).build();

    Assert.assertEquals(key, instance.getKey());
  }
コード例 #4
0
  @Test
  public void keyValuePair_getKey_strStr_plasiboPlasibo() {

    final KeyValuePair<String, String> keyValuePair = new KeyValuePair<String, String>();
    assertNotNull("KeyValuePair should not be null", keyValuePair);

    keyValuePair.setKey("Plasibo");

    final String key = keyValuePair.getKey();
    assertEquals("Unexpected KeyValuePair.getKey()", "Plasibo", key);
  }
コード例 #5
0
  @Test
  public void keyValuePair_constructor_strStr_NULLNULL() {

    final KeyValuePair<String, String> keyValuePair = new KeyValuePair<String, String>(null, null);
    assertNotNull("KeyValuePair should not be null", keyValuePair);

    final String key = keyValuePair.getKey();
    assertEquals("Unexpected KeyValuePair.getKey()", null, key);

    final String value = keyValuePair.getValue();
    assertEquals("Unexpected KeyValuePair.getValue()", null, value);
  }
コード例 #6
0
  @Override
  public <S, R> SmartMap<S, R> map(
      final UnaryFunction<KeyValuePair<S, R>, java.util.Map.Entry<K, V>> function) {
    SmartMap<S, R> resultMap = createNewInstance(new HashMap<S, R>());

    for (Map.Entry<K, V> entry : internalMap.entrySet()) {
      KeyValuePair<S, R> mappedEntry = function.apply(entry);
      resultMap.put(mappedEntry.getKey(), mappedEntry.getValue());
    }

    return resultMap;
  }
コード例 #7
0
  @Test
  public void keyValuePair_constructor_strBoo_plasiboTRUE() {

    final KeyValuePair<String, Boolean> keyValuePair =
        new KeyValuePair<String, Boolean>("plasibo", Boolean.TRUE);
    assertNotNull("KeyValuePair should not be null", keyValuePair);

    final String key = keyValuePair.getKey();
    assertEquals("Unexpected KeyValuePair.getKey()", "plasibo", key);

    final Boolean value = keyValuePair.getValue();
    assertEquals("Unexpected KeyValuePair.getValue()", Boolean.TRUE, value);
  }
コード例 #8
0
  @Test
  public void keyValuePair_constructor_strStr_plasiboEmpty() {

    final KeyValuePair<String, String> keyValuePair =
        new KeyValuePair<String, String>("plasibo", "");
    assertNotNull("KeyValuePair should not be null", keyValuePair);

    final String key = keyValuePair.getKey();
    assertEquals("Unexpected KeyValuePair.getKey()", "plasibo", key);

    final String value = keyValuePair.getValue();
    assertEquals("Unexpected KeyValuePair.getValue()", "", value);
  }
コード例 #9
0
  @Test
  public void keyValuePair_constructor_strInt_plasiboZero() {

    final KeyValuePair<String, Integer> keyValuePair =
        new KeyValuePair<String, Integer>("plasibo", 0);
    assertNotNull("KeyValuePair should not be null", keyValuePair);

    final String key = keyValuePair.getKey();
    assertEquals("Unexpected KeyValuePair.getKey()", "plasibo", key);

    final Integer value = keyValuePair.getValue();
    assertEquals("Unexpected KeyValuePair.getValue()", (Integer) 0, value);
  }
コード例 #10
0
  /**
   * Create a set of key value pair tags based on the input list. This is used internally by many
   * packing instructions.
   *
   * @param kvps <code>List<KeyValuePair></code> with the data to be formatted as key value pair
   *     tags.
   * @return <code>Tag</code> containing key value pairs.
   * @throws JargonException
   */
  protected Tag createKeyValueTag(final List<KeyValuePair> kvps) throws JargonException {
    /*
     * Must be like the following: <KeyValPair_PI> <ssLen>3</ssLen>
     * <keyWord>dataType</keyWord> <keyWord>destRescName</keyWord>
     * <keyWord>dataIncluded</keyWord> <svalue>generic</svalue>
     * <svalue>resourceB</svalue> <svalue></svalue> </KeyValPair_PI>
     */

    if (kvps == null) {
      throw new JargonException("kvps are null");
    }

    Tag pair = new Tag(KEY_VAL_PAIR_PI, new Tag(SS_LEN, 0));
    int ssLength = 0;

    // return the empty Tag if nothing was passed in
    if (kvps.size() == 0) {
      return pair;
    }

    // add keys
    for (KeyValuePair kvp : kvps) {
      pair.addTag(KEYWORD, kvp.getKey());
      ssLength++;
    }

    // just use index zero because they have to be in order...
    pair.getTags()[0].setValue(ssLength);
    if (ssLength == 0) {
      return pair;
    }

    // add values
    for (KeyValuePair kvp : kvps) {
      pair.addTag(S_VALUE, kvp.getValue());
    }

    if (log.isDebugEnabled()) {
      log.debug("kvp tag: {}", pair.parseTag());
    }

    return pair;
  }
コード例 #11
0
ファイル: MiscUtilTest.java プロジェクト: dvizzini/Util
  @Test
  public void testFindConstructor() {
    try {
      KeyValuePair keyValuePair =
          MiscUtil.findConstructor(
                  SpecialKeyValuePair.class, MiscUtilTest.class, ArrayList.class, Integer.class)
              .newInstance(this, new ArrayList<String>(), 0);
      System.out.println(keyValuePair.getKey());
      assertTrue(keyValuePair.getKey().equals("array"));
      assertTrue(keyValuePair.getValue().equals("list"));
    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception thrown");
    }

    try {
      KeyValuePair keyValuePair =
          MiscUtil.findConstructor(
                  SpecialKeyValuePair.class, MiscUtilTest.class, LinkedList.class, Integer.class)
              .newInstance(this, new LinkedList<String>(), 0);
      assertTrue(keyValuePair.getKey().equals("linked"));
      assertTrue(keyValuePair.getValue().equals("list"));
    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception thrown");
    }

    try {
      KeyValuePair keyValuePair =
          MiscUtil.findConstructor(
                  SpecialKeyValuePair.class, MiscUtilTest.class, ArrayDeque.class, Integer.class)
              .newInstance(this, new ArrayDeque<String>(), 0);
      assertTrue(keyValuePair.getKey().equals("array"));
      assertTrue(keyValuePair.getValue().equals("deque"));
    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception thrown");
    }

    //		try {
    //			KeyValuePair keyValuePair = MiscUtil.findConstructor(SpecialKeyValuePair.class,
    // MiscUtilTest.class, Iterable.class, Integer.class).newInstance(this, new
    // ArrayDeque<String>(), 0);
    //			assertTrue(keyValuePair.getKey().equals("iterable"));
    //			assertTrue(keyValuePair.getValue().equals("holler"));
    //		} catch (Exception e) {
    //			e.printStackTrace();
    //			fail("Exception thrown");
    //		}
    //
    try {
      KeyValuePair keyValuePair =
          MiscUtil.findConstructor(
                  SpecialKeyValuePair.class, MiscUtilTest.class, String.class, Integer.class)
              .newInstance(this, "whatever", 0);
      assertTrue(keyValuePair.getKey().equals("string"));
      assertTrue(keyValuePair.getValue().equals("holler"));
    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception thrown");
    }
  }
コード例 #12
0
ファイル: KeyValuePairTest.java プロジェクト: pnnl/svf
 @Override
 protected KeyValuePair<String, Integer> copyValueObject(
     final KeyValuePair<String, Integer> object) {
   return new KeyValuePair<>(object.getKey(), object.getValue());
 }