Search in sources :

Example 36 with Entry

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();
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) PreparedStatement(java.sql.PreparedStatement)

Example 37 with Entry

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();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Entry(java.util.Map.Entry) HttpURLConnection(java.net.HttpURLConnection) OutputStream(java.io.OutputStream) IOException(java.io.IOException) URL(java.net.URL)

Example 38 with Entry

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;
}
Also used : Maps.immutableEntry(com.google.common.collect.Maps.immutableEntry) Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) MapTestSuiteBuilder(com.google.common.collect.testing.MapTestSuiteBuilder) Map(java.util.Map)

Example 39 with Entry

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);
    }
}
Also used : Entry(java.util.Map.Entry) EqualsTester(com.google.common.testing.EqualsTester)

Example 40 with Entry

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;
}
Also used : Entry(java.util.Map.Entry) TestSuite(junit.framework.TestSuite) TestStringListMultimapGenerator(com.google.common.collect.testing.google.TestStringListMultimapGenerator) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Aggregations

Entry (java.util.Map.Entry)1334 HashMap (java.util.HashMap)367 Map (java.util.Map)365 ArrayList (java.util.ArrayList)329 List (java.util.List)217 Iterator (java.util.Iterator)168 IOException (java.io.IOException)137 Test (org.junit.Test)89 LinkedHashMap (java.util.LinkedHashMap)84 Set (java.util.Set)79 HashSet (java.util.HashSet)74 File (java.io.File)67 Key (lucee.runtime.type.Collection.Key)63 Struct (lucee.runtime.type.Struct)60 Collection (java.util.Collection)54 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)47 TreeMap (java.util.TreeMap)43 LinkedList (java.util.LinkedList)41 Properties (java.util.Properties)35 StructImpl (lucee.runtime.type.StructImpl)34