Java Code Examples for java.util.HashMap.entrySet()

The following are Jave code examples for showing how to use entrySet() of the java.util.HashMap 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: ServerlessPlatform   File: Monitoring.java   View Source Code Vote up 6 votes
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);			
	}
}
 
Example 2
Project: SayNoToMcLeaks   File: Metrics.java   View Source Code Vote up 6 votes
@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;
}
 
Example 3
Project: EpicBanRequests   File: Metrics.java   View Source Code Vote up 6 votes
@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;
}
 
Example 4
Project: ZooKeeper   File: Learner.java   View Source Code Vote up 5 votes
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);
}
 
Example 5
Project: EasyTransaction   File: EasyTransMsgInitializer.java   View Source Code Vote up 5 votes
@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();
}
 
Example 6
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: MQClientInstance.java   View Source Code Vote up 5 votes
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;
}
 
Example 7
Project: Ships   File: UsbUtils.java   View Source Code Vote up 5 votes
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;
}
 
Example 8
Project: GitHub   File: RecyclerViewCacheUtil.java   View Source Code Vote up 5 votes
/**
 * 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);
        }
    }
}
 
Example 9
Project: alfresco-repository   File: NodeChange.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 10
Project: Paper-Launcher   File: LauncherActivity.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
Project: Paper-Launcher   File: DictionaryUtil.java   View Source Code Vote up 5 votes
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;
}
 
Example 12
Project: personium-core   File: PersoniumRestAdapter.java   View Source Code Vote up 5 votes
/**
 * リクエストボディを受け取る 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;
}
 
Example 13
Project: jdk8u-jdk   File: FontConfiguration.java   View Source Code Vote up 5 votes
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;
}
 
Example 14
Project: android_viewtracker   File: TrackerUtil.java   View Source Code Vote up 5 votes
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;
}
 
Example 15
Project: human-mobility-modeling-utilities   File: DisplacementTest.java   View Source Code Vote up 5 votes
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);

}
 
Example 16
Project: Pogamut3   File: NavMeshAStarDistanceHeuristic.java   View Source Code Vote up 4 votes
protected void ensureTeleporterDistancesUpToDate( Location destination ) {
	if ( cachedDestination != null && cachedDestination.equals( destination ) ) {
		return;
	}
	
	cachedDestination = destination;
	
	// ensure teleporter locations have been initialized
	if ( teleporterToDistanceToCachedDestinationMap == null ) {
		teleporterToDistanceToCachedDestinationMap = Maps.newHashMap();
		for ( OffMeshPoint point : navMesh.getOffMeshPoints() ) {
			if ( point.getNavPoint().isTeleporter() ) {
				teleporterToDistanceToCachedDestinationMap.put( point, null );
			}
		}
	}
	
	// the complication here is that the agent may travel through multiple teleporters
	
	HashMap<Location, Double> sinkToDistanceMap = Maps.newHashMap();
	sinkToDistanceMap.put( destination, 0.0 );
	Set<OffMeshPoint> unusedTeleporters = Sets.newHashSet( teleporterToDistanceToCachedDestinationMap.keySet() );
	while ( unusedTeleporters.size() > 0 ) {
		// breadth search from the destination for the next closest teleport
		
		OffMeshPoint teleporterWithClosestExit = null;
		Double teleporterWithClosestExitCostEstimate = Double.POSITIVE_INFINITY;
		for ( OffMeshPoint candidateTeleporter : unusedTeleporters ) {
			assert( candidateTeleporter.getOutgoingEdges().size() == 1 ); // teleporter should have single exit
			Location candidateTeleporterExit = candidateTeleporter.getOutgoingEdges().iterator().next().getTo().getLocation();
			double candidateCostEstimate = Double.POSITIVE_INFINITY;
			for ( Entry<Location, Double> sinkEntry : sinkToDistanceMap.entrySet() ) {
				double sinkCostEstimate = candidateTeleporterExit.getDistance( sinkEntry.getKey() ) + sinkEntry.getValue();
				sinkCostEstimate = Math.min( candidateCostEstimate, sinkCostEstimate );
			}
			
			if ( candidateCostEstimate < teleporterWithClosestExitCostEstimate ) {
				teleporterWithClosestExit = candidateTeleporter;
				teleporterWithClosestExitCostEstimate = candidateCostEstimate;
			}
		}
		
		sinkToDistanceMap.put( teleporterWithClosestExit.getLocation(), teleporterWithClosestExitCostEstimate );
		teleporterToDistanceToCachedDestinationMap.put( teleporterWithClosestExit, teleporterWithClosestExitCostEstimate );
		unusedTeleporters.remove( teleporterWithClosestExit );
	}
}
 
Example 17
Project: BestConfig   File: TomcatConfigWrite.java   View Source Code Vote up 4 votes
@Override
public void writetoConfigfile(HashMap hm) {
	String iniConf = "data/server-initial.xml", updatedConf="data/server.xml";
	
	try {
		//we first read in the base line
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dbBuilder;
		dbBuilder = dbFactory.newDocumentBuilder();
		Document doc = dbBuilder.parse(new File(iniConf));
		
		//now we find the place to change
		NodeList connList = doc.getElementsByTagName("Connector");
		boolean done = false;
		for (int i = 0; i < connList.getLength() && !done; i++) {
			Node connNode = connList.item(i);
			if (connNode.getNodeType() == Node.ELEMENT_NODE) {
				 NamedNodeMap map = connNode.getAttributes();
				 for(int j=0;j<map.getLength() && !done;j++){
					 if(map.item(j).getNodeName().equals("port") &&
							 map.item(j).getNodeValue().equals("8080")){
						 /** now we update the config file as needed*/
						 Element ele = (Element)connNode;
						 for(Object obj : hm.entrySet()){
							 Map.Entry ent = (Map.Entry)obj;
							 ele.setAttribute(ent.getKey().toString(), ent.getValue().toString());
						 }
						 done=true;
					 }
				 }
			}
		}
		
		//updated! we write the config out to file
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
		Transformer transformer = transformerFactory.newTransformer();
		DOMSource source = new DOMSource(doc);
		StreamResult result = new StreamResult(new File(updatedConf));
		transformer.transform(source, result);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 18
