本文整理汇总了Java中java.util.HashMap类的典型用法代码示例。如果您正苦于以下问题:Java HashMap类的具体用法?Java HashMap怎么用?Java HashMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HashMap类属于java.util包,在下文中一共展示了HashMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSongsByAlbum
import java.util.HashMap; //导入依赖的package包/类
private void findSongsByAlbum() {
// Create key list
keyList = new ArrayList<>();
songAlbumList = new HashMap<>();
// Go through songs
List<SongData> songList = getSongInfoList();
for (SongData songData: songList) {
String album = songData.getSongAlbum();
// Create new if album does not exist
if (!keyList.contains(album)) {
keyList.add(album);
songAlbumList.put(album, new ArrayList<SongData>());
}
songAlbumList.get(album).add(songData);
}
}
示例2: startWithoutTitle
import java.util.HashMap; //导入依赖的package包/类
@Test
public void startWithoutTitle()
{
Intent intent = new Intent();
final Bundle bundle = new Bundle();
bundle.putInt("description", R.string.app_name);
bundle.putSerializable("items", new HashMap<String, Integer>());
intent.putExtras(bundle);
ActivityController controller = Robolectric.buildActivity(ItemizeActivity.class, intent).create();
Activity activity = (Activity)controller.get();
controller.start();
assertTrue(activity.isFinishing());
String latestToast = ShadowToast.getTextOfLatestToast();
assertNotNull(latestToast);
}
示例3: testAsyncUpdateRow2
import java.util.HashMap; //导入依赖的package包/类
@Test
public void testAsyncUpdateRow2() {
Map<String,Object> updateValues = new HashMap<String,Object>();
updateValues.put(PERSON_FIRST_NAME, "Tennis");
updateValues.put(PERSON_AGE, 60);
Future<?> future = storageSource.updateRowAsync(PERSON_TABLE_NAME, "777-77-7777", updateValues);
waitForFuture(future);
try {
IResultSet resultSet = storageSource.getRow(PERSON_TABLE_NAME, "777-77-7777");
Object[][] expectedPersons = {{"777-77-7777", "Tennis", "Borg", 60, true}};
checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedPersons);
}
catch (Exception e) {
fail("Exception thrown in async storage operation: " + e.toString());
}
}
示例4: init
import java.util.HashMap; //导入依赖的package包/类
/**
* Initialize internal data structures
*/
public void init(Map<String, String> configParams) throws FloodlightModuleException {
this.moduleLoaderState = ModuleLoaderState.INIT;
// These data structures are initialized here because other
// module's startUp() might be called before ours
this.messageListeners = new ConcurrentHashMap<OFType, ListenerDispatcher<OFType, IOFMessageListener>>();
this.haListeners = new ListenerDispatcher<HAListenerTypeMarker, IHAListener>();
this.controllerNodeIPsCache = new HashMap<String, String>();
this.updates = new LinkedBlockingQueue<IUpdate>();
this.providerMap = new HashMap<String, List<IInfoProvider>>();
setConfigParams(configParams);
HARole initialRole = getInitialRole(configParams);
this.notifiedRole = initialRole;
this.shutdownService = new ShutdownServiceImpl();
this.roleManager = new RoleManager(this, this.shutdownService,
this.notifiedRole,
INITIAL_ROLE_CHANGE_DESCRIPTION);
this.timer = new HashedWheelTimer();
// Switch Service Startup
this.switchService.registerLogicalOFMessageCategory(LogicalOFMessageCategory.MAIN);
this.switchService.addOFSwitchListener(new NotificationSwitchListener());
this.counters = new ControllerCounters(debugCounterService);
}
示例5: handleRequestInternal
import java.util.HashMap; //导入依赖的package包/类
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
Map<String,Object> model = new HashMap<String,Object>();
model.put("summary", ProfilerControl.generateSummary());
model.put("profiles", ProfilerControl.getMethodProfiles());
return new ModelAndView("viewProfiling", model);
}
示例6: findPathVarIgnoreCaseTest
import java.util.HashMap; //导入依赖的package包/类
@Test
public void findPathVarIgnoreCaseTest() {
// Setup
final Request req = Mockito.mock(Request.class);
Mockito.when(req.params()).thenReturn(new HashMap<String, String>() {
{
put(":name", "Bob");
put(":Age", "21");
}
});
// Test
final String nameResult = GeneralUtils.findPathVarIgnoreCase(req, "NAME");
// Assertions
Assert.assertNotNull(nameResult);
Assert.assertEquals("Bob", nameResult);
// Test
final String ageResult = GeneralUtils.findPathVarIgnoreCase(req, "age");
// Assertions
Assert.assertNotNull(ageResult);
Assert.assertEquals("21", ageResult);
}
示例7: getRequestProperties
import java.util.HashMap; //导入依赖的package包/类
/**
* Returns an unmodifiable Map of general request
* properties for this connection. The Map keys
* are Strings that represent the request-header
* field names. Each Map value is a unmodifiable List
* of Strings that represents the corresponding
* field values.
*
* @return a Map of the general request properties for this connection.
* @throws IllegalStateException if already connected
* @since 1.4
*/
@Override
public synchronized Map<String, List<String>> getRequestProperties() {
if (connected)
throw new IllegalStateException("Already connected");
// exclude headers containing security-sensitive info
if (setUserCookies) {
return requests.getHeaders(EXCLUDE_HEADERS);
}
/*
* The cookies in the requests message headers may have
* been modified. Use the saved user cookies instead.
*/
Map<String, List<String>> userCookiesMap = null;
if (userCookies != null || userCookies2 != null) {
userCookiesMap = new HashMap<>();
if (userCookies != null) {
userCookiesMap.put("Cookie", Arrays.asList(userCookies));
}
if (userCookies2 != null) {
userCookiesMap.put("Cookie2", Arrays.asList(userCookies2));
}
}
return requests.filterAndAddHeaders(EXCLUDE_HEADERS2, userCookiesMap);
}
示例8: setOpenStackParams
import java.util.HashMap; //导入依赖的package包/类
private static void setOpenStackParams(VirtualizationConnectorDto vcDto,
String projectName,
String domainId,
String rabbitMquser,
String rabbitMqpassword,
String rabbitMqport,
String controllerTypeStr){
vcDto.setAdminDomainId(domainId);
vcDto.setAdminProjectName(projectName);
Map<String, String> providerAttributes = new HashMap<>();
providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_USER, rabbitMquser);
providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_USER_PASSWORD, rabbitMqpassword);
providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_PORT, rabbitMqport);
vcDto.setProviderAttributes(providerAttributes);
if (controllerTypeStr != null && (!controllerTypeStr.isEmpty())) {
vcDto.setControllerType(controllerTypeStr);
}
}
示例9: handleUpdate
import java.util.HashMap; //导入依赖的package包/类
@Override
protected WriteAttributeResults handleUpdate ( final Map<String, Variant> attributes, final OperationParameters operationParameters ) throws Exception
{
final Map<String, String> data = new HashMap<String, String> ();
final Variant active = attributes.get ( "active" ); //$NON-NLS-1$
final Variant factor = attributes.get ( "factor" ); //$NON-NLS-1$
final Variant offset = attributes.get ( "offset" ); //$NON-NLS-1$
if ( active != null && !active.isNull () )
{
data.put ( "active", active.asString () ); //$NON-NLS-1$
}
if ( factor != null && !factor.isNull () )
{
data.put ( "factor", factor.asString () ); //$NON-NLS-1$
}
if ( offset != null && !offset.isNull () )
{
data.put ( "offset", offset.asString () ); //$NON-NLS-1$
}
return updateConfiguration ( data, attributes, false, operationParameters );
}
示例10: jsonToHasMap
import java.util.HashMap; //导入依赖的package包/类
public static HashMap<String, Object> jsonToHasMap(JSONObject jsonObject) throws JSONException {
HashMap<String, Object> hs = new HashMap<String, Object>();
JSONObject object = jsonObject;
Iterator<?> iterator = object.keys();
while (iterator.hasNext()) {
String key = (String) iterator.next();
Object value = object.get(key);
if (value instanceof JSONObject) {
JSONObject jsonObject2 = new JSONObject(value.toString());
hs.put(key, jsonToHasMap(jsonObject2));
} else {
if (value instanceof JSONArray) {
JSONArray array = new JSONArray(value.toString());
List<HashMap<?, ?>> list = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
list.add(jsonToHasMap(array.getJSONObject(i)));
}
hs.put(key, list);
} else {
hs.put(key, value);
}
}
}
return hs;
}
示例11: onNextButtonClicked
import java.util.HashMap; //导入依赖的package包/类
@FXML
private void onNextButtonClicked() {
// Prevent proceeding when no rooms are selected
if(selectedRooms.size() <= 0) {
return;
}
Object temp = ScreenManager.getInstance().switchToScreen("/fxml/PlaceBookingScreen.fxml");
PlaceBookingScreenController controller = (PlaceBookingScreenController) temp;
Map<RoomCategory, Integer> roomsData = new HashMap<>();
LocalDate checkInDate = checkInDatePicker.getValue();
LocalDate checkOutDate = checkOutDatePicker.getValue();
selectedRooms.forEach((r) -> {
roomsData.merge(r.getRoomCategory(), 1, Integer::sum);
});
controller.initializeData(roomsData, this.packageQtys, checkInDate, checkOutDate);
}
示例12: getBasicSchemaGridRowList
import java.util.HashMap; //导入依赖的package包/类
/**
* pull out basicSchemaGridRow object from Schema object.
*
* @param targetTerminal
* @param link
* @return list of BasicSchemaGridRow
*/
public List<BasicSchemaGridRow> getBasicSchemaGridRowList(String targetTerminal, Link link) {
List<BasicSchemaGridRow> basicSchemaGridRows=null;
if(StringUtils.equalsIgnoreCase(Constants.INPUT_SUBJOB_COMPONENT_NAME, link.getSource().getComponentName())
||StringUtils.equalsIgnoreCase(Constants.SUBJOB_COMPONENT, link.getSource().getComponentName()))
{
Map<String,Schema> inputSchemaMap=(HashMap<String,Schema>)link.getSource().getProperties().
get(Constants.SCHEMA_FOR_INPUTSUBJOBCOMPONENT);
if(inputSchemaMap!=null &&inputSchemaMap.get(targetTerminal)!=null)
basicSchemaGridRows=SchemaSyncUtility.INSTANCE.
convertGridRowsSchemaToBasicSchemaGridRows(inputSchemaMap.get(targetTerminal).getGridRow());
}
else
{
Schema previousComponentSchema=SchemaPropagation.INSTANCE.getSchema(link);
if (previousComponentSchema != null)
basicSchemaGridRows=SchemaSyncUtility.INSTANCE.
convertGridRowsSchemaToBasicSchemaGridRows(previousComponentSchema.getGridRow());
}
return basicSchemaGridRows;
}
示例13: testsForHashMapNullKeysForbidden
import java.util.HashMap; //导入依赖的package包/类
private static Test testsForHashMapNullKeysForbidden() {
return wrappedHashMapTests(new WrappedHashMapGenerator() {
@Override Map<String, String> wrap(final HashMap<String, String> map) {
if (map.containsKey(null)) {
throw new NullPointerException();
}
return new AbstractMap<String, String>() {
@Override public Set<Map.Entry<String, String>> entrySet() {
return map.entrySet();
}
@Override public String put(String key, String value) {
checkNotNull(key);
return map.put(key, value);
}
};
}
}, "HashMap w/out null keys", ALLOWS_NULL_VALUES);
}
示例14: getAirEvent
import java.util.HashMap; //导入依赖的package包/类
private AirEvent getAirEvent(HashMap<String, KeyCode> codeDatas) {
AirEvent airEvent = null;
if (!Utility.isEmpty(codeDatas)) {
if (airVerSion == V3) {
airEvent = new AirV3Command(codeDatas);
} else {
airEvent = new AirV1Command(codeDatas);
}
}
// Map.Entry<String,KeyCode> entry;
// for(Iterator iterator = codeDatas.entrySet().iterator();iterator.hasNext();){
// entry = (Map.Entry<String, KeyCode>) iterator.next();
// entry.getKey();
// YourKeyCode yourKeyCode = new YourKeyCode();
// yourKeyCode.setSrcCode(entry.getValue().getSrcCode());
// }
return airEvent;
}
示例15: Z18TestJoinUserOrganisation3
import java.util.HashMap; //导入依赖的package包/类
@Test
public void Z18TestJoinUserOrganisation3(){
TestKit probe = new TestKit(system);
ActorRef subject = system.actorOf(props);
Request reqObj = new Request();
reqObj.setOperation(ActorOperations.JOIN_USER_ORGANISATION.getValue());
Map<String, Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.USER_ID,userId);
innerMap.put(JsonKey.ORGANISATION_ID,(orgId2+"456as"));
reqObj.getRequest().put(JsonKey.REQUESTED_BY,userIdnew);
Map<String, Object> request = new HashMap<String, Object>();
request.put(JsonKey.USER_ORG, innerMap);
reqObj.setRequest(request);
subject.tell(reqObj, probe.getRef());
probe.expectMsgClass(duration("200 second"), ProjectCommonException.class);
}