本文整理匯總了Java中java.util.Map.Entry方法的典型用法代碼示例。如果您正苦於以下問題:Java Map.Entry方法的具體用法?Java Map.Entry怎麽用?Java Map.Entry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Map
的用法示例。
在下文中一共展示了Map.Entry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toString
import java.util.Map; //導入方法依賴的package包/類
/**
* Returns the Map as a string.
*
* @return the Map as a String
*/
@Override
public String toString() {
if (isEmpty()) {
return "{}";
}
final StringBuilder buf = new StringBuilder();
buf.append('{');
boolean first = true;
for (final Map.Entry<K, V> entry : entrySet()) {
final K key = entry.getKey();
final V value = entry.getValue();
if (first) {
first = false;
} else {
buf.append(", ");
}
buf.append(key == this ? "(this Map)" : key);
buf.append('=');
buf.append(value == this ? "(this Map)" : value);
}
buf.append('}');
return buf.toString();
}
示例2: commandList
import java.util.Map; //導入方法依賴的package包/類
/** Returns a 2-column list with command names and the first line of their header or (if absent) description.
* @return a usage help section describing the added commands */
public String commandList() {
if (commands.isEmpty()) { return ""; }
int commandLength = maxLength(commands.keySet());
Help.TextTable textTable = new Help.TextTable(ansi(),
new Help.Column(commandLength + 2, 2, Help.Column.Overflow.SPAN),
new Help.Column(usageHelpWidth - (commandLength + 2), 2, Help.Column.Overflow.WRAP));
for (Map.Entry<String, Help> entry : commands.entrySet()) {
Help help = entry.getValue();
CommandSpec command = help.commandSpec;
String header = command.header() != null && command.header().length > 0 ? command.header()[0]
: (command.description() != null && command.description().length > 0 ? command.description()[0] : "");
textTable.addRowValues(colorScheme.commandText(entry.getKey()), ansi().new Text(header));
}
return textTable.toString();
}
示例3: deserialize
import java.util.Map; //導入方法依賴的package包/類
@Override
public SetMultimap<String, String> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
SetMultimap<String, String> map = HashMultimap.create();
JsonObject filters = json.getAsJsonObject();
for (Map.Entry<String, JsonElement> filter : filters.entrySet())
{
String name = filter.getKey();
JsonArray values = ((JsonArray)filter.getValue());
for (JsonElement value : values)
{
map.put(name, value.getAsString());
}
}
return map;
}
示例4: match
import java.util.Map; //導入方法依賴的package包/類
/**
* 匹配url獲取相應字符集
* @param url 網址
* @return 失敗返回null
*/
public String match(String url) {
String commonCharset = getCommonCharset();
if (commonCharset != null) {
return commonCharset;
}
String host = SpiderUrlUtils.getUrlHost(url);
if (host != null) {
for (Map.Entry<String, String> entry : charsets.entrySet()) {
if (host.contains(entry.getKey())) {
return entry.getValue();
}
}
}
return null;
}
示例5: verifySize
import java.util.Map; //導入方法依賴的package包/類
public static void verifySize(String regionName, int noOfElememts, int entrySize) {
final Region pr = cache.getRegion(regionName);
for (final Iterator i =
((PartitionedRegion) pr).getDataStore().getAllLocalBuckets().iterator(); i.hasNext();) {
final Map.Entry entry = (Map.Entry) i.next();
final BucketRegion bucketRegion = (BucketRegion) entry.getValue();
if (bucketRegion == null) {
continue;
} else {
AbstractLRURegionMap map = (AbstractLRURegionMap) bucketRegion.entries;
if (map == null || map.size() == 0) {
continue;
}
LogWriterUtils.getLogWriter().info("Checking for entry in bucket region: " + bucketRegion);
for (int counter = 1; counter <= noOfElememts; counter++) {
assertEquals(entrySize,
((AbstractLRURegionEntry) map.getEntry(new Integer(counter))).getEntrySize());
}
}
}
}
示例6: addParameters
import java.util.Map; //導入方法依賴的package包/類
/**
* Add parameters to a new url.
*
* @param parameters
* @return A new URL
*/
public URL addParameters(Map<String, String> parameters) {
if (parameters == null || parameters.size() == 0) {
return this;
}
boolean hasAndEqual = true;
for(Map.Entry<String, String> entry : parameters.entrySet()) {
String value = getParameters().get(entry.getKey());
if(value == null && entry.getValue() != null || !value.equals(entry.getValue())) {
hasAndEqual = false;
break;
}
}
// 如果沒有修改,直接返回。
if(hasAndEqual) return this;
Map<String, String> map = new HashMap<String, String>(getParameters());
map.putAll(parameters);
return new URL(protocol, username, password, host, port, path, map);
}
示例7: containsValue
import java.util.Map; //導入方法依賴的package包/類
@Override
public boolean containsValue(Object value) {
if (value == null) {
throw new NullPointerException();
}
for (Map.Entry<K, CachedValue<K, V>> entry : map.entrySet()) {
CachedValue<K, V> cachedValue = entry.getValue();
if (cachedValue.getValue().equals(value)) {
if (isValueExpired(cachedValue)) {
if (map.remove(cachedValue.getKey(), cachedValue)) {
onValueRemove(cachedValue);
}
} else {
readValue(cachedValue);
return true;
}
}
}
return false;
}
示例8: uri
import java.util.Map; //導入方法依賴的package包/類
static String uri(final URI apiHost,
final Map<String, List<String>> parameters,
final String... segments) {
final Builder builder = builder(apiHost, segments);
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
for (String value : entry.getValue()) {
builder.addQueryParameter(entry.getKey(), value);
}
}
return builder.build().toString();
}
示例9: properties2String
import java.util.Map; //導入方法依賴的package包/類
public static String properties2String(final Properties properties) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
if (entry.getValue() != null) {
sb.append(entry.getKey().toString())
.append("=").append(entry.getValue().toString())
.append("\n");
}
}
return sb.toString();
}
示例10: findAddressesByService
import java.util.Map; //導入方法依賴的package包/類
public List<String> findAddressesByService(String service) {
List<String> ret = new ArrayList<String>();
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
if(null == consumerUrls) return ret;
for(Map.Entry<Long, URL> e2 : consumerUrls.get(service).entrySet()) {
URL u = e2.getValue();
String app = u.getAddress();
if(app != null) ret.add(app);
}
return ret;
}
示例11: mergeWRSLatencies
import java.util.Map; //導入方法依賴的package包/類
public static WRSLatency mergeWRSLatencies(WRSLatency[] latencies) {
WRSLatency ret = new WRSLatency();
for (WRSLatency src : latencies) {
// merge write latency
if (src == null) {
new RuntimeException("meet WRSLatency null").printStackTrace();
continue;
}
for (int i = 0; i < src.writeStatistics.latencyBoxNumbers.length; i++) {
ret.writeStatistics.latencyBoxNumbers[i] += src.writeStatistics.latencyBoxNumbers[i];
}
ret.writeStatistics.totalLatency += src.writeStatistics.totalLatency;
ret.writeStatistics.totalCount += src.writeStatistics.totalCount;
ret.writeStatistics.maxLatency =
Math.max(ret.writeStatistics.maxLatency, src.writeStatistics.maxLatency);
// merge read latency
for (int i = 0; i < src.readStatistics.latencyBoxNumbers.length; i++) {
ret.readStatistics.latencyBoxNumbers[i] += src.readStatistics.latencyBoxNumbers[i];
}
ret.readStatistics.totalLatency += src.readStatistics.totalLatency;
ret.readStatistics.totalCount += src.readStatistics.totalCount;
ret.readStatistics.maxLatency =
Math.max(ret.readStatistics.maxLatency, src.readStatistics.maxLatency);
// merge scan latency
for (Map.Entry<String, Long> entry : src.scanTimes.entrySet()) {
long prevTime =
ret.scanTimes.containsKey(entry.getKey()) ? ret.scanTimes.get(entry.getKey()) : 0;
long prevCount =
ret.scanCounts.containsKey(entry.getKey()) ? ret.scanCounts.get(entry.getKey()) : 0;
ret.scanTimes.put(entry.getKey(), prevTime + entry.getValue());
ret.scanCounts.put(entry.getKey(), prevCount + src.scanCounts.get(entry.getKey()));
}
}
return ret;
}
示例12: getSourceLevel
import java.util.Map; //導入方法依賴的package包/類
@Override
public Result getSourceLevel(FileObject javaFile) {
for (Map.Entry<FileObject,R> e : this.levels.entrySet()) {
final FileObject root = e.getKey();
if (root.equals(javaFile) || FileUtil.isParentOf(root, javaFile)) {
return e.getValue();
}
}
return null;
}
示例13: unmodifiableMultiValueMap
import java.util.Map; //導入方法依賴的package包/類
/**
* Return an unmodifiable view of the specified multi-value map.
*
* @param map
* the map for which an unmodifiable view is to be returned.
* @return an unmodifiable view of the specified multi-value map.
* @since 3.1
*/
public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap(MultiValueMap<? extends K, ? extends V> map) {
Assert.notNull(map, "'map' must not be null");
Map<K, List<V>> result = new LinkedHashMap<K, List<V>>(map.size());
for (Map.Entry<? extends K, ? extends List<? extends V>> entry : map.entrySet()) {
List<V> values = Collections.unmodifiableList(entry.getValue());
result.put(entry.getKey(), values);
}
Map<K, List<V>> unmodifiableMap = Collections.unmodifiableMap(result);
return toMultiValueMap(unmodifiableMap);
}
示例14: putAll
import java.util.Map; //導入方法依賴的package包/類
@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
boolean changed = false;
for (Map.Entry<? extends K, ? extends V> entry : multimap.entries()) {
changed |= put(entry.getKey(), entry.getValue());
}
return changed;
}
示例15: getNameTest
import java.util.Map; //導入方法依賴的package包/類
@Test
public void getNameTest() {
for (Map.Entry<Method, ResolvedJavaMethod> e : methods.entrySet()) {
String expected = e.getKey().getName();
String actual = e.getValue().getName();
assertEquals(expected, actual);
}
}