Project: VanillaPlus   File: MenuManager.java   View Source Code Vote up 4 votes
public void start(ConfigurationSection section) {
	HashMap<String, LiteEntry<MessageManager,YamlConfiguration>> menusList = new HashMap<String, LiteEntry<MessageManager,YamlConfiguration>>();
	for(VanillaPlusExtension extension : toLoad){
		for(Entry<String, YamlConfiguration>c : loadMenus(new File(extension.getInstance().getDataFolder(),"Menu")).entrySet()){
			if(menusList.containsKey(c.getKey())){
				ErrorLogger.addError("Menu " + c.getKey() + " already exist !");
			}else{
				menusList.put(c.getKey(), new LiteEntry<MessageManager, YamlConfiguration>(extension.getMessageManager(), c.getValue()));
			}
		}
	}
	toInit = new HashMap<String, MediumEntry<MessageManager, Menu, ConfigurationSection>>();
	for (Entry<String, LiteEntry<MessageManager, YamlConfiguration>> entry : menusList.entrySet()) {
		if(entry.getKey() == null || entry.getKey() == null || entry.getKey().isEmpty())
			continue;
		ErrorLogger.addPrefix(entry.getKey() + ".yml");
		Menu menu = create(entry.getValue().getValue().getString(Node.TYPE.get(), Node.BASE.get()), entry.getValue().getKey(),
				entry.getValue().getValue());
		ErrorLogger.removePrefix();
		if(menu == null)
			continue;
		register(entry.getKey(), menu, true);
		toInit.put(entry.getKey()+".yml", new MediumEntry<MessageManager, Menu, ConfigurationSection>(entry.getValue().getKey(),
				menu, entry.getValue().getValue()));
	}
	Bukkit.getServer().getPluginManager().registerEvents(this, VanillaPlus.getInstance());
	Bukkit.getScheduler().scheduleSyncRepeatingTask(VanillaPlus.getInstance(), new Runnable() {
		private byte elapsedTenths;
		@Override
		public void run() {
			for (VPPlayer player : VanillaPlusCore.getPlayerManager().getOnlinePlayers()) {
				if(defaultMenu != null){
					if (defaultMenu.getRefresh() > 0)
						if (elapsedTenths % defaultMenu.getRefresh() == 0)
							defaultMenu.refresh(player, player.getPlayer().getInventory());
				}
				InventoryView view = player.getPlayer().getOpenInventory();
				if (view == null) {
					return;
				}
				Inventory topInventory = view.getTopInventory();
				if (topInventory.getHolder() instanceof MenuLink) {
					MenuLink menuHolder = (MenuLink) topInventory.getHolder();
					if (menuHolder.getIconMenu() instanceof Menu) {
						Menu extMenu = (Menu) menuHolder.getIconMenu();
						if (extMenu.getRefresh() > 0) {
							if (elapsedTenths % extMenu.getRefresh() == 0) {
								extMenu.refresh(player, topInventory);
							}
						}
					}
				}
			}
			elapsedTenths++;
			if(elapsedTenths > 30)
				elapsedTenths = 1;
		}
	}, 1, 20);
	anti_click_spam_delay = section.getInt(Node.DELAY.get(), 1000);
	if(section.contains("PLAYER_MENU")){
		ErrorLogger.addPrefix("PLAYER_MENU");
		defaultMenu = get(section.getString("PLAYER_MENU"), true);
		if(defaultMenu != null){
			if(defaultMenu.getSize()!=36)
				ErrorLogger.addError("Invalid size must be 36");
		}
		ErrorLogger.removePrefix();
	}
	
}
 
