本文整理匯總了Java中java.util.LinkedHashMap.put方法的典型用法代碼示例。如果您正苦於以下問題:Java LinkedHashMap.put方法的具體用法?Java LinkedHashMap.put怎麽用?Java LinkedHashMap.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.LinkedHashMap
的用法示例。
在下文中一共展示了LinkedHashMap.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: locateRoutes
import java.util.LinkedHashMap; //導入方法依賴的package包/類
@Override
protected LinkedHashMap<String, ZuulRoute> locateRoutes() {
LinkedHashMap<String, ZuulRoute> routesMap = new LinkedHashMap<String, ZuulRoute>();
//從application.properties中加載路由信息
routesMap.putAll(super.locateRoutes());
//從db中加載路由信息
routesMap.putAll(locateRoutesFromDB());
//優化一下配置
LinkedHashMap<String, ZuulRoute> values = new LinkedHashMap<>();
for (Map.Entry<String, ZuulRoute> entry : routesMap.entrySet()) {
String path = entry.getKey();
// Prepend with slash if not already present.
if (!path.startsWith("/")) {
path = "/" + path;
}
if (StringUtils.hasText(this.properties.getPrefix())) {
path = this.properties.getPrefix() + path;
if (!path.startsWith("/")) {
path = "/" + path;
}
}
values.put(path, entry.getValue());
}
return values;
}
示例2: getIndicesForQuery
import java.util.LinkedHashMap; //導入方法依賴的package包/類
public static LinkedHashMap<Integer, Integer> getIndicesForQuery(final String str,
final String query) {
final LinkedHashMap<Integer, Integer> indices = new LinkedHashMap<>();
final int start = org.apache.commons.lang3.StringUtils.indexOfIgnoreCase(str, query);
final int length = query.length();
indices.put(start, start + length);
int i = start + 1;
while ((i = org.apache.commons.lang3.StringUtils.indexOfIgnoreCase(str, query, i)) > 0) {
indices.put(i, i + length);
i += length;
}
return indices;
}
示例3: readGroupedEntryMap
import java.util.LinkedHashMap; //導入方法依賴的package包/類
protected static <T extends GroupedBiomeEntry> void readGroupedEntryMap(JsonObject o, LinkedHashMap<String, T> list, Class<T> clazz) {
for(Map.Entry<String, JsonElement> entry : o.entrySet()) {
EnumBiomeCategory category = EnumBiomeCategory.get(entry.getKey());
if (category == null) { continue; }
JsonObject cgroups = JsonUtil.asObject(entry.getValue());
for (Map.Entry<String, JsonElement> groupentry : cgroups.entrySet()) {
String group = groupentry.getKey();
JsonArray gbiomes = JsonUtil.asArray(groupentry.getValue());
for (JsonElement biome : gbiomes) {
T bd = IJsonable.create(clazz);
if(bd == null) { return; }
bd.fromJson(JsonUtil.asObject(biome));
bd.category = category;
bd.group = group;
list.put(bd.getMapKey(), bd);
}
}
}
}
示例4: serverBootStrapWithOptionsTest
import java.util.LinkedHashMap; //導入方法依賴的package包/類
@Test
public void serverBootStrapWithOptionsTest() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
LinkedHashMap<String, Object> channelHandlerOptions = new LinkedHashMap<String, Object>();
channelHandlerOptions.put("lineFrame", new LineBasedFrameDecoder(2000));
channelHandlerOptions.put("decoder", new StringDecoder());
channelHandlerOptions.put("encoder", new StringEncoder());
channelHandlerOptions.put("handler", new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
log.info("Message Received and forward to ConsumerProcessor. Msg -> {}", msg);
}
});
Server server = BootStrap.builder()
.port(5252)
.options(channelHandlerOptions)
.messageConsumer(msg -> log.info(msg))
.build();
assertNotNull(server);
}
示例5: test_LinkedHashMap
import java.util.LinkedHashMap; //導入方法依賴的package包/類
@Test
public void test_LinkedHashMap() throws Exception {
LinkedHashMap<String, String> data = new LinkedHashMap<String, String>();
data.put("1", "a");
data.put("2", "b");
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
Object read = deserialize.readObject();
assertTrue(read instanceof LinkedHashMap);
@SuppressWarnings("unchecked")
String key1 = ((LinkedHashMap<String, String>)read).entrySet().iterator().next().getKey();
assertEquals("1", key1);
assertEquals(data, read);
try {
deserialize.readObject();
fail();
} catch (IOException expected) {
}
}
示例6: actualAdapterWithTableNotToAdapt
import java.util.LinkedHashMap; //導入方法依賴的package包/類
@Test
public void actualAdapterWithTableNotToAdapt()
{
this.verifier.starting(this.description.get());
LinkedHashMap<String, VerifiableTable> tableMap = new LinkedHashMap<>();
tableMap.put("table1", TableTestUtils.ACTUAL);
tableMap.put("table2", TableTestUtils.ACTUAL_2);
this.verifier.withActualAdapter(ACTUAL_ADAPTER).withTablesNotToAdapt("table1")
.verify(tableMap);
this.verifier.succeeded(this.description.get());
}
示例7: getValues
import java.util.LinkedHashMap; //導入方法依賴的package包/類
public Map<String, Serializable> getValues()
{
LinkedHashMap<String, Serializable> answer = new LinkedHashMap<String, Serializable>();
for (String column : resultSet.getMetaData().getColumnNames())
{
answer.put(column, getValue(column));
}
return answer;
}
示例8: testGetAllTwoProfilesFromSessionAndRequest
import java.util.LinkedHashMap; //導入方法依賴的package包/類
@Test
public void testGetAllTwoProfilesFromSessionAndRequest() {
profiles.put(CLIENT1, PROFILE1);
context.setRequestAttribute(Pac4jConstants.USER_PROFILES, profiles);
final LinkedHashMap<String, CommonProfile> profiles2 = new LinkedHashMap<>();
profiles2.put(CLIENT2, PROFILE2);
context.setSessionAttribute(Pac4jConstants.USER_PROFILES, profiles2);
assertEquals(PROFILE1, profileManager.getAll(true).get(0));
assertEquals(PROFILE2, profileManager.getAll(true).get(1));
}
示例9: putOrAdd
import java.util.LinkedHashMap; //導入方法依賴的package包/類
protected static final void putOrAdd(LinkedHashMap<String, Object> map, LinkedList<Object> list, String name,
Object value) {
if (map == null) {
list.add(value);
} else {
map.put(name, value);
}
}
示例10: getResults
import java.util.LinkedHashMap; //導入方法依賴的package包/類
public LinkedHashMap<String, String> getResults() {
LinkedHashMap<String, String> results = new LinkedHashMap<>();
for (int i = 0; i < mCommands.length(); i++) {
try {
JSONObject command = mCommands.getJSONObject(i);
results.put(command.getString("path"), command.getString("command"));
} catch (JSONException ignored) {
}
}
return results;
}
示例11: sortHashMapByValues
import java.util.LinkedHashMap; //導入方法依賴的package包/類
/**
* Sorts LinkedHashMap by its values(natural descending order). keeps the
* duplicates as it is.
*
* @param passedMap
* An Object of type LinkedHashMap to be sorted by its values.
*
* @return An Object containing the sorted LinkedHashMap.
*/
private LinkedHashMap<String,String> sortHashMapByValues(LinkedHashMap<String,String> passedMap) {
List<String> mapKeys = new ArrayList<String>(passedMap.keySet());
List<String> mapValues = new ArrayList<String>(passedMap.values());
Collections.sort(mapValues, new ValueComparator());
Collections.sort(mapKeys);
Collections.reverse(mapValues);
LinkedHashMap<String,String> sortedMap = new LinkedHashMap<String,String>();
Iterator<String> valueIt = mapValues.iterator();
while (valueIt.hasNext()) {
String val = valueIt.next();
Iterator<String> keyIt = mapKeys.iterator();
while (keyIt.hasNext()) {
String key = keyIt.next();
String comp1 = passedMap.get(key).toString();
String comp2 = val.toString();
if (comp1.equals(comp2)) {
passedMap.remove(key);
mapKeys.remove(key);
sortedMap.put(key, val);
break;
}
}
}
return sortedMap;
}
示例12: weeklyAdjusted
import java.util.LinkedHashMap; //導入方法依賴的package包/類
public LinkedHashMap<LocalDate, Stock> weeklyAdjusted(String symbol, HashMap<String, String> options) throws UnsupportedEncodingException, InvalidApiKeyException, InvalidFunctionOptionException, MalFormattedFunctionException, MissingApiKeyException, UltraHighFrequencyRequestException {
String function = "TIME_SERIES_WEEKLY_ADJUSTED";
String queryString = ALPHA_VANTAGE_API_URL + "function=" + function + "&symbol=" + symbol + "&apikey=" + apiKey + "&";
String encodedUrl = options.keySet().stream().map(key -> {
try {
return key + "=" + UriUtils.encode(options.get(key), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}).collect(joining("&", queryString, ""));
LinkedHashMap<LocalDate, Stock> result = new LinkedHashMap<>();
JsonNode jsonNode = restTemplate.getForObject(encodedUrl, JsonNode.class);
Iterator<Map.Entry<String, JsonNode>> it = jsonNode.fields();
while (it.hasNext()) {
Map.Entry<String, JsonNode> mapEntry = it.next();
ExceptionUtil.handleException(mapEntry, function);
if (mapEntry.getKey().equals("Weekly Adjusted Time Series")) {
JsonNode node = mapEntry.getValue();
Iterator<Map.Entry<String, JsonNode>> timeSeriesIter = node.fields();
while (timeSeriesIter.hasNext()) {
Map.Entry<String, JsonNode> timeSeriesMap = timeSeriesIter.next();
LocalDate localDate = LocalDate.parse(timeSeriesMap.getKey(), DateTimeFormatter.ISO_LOCAL_DATE);
String open = String.valueOf(timeSeriesMap.getValue().get("1. open")).replaceAll("\"", "");
String high = String.valueOf(timeSeriesMap.getValue().get("2. high")).replaceAll("\"", "");
String low = String.valueOf(timeSeriesMap.getValue().get("3. low")).replaceAll("\"", "");
String close = String.valueOf(timeSeriesMap.getValue().get("4. close")).replaceAll("\"", "");
String volume = String.valueOf(timeSeriesMap.getValue().get("5. volume")).replaceAll("\"", "");
result.put(localDate, Stock.newStpckInstance(symbol, open, high, low, close, volume));
}
}
}
return result;
}
示例13: getUrlParameters
import java.util.LinkedHashMap; //導入方法依賴的package包/類
protected LinkedHashMap<String, String> getUrlParameters(Chain chain) {
final HttpUrl url = chain.request().url();
int size = url.querySize();
final LinkedHashMap<String, String> params = new LinkedHashMap<>();
for (int i = 0; i < size; i++) {
params.put(url.queryParameterName(i), url.queryParameterValue(i));
}
return params;
}
示例14: organizeEntries
import java.util.LinkedHashMap; //導入方法依賴的package包/類
/**
* Organizes the valid data extracted from the log entries into LinkedHashMap.
*
* @param store
* A global LinkedHashMap containing the processing elements (with
* time in milliseconds) in hierarchical structure.
* @param matchedPR
* A PR matching the given search string.
* @param bTime
* Time taken by the specific processing element.
* @param docName
* Name of the document being processed.
*/
@SuppressWarnings("unchecked")
private void organizeEntries(LinkedHashMap<String, Object> store,
String matchedPR, String bTime, String docName) {
allDocs.add(docName);
if (store.containsKey(matchedPR)) {
((LinkedHashMap<String, Object>) store.get(matchedPR))
.put(docName, bTime);
} else {
LinkedHashMap<String, Object> tempLHM = new LinkedHashMap<String, Object>();
tempLHM.put(docName, bTime);
store.put(matchedPR, tempLHM);
}
}
示例15: asMap
import java.util.LinkedHashMap; //導入方法依賴的package包/類
/**
* Returns a newly created LinkedHashMap mapping each key to its
* corresponding value, in the given order.
*/
public static <K, V> LinkedHashMap<K,V> asMap(K[] keys, V... values) {
LinkedHashMap<K,V> ans = new LinkedHashMap<K,V>();
for (int i = 0; i < keys.length && i < values.length; i++)
ans.put(keys[i], values[i]);
return ans;
}