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(); }
/** Test of getValue method, of class KeyValuePair. */ @Test public void testGetValue() { final String key = "key"; final Integer value = 137; final KeyValuePair<String, Integer> instance = new KeyValuePair<>(key, value); Assert.assertEquals(value, instance.getValue()); }
/** Test of getValue method, of class KeyValuePair. */ @Test public void testGetValueBuilder() { 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(value, instance.getValue()); }
@Test public void keyValuePair_hashCode_strStr_emptyEmpty() { final KeyValuePair<String, String> keyValuePair = new KeyValuePair<String, String>(); assertNotNull("KeyValuePair should not be null", keyValuePair); final int keyValuePairHashCode = keyValuePair.hashCode(); assertEquals("Unexpected KeyValuePair.hashCode()", -62888490, keyValuePairHashCode); }
public Operand getSimplifiedOperand(Map<Operand, Operand> valueMap) { int i = 0; for (KeyValuePair kv : _pairs) { kv._key = kv._key.getSimplifiedOperand(valueMap); kv._value = kv._value.getSimplifiedOperand(valueMap); i++; } return this; }
@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); }
@Test public void keyValuePair_getValue_strStr_emptyPlasibo() { final KeyValuePair<String, String> keyValuePair = new KeyValuePair<String, String>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setValue("Plasibo"); final String string = keyValuePair.getValue(); assertEquals("Unexpected KeyValuePair.getValue()", "Plasibo", string); }
@Test public void keyValuePair_getValue_strInt_emptyNULL() { final KeyValuePair<String, Integer> keyValuePair = new KeyValuePair<String, Integer>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setValue(null); final Integer integer = keyValuePair.getValue(); assertNull("Unexpected KeyValuePair.getValue()", integer); }
@Test public void keyValuePair_hashCode_strStr_emptyPlasibo() { final KeyValuePair<String, String> keyValuePair = new KeyValuePair<String, String>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setValue("Plasibo"); final int keyValuePairHashCode = keyValuePair.hashCode(); assertEquals("Unexpected KeyValuePair.hashCode()", 1108021822, keyValuePairHashCode); }
@Test public void keyValuePair_hashCode_strStr_plasiboEmpty() { final KeyValuePair<String, String> keyValuePair = new KeyValuePair<String, String>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setKey("Plasibo"); final int keyValuePairHashCode = keyValuePair.hashCode(); assertEquals("Unexpected KeyValuePair.hashCode()", 311120094, keyValuePairHashCode); }
@Test public void keyValuePair_getValue_strBoo_emptyTRUE() { final KeyValuePair<String, Boolean> keyValuePair = new KeyValuePair<String, Boolean>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setValue(true); final Boolean bool = keyValuePair.getValue(); assertEquals("Unexpected KeyValuePair.getValue()", Boolean.TRUE, bool); }
@Test public void keyValuePair_getValue_strInt_emptyZero() { final KeyValuePair<String, Integer> keyValuePair = new KeyValuePair<String, Integer>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setValue(0); final Integer integer = keyValuePair.getValue(); assertEquals("Unexpected KeyValuePair.getValue()", Integer.valueOf(0), integer); }
@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); }
@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; }
@Test public void keyValuePair_hashCode_strInt_plasiboMIN() { final KeyValuePair<String, Integer> keyValuePair = new KeyValuePair<String, Integer>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setKey("Plasibo"); keyValuePair.setValue(Integer.MIN_VALUE); final int keyValuePairHashCode = keyValuePair.hashCode(); assertEquals("Unexpected KeyValuePair.hashCode()", -1836363554, keyValuePairHashCode); }
@Test public void keyValuePair_hashCode_strBoo_plasiboTRUE() { final KeyValuePair<String, Boolean> keyValuePair = new KeyValuePair<String, Boolean>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setKey("Plasibo"); keyValuePair.setValue(true); final int keyValuePairHashCode = keyValuePair.hashCode(); assertEquals("Unexpected KeyValuePair.hashCode()", 311121325, keyValuePairHashCode); }
@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); }
@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); }
@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); }
/** * 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; }
@Test public void keyValuePair_equals_strBoo_plasiboTRUE() { final KeyValuePair<String, Boolean> REF = STR_BOO_PLASIBO_TRUE; final KeyValuePair<String, Boolean> keyValuePair = new KeyValuePair<String, Boolean>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setKey("plasibo"); keyValuePair.setValue(false); assertFalse("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); keyValuePair.setValue(null); assertFalse("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); keyValuePair.setValue(true); assertTrue("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); }
@Test public void keyValuePair_equals_strStr_plasiboPlasibo() { final KeyValuePair<String, String> REF = STR_STR_PLASIBO_PLASIBO; final KeyValuePair<String, String> keyValuePair = new KeyValuePair<String, String>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setKey("plasibo"); keyValuePair.setValue(""); assertFalse("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); keyValuePair.setValue(null); assertFalse("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); keyValuePair.setValue("plasibo"); assertTrue("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); }
@Override public boolean contains(final KeyValuePair<Key, Value> item) { Value v = get(item.Key()); if (v == null) return false; return EqualityComparer.DEFAULT.Equals(v, item.Value()); }
@Override protected KeyValuePair<String, Integer> copyValueObject( final KeyValuePair<String, Integer> object) { return new KeyValuePair<>(object.getKey(), object.getValue()); }
@Test public void keyValuePair_equals_strInt_plasiboZero() { final KeyValuePair<String, Integer> REF = STR_INT_PLASIBO_ZERO; final KeyValuePair<String, Integer> keyValuePair = new KeyValuePair<String, Integer>(); assertNotNull("KeyValuePair should not be null", keyValuePair); keyValuePair.setKey("plasibo"); keyValuePair.setValue(Integer.MAX_VALUE); assertFalse("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); keyValuePair.setValue(Integer.MIN_VALUE); assertFalse("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); keyValuePair.setValue(null); assertFalse("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); keyValuePair.setValue(0); assertTrue("Unexpected KeyValuePair.equals(Object)", REF.equals(keyValuePair)); }
@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"); } }