use of java.util.Map.Entry in project translationstudio8 by heartsome.
the class DBOperator method insertBAttribute.
/**
* 写BAttribute的内容
* @param attrs
* @param parentName
* @param parentId
* @throws SQLException
* ;
*/
public void insertBAttribute(Map<String, String> attrs, String parentName, int parentId) throws SQLException {
if (attrs != null) {
PreparedStatement stmt = null;
String sql = dbConfig.getOperateDbSQL("insert-battribute");
Iterator<Entry<String, String>> iter = attrs.entrySet().iterator();
try {
while (iter.hasNext()) {
Entry<String, String> entry = iter.next();
String attrName = entry.getKey();
String attrValue = entry.getValue();
stmt = conn.prepareStatement(sql);
stmt.setInt(1, parentId);
stmt.setString(2, attrName);
stmt.setString(3, attrValue);
stmt.setString(4, parentName);
stmt.addBatch();
}
stmt.executeBatch();
stmt.clearBatch();
} finally {
if (stmt != null) {
stmt.close();
}
}
}
}
use of java.util.Map.Entry in project iosched by google.
the class ServerUtilities method post.
/**
* Issue a POST request to the server.
*
* @param endpoint POST address.
* @param params request parameters.
* @throws java.io.IOException propagated from POST.
*/
private static void post(String endpoint, Map<String, String> params, String key) throws IOException {
URL url;
try {
url = new URL(endpoint);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("invalid url: " + endpoint);
}
params.put("key", key);
StringBuilder bodyBuilder = new StringBuilder();
Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
// constructs the POST body using the parameters
while (iterator.hasNext()) {
Entry<String, String> param = iterator.next();
bodyBuilder.append(param.getKey()).append('=').append(param.getValue());
if (iterator.hasNext()) {
bodyBuilder.append('&');
}
}
String body = bodyBuilder.toString();
LOGW(TAG, "Posting to " + url);
LOGV(TAG, "Posting '" + body + "'");
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setChunkedStreamingMode(0);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
conn.setRequestProperty("Content-Length", Integer.toString(body.length()));
// post the request
OutputStream out = conn.getOutputStream();
out.write(body.getBytes());
out.close();
// handle the response
int status = conn.getResponseCode();
if (status != 200) {
throw new IOException("Post failed with error code " + status);
}
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
use of java.util.Map.Entry in project guava by google.
the class ImmutableTypeToInstanceMapTest method suite.
// problem with suite builders on Android
@AndroidIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ImmutableTypeToInstanceMapTest.class);
suite.addTest(MapTestSuiteBuilder.using(new TestTypeToInstanceMapGenerator() {
// Other tests will verify what real, warning-free usage looks like
// but here we have to do some serious fudging
@Override
@SuppressWarnings("unchecked")
public Map<TypeToken, Object> create(Object... elements) {
ImmutableTypeToInstanceMap.Builder<Object> builder = ImmutableTypeToInstanceMap.builder();
for (Object object : elements) {
Entry<TypeToken, Object> entry = (Entry<TypeToken, Object>) object;
builder.put(entry.getKey(), entry.getValue());
}
return (Map) builder.build();
}
}).named("ImmutableTypeToInstanceMap").withFeatures(MapFeature.REJECTS_DUPLICATES_AT_CREATION, MapFeature.RESTRICTS_KEYS, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY, MapFeature.ALLOWS_ANY_NULL_QUERIES).createTestSuite());
return suite;
}
use of java.util.Map.Entry in project guava by google.
the class PopulatedCachesTest method testKeySet_populated.
public void testKeySet_populated() {
for (LoadingCache<Object, Object> cache : caches()) {
Set<Object> keys = cache.asMap().keySet();
List<Entry<Object, Object>> warmed = warmUp(cache);
Set<Object> expected = Maps.newHashMap(cache.asMap()).keySet();
assertThat(keys).containsExactlyElementsIn(expected);
assertThat(keys.toArray()).asList().containsExactlyElementsIn(expected);
assertThat(keys.toArray(new Object[0])).asList().containsExactlyElementsIn(expected);
new EqualsTester().addEqualityGroup(cache.asMap().keySet(), keys).addEqualityGroup(ImmutableSet.of()).testEquals();
assertEquals(WARMUP_SIZE, keys.size());
for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) {
Object key = warmed.get(i - WARMUP_MIN).getKey();
assertTrue(keys.contains(key));
assertTrue(keys.remove(key));
assertFalse(keys.remove(key));
assertFalse(keys.contains(key));
}
checkEmpty(keys);
checkEmpty(cache);
}
}
use of java.util.Map.Entry in project guava by google.
the class ArrayListMultimapTest method suite.
// suite
@GwtIncompatible
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(ListMultimapTestSuiteBuilder.using(new TestStringListMultimapGenerator() {
@Override
protected ListMultimap<String, String> create(Entry<String, String>[] entries) {
ListMultimap<String, String> multimap = ArrayListMultimap.create();
for (Entry<String, String> entry : entries) {
multimap.put(entry.getKey(), entry.getValue());
}
return multimap;
}
}).named("ArrayListMultimap").withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES, MapFeature.GENERAL_PURPOSE, MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, CollectionFeature.SERIALIZABLE, CollectionSize.ANY).createTestSuite());
suite.addTestSuite(ArrayListMultimapTest.class);
return suite;
}
Aggregations