Example 19
Project: jaffa-framework   File: JaffaTransactionMessageService.java   View Source Code Vote up 4 votes
/**
 * Gets all Transactions that have the specified fields with the input values.
 * If there are more than one value for a key, this will return fields that have any of the specified values.
 *
 * @param fields the field name/value pairs
 * @return a collection of Transactions that contain the specified fields with the input values
 * @throws FrameworkException
 */
@Override
public Collection<Transaction> getTransactionsByFields(HashMap<String, List<Serializable>> fields) throws FrameworkException {
    UOW uow = null;
    List<Transaction> results = new ArrayList<Transaction>();
    try {
        uow = new UOW();
        Criteria transactionCriteria = new Criteria();
        transactionCriteria.setTable(TransactionMeta.getName());

        // add each field in the field map to the query
        for (Map.Entry<String, List<Serializable>> field : fields.entrySet()) {

            // if there is no field or values defined, skip to the next entry
            if ((field.getKey() == null) || field.getKey().isEmpty() || field.getValue().isEmpty()) {
                continue;
            }

            // if the value list has one entry, create a criteria
            if (field.getValue().size() == 1) {
                Criteria singleValueCriteria = new Criteria();
                singleValueCriteria.setTable(TransactionFieldMeta.getName());
                singleValueCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
                singleValueCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, field.getKey());
                if (field.getValue().get(0) == null) {
                    singleValueCriteria.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                } else {
                    singleValueCriteria.addCriteria(TransactionFieldMeta.VALUE, field.getValue().get(0));
                }
                transactionCriteria.addAggregate(singleValueCriteria);
                continue;
            }

            // if the value list has multiple entries, create an atomic criteria for each one
            Criteria multiValueCriteria = new AtomicCriteria();
            multiValueCriteria.setTable(TransactionFieldMeta.getName());
            multiValueCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
            multiValueCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, field.getKey());
            AtomicCriteria ac = new AtomicCriteria();
            for (Object value : field.getValue()) {

                // if the value is null, add a relational null criteria
                // check if this is the first criteria or an 'or' criteria when adding it
                if (value == null) {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    }
                } else {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, value);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, value);
                    }
                }
            }
            multiValueCriteria.addAtomic(ac);
            transactionCriteria.addAggregate(multiValueCriteria);
        }

        for (Object result : uow.query(transactionCriteria)) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            results.add((Transaction) result);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
 
Example 20
Project: SystemMonitorJFX   File: MainStage.java   View Source Code Vote up 2 votes
private void backgroudFinishCallback() {
	HashMap<String, CpuInfo> cpus = coresManager.getCPUsInfo();
	
	CpuInfo cpuInfo;
	XYChart.Data data;
	
	for (Entry<String, CpuInfo> entry: cpus.entrySet()) {
		Rectangle rect = new Rectangle(0, 0);
		rect.setVisible(false);
	
		cpuInfo = entry.getValue();
		data = new XYChart.Data(currentGraphPosition, cpuInfo.getUsage());
		data.setNode(rect);
		
		if (currentGraphPosition > MAX_DATA_POINTS) {	
			cpuInfo.getSeries().getData().remove(0);
		}
		
		cpuInfo.getSeries().getData().add(data);
		cpuInfo.getLabel().setText(cpuInfo.getName() + ": " + Math.round(cpuInfo.getUsage()) + "%");
	}
	
	
	
	OperatingSystemMXBean os = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
	
	//os.getTotalPhysicalMemorySize()
	
	double usedPercent = 100 * ((double) (1.0 -  ((double) os.getFreePhysicalMemorySize() / (double) os.getTotalPhysicalMemorySize())));
	
	//System.out.println("usedPercent: " + Runtime.getRuntime().freeMemory() / 1024);
	//System.out.println("usedPercent: " + Runtime.getRuntime().totalMemory()/ 1024);
	//System.out.println("        divi: " + ((double)Runtime.getRuntime().freeMemory()/(double)Runtime.getRuntime().totalMemory()));
	//System.out.println("\n\n");
	
	
	
	usedPercent = Math.round(usedPercent > 99.9? 100 : usedPercent);
	
	Rectangle memRect = new Rectangle(0, 0);
	memRect.setVisible(false);
	
	XYChart.Data memoryData = new XYChart.Data(currentGraphPosition, usedPercent);
	memoryData.setNode(memRect);
	
	memoryChart.setTitle("Uso de memória (" + usedPercent + "%)");
	
	if (currentGraphPosition > MAX_DATA_POINTS) {	
		memorySeries.getData().remove(0);
	}
	
	memorySeries.getData().add(memoryData);
	
	if (currentGraphPosition > MAX_DATA_POINTS) {
		xCPUAxis.setLowerBound(currentGraphPosition - MAX_DATA_POINTS);
		xCPUAxis.setUpperBound(currentGraphPosition);
		
		xMemoryAxis.setLowerBound(currentGraphPosition - MAX_DATA_POINTS);
		xMemoryAxis.setUpperBound(currentGraphPosition);
	}
	
	currentGraphPosition ++;
}