本文整理汇总了Java中java.util.HashMap.entrySet方法的典型用法代码示例。如果您正苦于以下问题:Java HashMap.entrySet方法的具体用法?Java HashMap.entrySet怎么用?Java HashMap.entrySet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashMap
的用法示例。
在下文中一共展示了HashMap.entrySet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChartData
import java.util.HashMap; //导入方法依赖的package包/类
@Override
protected JsonObject getChartData() {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
示例2: removeMachine
import java.util.HashMap; //导入方法依赖的package包/类
public void removeMachine(JSONObject jSon) {
String machineName=(String)jSon.get("removeMachine");
if(machineStats.containsKey(machineName)){
HashMap<String, Integer> svcInstances=machineStats.get(machineName).getInstances();
ArrayList<String>svcList=new ArrayList<>();
for(Entry<String, Integer> e : svcInstances.entrySet()) {
if(serviceStats.containsKey(e.getKey())) {
ServiceStats ss=serviceStats.get(e.getKey());
HashMap<String, Integer>tempHM=ss.getServiceList();
if(tempHM.containsKey(machineName)) {
tempHM.remove(machineName);
if (tempHM.size()==0) {
svcList.add(e.getKey());
}else {
ss.setServiceList(tempHM);
serviceStats.put(e.getKey(), ss);
}
}
}
}
for(Iterator<String> it=svcList.iterator();it.hasNext();)
serviceStats.remove(it.next());
machineStats.remove(machineName);
}
}
示例3: getChartData
import java.util.HashMap; //导入方法依赖的package包/类
@Override
protected JSONObject getChartData() {
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
HashMap<String, Integer> map = getValues(new HashMap<String, Integer>());
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.put(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.put("values", values);
return data;
}
示例4: ping
import java.util.HashMap; //导入方法依赖的package包/类
protected void ping(QuorumPacket qp) throws IOException {
// Send back the ping with our session data
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
HashMap<Long, Integer> touchTable = zk
.getTouchSnapshot();
for (Entry<Long, Integer> entry : touchTable.entrySet()) {
dos.writeLong(entry.getKey());
dos.writeInt(entry.getValue());
}
qp.setData(bos.toByteArray());
writePacket(qp, true);
}
示例5: init
import java.util.HashMap; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked" })
private void init(){
HashMap<String,List<String>> map = new HashMap<String, List<String>>();
//do initial
Set<Class<?>> transactionTypeSet = serviceWareHouse.getServiceTransactionTypeSet(MessageBusinessProvider.class);
for(Class<?> transactionType:transactionTypeSet){
List<Object> serviceMap = serviceWareHouse.getServices(MessageBusinessProvider.class, transactionType);
for(Object handler:serviceMap){
BusinessProvider<?> messageHandler = (BusinessProvider<?>) handler;
wrapToFilter(messageHandler);
Class<? extends EasyTransRequest<?, ?>> clazz = ReflectUtil.getRequestClass((Class<? extends BusinessProvider<?>>) messageHandler.getClass());
BusinessIdentifer businessIdentifer = ReflectUtil.getBusinessIdentifer(clazz);
List<String> list = map.get(businessIdentifer.appId());
if(list == null){
list = new ArrayList<String>();
map.put(businessIdentifer.appId(), list);
}
list.add(businessIdentifer.busCode());
}
}
//register listener to queue
for(Entry<String, List<String>> e:map.entrySet()){
consumer.subscribe(e.getKey(), e.getValue(), this);
}
consumer.start();
}
示例6: findBrokerAddressInAdmin
import java.util.HashMap; //导入方法依赖的package包/类
public FindBrokerResult findBrokerAddressInAdmin(final String brokerName) {
String brokerAddr = null;
boolean slave = false;
boolean found = false;
HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
if (map != null && !map.isEmpty()) {
FOR_SEG:
for (Map.Entry<Long, String> entry : map.entrySet()) {
Long id = entry.getKey();
brokerAddr = entry.getValue();
if (brokerAddr != null) {
found = true;
if (MixAll.MASTER_ID == id) {
slave = false;
break FOR_SEG;
} else {
slave = true;
}
break;
}
} // end of for
}
if (found) {
return new FindBrokerResult(brokerAddr, slave, findBrokerVersion(brokerName, brokerAddr));
}
return null;
}
示例7: retrieveAvailableUsbDevices
import java.util.HashMap; //导入方法依赖的package包/类
public static List<RtlSdrDevice> retrieveAvailableUsbDevices(final Context context) {
final List<RtlSdrDevice> result = new LinkedList<>();
if (usbSupported) {
final Object usbManagerObj=context.getSystemService(Context.USB_SERVICE);
if (usbManagerObj instanceof UsbManager) {
final UsbManager manager = (UsbManager) usbManagerObj;
retrieveSupportedDevices(context.getResources());
final HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
for (final Map.Entry<String, UsbDevice> desc : deviceList.entrySet()) {
final UsbDevice candidate = desc.getValue();
final Pair<Integer, Integer> candidatePair = new Pair<>(candidate.getVendorId(), candidate.getProductId());
SupportedDevice device = null;
for (int i = 0; i < supportedDevices.size() && device == null; i++) {
final SupportedDevice supportedDevice = supportedDevices.get(i);
if (supportedDevice.getVendorAndProductId().equals(candidatePair)) {
device = supportedDevice;
}
}
if (device != null) {
final String friendlyName = candidate.getDeviceName() + " " + device.getDescription() + " (" + candidate.getVendorId() + ":" + candidate.getProductId() + ")";
result.add(new RtlSdrDevice(candidate, friendlyName));
}
}
}
}
return result;
}
示例8: apply
import java.util.HashMap; //导入方法依赖的package包/类
/**
* init the cache on your own.
*
* @param recyclerView
* @param items
*/
public void apply(RecyclerView recyclerView, Iterable<Item> items) {
if (items != null) {
//we pre-create the views for our cache
HashMap<Integer, Stack<RecyclerView.ViewHolder>> cache = new HashMap<>();
for (Item d : items) {
if (!cache.containsKey(d.getType())) {
cache.put(d.getType(), new Stack<RecyclerView.ViewHolder>());
}
if (mCacheSize == -1 || cache.get(d.getType()).size() <= mCacheSize) {
cache.get(d.getType()).push(d.getViewHolder(recyclerView));
}
RecyclerView.RecycledViewPool recyclerViewPool = new RecyclerView.RecycledViewPool();
//we fill the pool
for (Map.Entry<Integer, Stack<RecyclerView.ViewHolder>> entry : cache.entrySet()) {
recyclerViewPool.setMaxRecycledViews(entry.getKey(), mCacheSize);
for (RecyclerView.ViewHolder holder : entry.getValue()) {
recyclerViewPool.putRecycledView(holder);
}
//make sure to clear the stack
entry.getValue().clear();
}
//make sure to clear the cache
cache.clear();
recyclerView.setRecycledViewPool(recyclerViewPool);
}
}
}
示例9: addVersionPropertiesToAuditMap
import java.util.HashMap; //导入方法依赖的package包/类
private void addVersionPropertiesToAuditMap(Map<String, Serializable> auditMap,
HashMap<String, Serializable> properties, boolean subAction)
{
for (Map.Entry<String, Serializable> entry: properties.entrySet())
{
// The key may be the string version ({URI}localName) of a QName.
// If so get the prefixed version.
String key = entry.getKey();
if (key.indexOf(QName.NAMESPACE_PREFIX) == 0)
{
try
{
QName qNameKey = QName.createQName(key);
qNameKey = getPrefixedQName(qNameKey);
key = qNameKey.toPrefixString();
}
catch (InvalidQNameException e)
{
// Its just a String.
}
}
String name = replaceInvalidPathChars(key);
auditMap.put(buildPath(VERSION_PROPERTIES, name), entry.getValue());
}
if (!subAction)
{
auditMap.put(VERSION_PROPERTIES, properties);
}
}
示例10: fetchCurrentIconPack
import java.util.HashMap; //导入方法依赖的package包/类
private IconPack fetchCurrentIconPack() {
HashMap<String, IconPack> iconPackHashMap = IconPackLoader.getAvailableIconPacks(this, false);
String iconPackPackageName = IconPackSelectHelper.get().getIconPack(this);
if (iconPackPackageName != null) {
for (Map.Entry<String, IconPack> entry : iconPackHashMap.entrySet()) {
if (entry.getKey().equals(iconPackPackageName)) {
return entry.getValue();
}
}
}
return null;
}
示例11: sortHashMapByValues
import java.util.HashMap; //导入方法依赖的package包/类
public static List<Map.Entry<String, Integer>> sortHashMapByValues(HashMap<String, Integer> hashMap) {
Set<Map.Entry<String, Integer>> set = hashMap.entrySet();
List<Map.Entry<String, Integer>> list = new ArrayList<>(set);
Collections.sort(list, (o1, o2) -> o2.getValue().compareTo(o1.getValue()));
return list;
}
示例12: post
import java.util.HashMap; //导入方法依赖的package包/类
/**
* リクエストボディを受け取る POSTメソッド.
* @param url リクエスト対象URL
* @param data 書き込むデータ
* @param headers リクエストヘッダのハッシュマップ
* @return DcResponse型
* @throws PersoniumException DAO例外
*/
public final PersoniumResponse post(final String url, final String data, final HashMap<String, String> headers)
throws PersoniumException {
String contentType = headers.get(HttpHeaders.CONTENT_TYPE);
HttpUriRequest req = makePostRequest(url, data, contentType);
for (Map.Entry<String, String> entry : headers.entrySet()) {
req.setHeader(entry.getKey(), entry.getValue());
}
req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());
debugHttpRequest(req, data);
PersoniumResponse res = request(req);
return res;
}
示例13: toList
import java.util.HashMap; //导入方法依赖的package包/类
private static short[] toList(HashMap<String, Short> map) {
short[] list = new short[map.size()];
Arrays.fill(list, (short) -1);
for (Entry<String, Short> entry : map.entrySet()) {
list[entry.getValue()] = getStringID(entry.getKey());
}
return list;
}
示例14: getHashMap
import java.util.HashMap; //导入方法依赖的package包/类
public static HashMap<String, String> getHashMap(HashMap<String, Object> map) {
HashMap<String, String> args = new HashMap<String, String>();
if (map != null && map.size() > 0) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (!TextUtils.isEmpty(entry.getKey()) && entry.getValue() != null) {
args.put(entry.getKey(), String.valueOf(entry.getValue()));
}
}
}
return args;
}
示例15: DisplacementTest
import java.util.HashMap; //导入方法依赖的package包/类
public DisplacementTest(){
super(new GridLayout(1,2));
loadData();
HashMap<Long, Double> values = null;
HashMap<Double, Double> probabilities = null;
try {
values = displacementTest();
} catch (InsufficientLocationTraceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
probabilities = DataHelper.log10(values);
double[][] plotValues = new double [probabilities.keySet().size()][2];
int index=0;
for(Entry<Double, Double> entry:probabilities.entrySet()){
plotValues[index][0] = entry.getKey();
plotValues[index][1] = entry.getValue();
index++;
}
PlotCanvas canvas = ScatterPlot.plot(plotValues);
canvas.setTitle("Displacement");
canvas.setAxisLabels("Log10 [ d ]", "Log10 [ p (d) ]");
add(canvas);
}