How to load a HashMap with all items from a Group<>

Posted on 2014-11-03
Medium Priority
Last Modified: 2014-11-08
C#.net guy, trying to write .java code; fumbling around on something that seems should be simple.

I have need to load a HashMap with a data that I am receiving from a class that is coming to be as a Group<>
Object model looks something like this;

VmGroupResource vmGroupResource = provider.getVmGroupResource(root.getVms());
Group<Vm> vms = vmGroupResource.getAllVms();

From there I need to put the data in the return data as a HashMap, but I get a type mismatch when I try to do;

(vccdata is the HashMap)
vccdata.putAll(Map) vms);

The IDE doesn't show me an error, but it throws an exception when debugging using NetBeans.
Question by:Michael Krumpe
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 16

Expert Comment

ID: 40419963
Best post your code with the exception so we can see it in situ.

Author Comment

by:Michael Krumpe
ID: 40420059
Working on that. Is my code though the proper way to push a Group<> into a a HashMap?
LVL 16

Accepted Solution

krakatoa earned 2000 total points
ID: 40420106
I don't recall Group being in the Java API.

Maybe you mean a collection, in which case you'd be referring to java Collections I reckon. In which case, pls take a shuftee at the API for it.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 86

Expert Comment

ID: 40420169
Group<Vm> itself would have to be a Map. Somehow that seems unlikely

Assisted Solution

by:Michael Krumpe
Michael Krumpe earned 0 total points
ID: 40420310
I am using an SDK provided class model. Drilling into the definition of Group, it looks like it is a type created in the class that extends Entity. It is pulling together some Json types from com.fasterxml.jackson.annotation, and then later adds
type, items, first, last, next, prev, build as interfaces.

the interface for .items is a List.

Thanks for pointing me in the direction to drill in a little more. That said, should I just treat it like a Collection and do:
for (Vm i: vms.getItems()) vccdata.put(i.getId(), i);

Open in new window

Should work... I think. Its giving me back 0 items as a size count. ... just want to make sure I'm doing it right before I bark up the SDK developer's tree.
LVL 16

Expert Comment

ID: 40420603
Not objecting as such to your close request, but wondering if you are entirely in the clear with it, given CEHJ's comment, and then my lack of full understanding of your requirements. Question.

Author Closing Comment

by:Michael Krumpe
ID: 40430074
Feedback pointed me in the right direction to see it as a collection, which needed to be treated as its own for loop.

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question