Java Code Examples for java.util.Map.Entry

The following are Jave code examples for showing how to use Entry of the java.util.Map class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: HCFCore   File: ListOrderedMap.java   View Source Code Vote up 7 votes
/**
 * 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();
}
 
Example 2
Project: picocli   File: CommandLine.java   View Source Code Vote up 6 votes
/** 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();
}
 
Example 3
Project: abhot   File: SetMultimapDeserializer.java   View Source Code Vote up 6 votes
@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;
}
 
Example 4
Project: jspider   File: Charsets.java   View Source Code Vote up 6 votes
/**
 * 匹配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;
}
 
Example 5
Project: monarch   File: EvictionObjectSizerDUnitTest.java   View Source Code Vote up 6 votes
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());
      }
    }
  }
}
 
Example 6
Project: dubbo2   File: URL.java   View Source Code Vote up 6 votes
/**
* 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);
  }
 
Example 7
Project: JRediClients   File: AbstractCacheMap.java   View Source Code Vote up 6 votes
@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;
}
 
Example 8
Project: rkt-launcher   File: RktCommandHelper.java   View Source Code Vote up 5 votes
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();
}
 
Example 9
Project: fiery   File: Toolbox.java   View Source Code Vote up 5 votes
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();
}
 
Example 10
Project: EatDubbo   File: ConsumerServiceImpl.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
Project: ditb   File: LatencyStatistics.java   View Source Code Vote up 5 votes
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;
}
 
Example 12
Project: incubator-netbeans   File: DefaultClassPathProviderTest.java   View Source Code Vote up 5 votes
@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;
}
 
Example 13
Project: tangyuan2   File: CollectionUtils.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 14
Project: sstore-soft   File: AbstractMultimap.java   View Source Code Vote up 5 votes
@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;
}
 
Example 15
Project: openjdk-jdk10   File: TestJavaMethod.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 16
Project: GitHub   File: HostEditorFragment.java   View Source Code Vote up 5 votes
/**
 * Sets the Charset encoding data for the editor.
 * @param data A map from Charset display name to Charset value (i.e., unique ID for the
 *     Charset).
 */
public void setCharsetData(final Map<String, String> data) {
	mCharsetData = data;

	if (mEncodingText != null) {
		Iterator it = data.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry<String, String> pair = (Map.Entry) it.next();
			if (pair.getValue().equals(mHost.getEncoding())) {
				mEncodingText.setText(pair.getKey());
				return;
			}
		}
	}
}
 
Example 17
Project: pine-database   File: Table.java   View Source Code Vote up 5 votes
/**
 * Insert a list of field into the table.
 *
 * @param fields The list of fields.
 */
public void insert(Map<String, Object> fields) {
    //Setup insert fields
    StringBuilder setter = new StringBuilder();
    StringBuilder field = new StringBuilder();
    for (Map.Entry<String, Object> entry : fields.entrySet()) {
        field.append("`" + entry.getKey() + "`, ");
        setter.append("'" + entry.getValue() + "', ");
    }

    //Update query
    requestHandler.executeUpdate(Method.INSERT_INTO.getName() + quotesName + "(" +
            field.substring(0, field.length() - 2) + ") " + Method.VALUES.getName() +
            "(" + setter.substring(0, setter.length() - 2) + ")");
}
 
Example 18
Project: sstore-soft   File: AbstractMapBasedMultimap.java   View Source Code Vote up 4 votes
@Override
public Map.Entry<K, Collection<V>> next() {
  Map.Entry<K, Collection<V>> entry = delegateIterator.next();
  collection = entry.getValue();
  return wrapEntry(entry);
}
 
Example 19
Project: OpenJSharp   File: XmlSchemaGenerator.java   View Source Code Vote up 4 votes
/**
 * Write out the schema documents.
 */
public void write(SchemaOutputResolver resolver, ErrorListener errorListener) throws IOException {
    if(resolver==null)
        throw new IllegalArgumentException();

    if(logger.isLoggable(Level.FINE)) {
        // debug logging to see what's going on.
        logger.log(Level.FINE,"Wrigin XML Schema for "+toString(),new StackRecorder());
    }

    // make it fool-proof
    resolver = new FoolProofResolver(resolver);
    this.errorListener = errorListener;

    Map<String, String> schemaLocations = types.getSchemaLocations();

    Map<Namespace,Result> out = new HashMap<Namespace,Result>();
    Map<Namespace,String> systemIds = new HashMap<Namespace,String>();

    // we create a Namespace object for the XML Schema namespace
    // as a side-effect, but we don't want to generate it.
    namespaces.remove(WellKnownNamespace.XML_SCHEMA);

    // first create the outputs for all so that we can resolve references among
    // schema files when we write
    for( Namespace n : namespaces.values() ) {
        String schemaLocation = schemaLocations.get(n.uri);
        if(schemaLocation!=null) {
            systemIds.put(n,schemaLocation);
        } else {
            Result output = resolver.createOutput(n.uri,"schema"+(out.size()+1)+".xsd");
            if(output!=null) {  // null result means no schema for that namespace
                out.put(n,output);
                systemIds.put(n,output.getSystemId());
            }
        }
    }

    // then write'em all
    for( Map.Entry<Namespace,Result> e : out.entrySet() ) {
        Result result = e.getValue();
        e.getKey().writeTo( result, systemIds );
        if(result instanceof StreamResult) {
            OutputStream outputStream = ((StreamResult)result).getOutputStream();
            if(outputStream != null) {
                outputStream.close(); // fix for bugid: 6291301
            } else {
                final Writer writer = ((StreamResult)result).getWriter();
                if(writer != null) writer.close();
            }
        }
    }
}
 
Example 20
Project: directory-ldap-api   File: SchemaUtils.java   View Source Code Vote up 4 votes
/**
 * Renders the schema extensions into a new StringBuffer.
 *
 * @param extensions the schema extensions map with key and values
 * @return a StringBuffer with the extensions component of a syntax description
 */
public static StringBuilder render( Map<String, List<String>> extensions )
{
    StringBuilder buf = new StringBuilder();

    if ( extensions.isEmpty() )
    {
        return buf;
    }

    for ( Map.Entry<String, List<String>> entry : extensions.entrySet() )
    {
        buf.append( " " ).append( entry.getKey() ).append( " " );

        List<String> values = entry.getValue();

        // For extensions without values like X-IS-HUMAN-READIBLE
        if ( values == null || values.isEmpty() )
        {
            continue;
        }

        // For extensions with a single value we can use one qdstring like 'value'
        if ( values.size() == 1 )
        {
            buf.append( "'" ).append( values.get( 0 ) ).append( "' " );
            continue;
        }

        // For extensions with several values we have to surround whitespace
        // separated list of qdstrings like ( 'value0' 'value1' 'value2' )
        buf.append( "( " );
        for ( String value : values )
        {
            buf.append( "'" ).append( value ).append( "' " );
        }
        buf.append( ")" );
    }

    if ( buf.charAt( buf.length() - 1 ) != ' ' )
    {
        buf.append( " " );
    }

    return buf;
}