Example usage for java.util Map hashCode

List of usage examples for java.util Map hashCode

Introduction

In this page you can find the example usage for java.util Map hashCode.

Prototype

int hashCode();

Source Link

Document

Returns the hash code value for this map.

Usage

From source file:com.haulmont.cuba.gui.WindowManager.java

protected Integer getHash(WindowInfo windowInfo, Map<String, Object> params) {
    return windowInfo.hashCode() + params.hashCode();
}

From source file:uniko.west.topology.bolts.RoleAnalysisBolt.java

@Override
public void execute(Tuple input) {
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> message;
    try {//from  w ww  . j a  v a  2s  .  com
        message = mapper.readValue((String) input.getValue(0), Map.class);

        // Acknowledge the collector that we actually received the input
        this.collector.ack(input);

        // Calling the factory methods to create the internal community
        // structures from the tweets in the files.
        Logger.getLogger(RoleAnalysisBolt.class.getName()).log(Level.INFO, "Constructing community ...");
        Community seCommunity = StormCommunityFactory.parseCommunity("storm", message);
        int minLimit = 1;
        Logger.getLogger(RoleAnalysisBolt.class.getName()).log(Level.INFO,
                "Community Analysis, using minlimit: " + minLimit);
        HashSet<UserWithFeatures> uwf = CommunityAnalysis.analyseUserFeatures(seCommunity, minLimit);

        Logger.getLogger(RoleAnalysisBolt.class.getName()).log(Level.INFO, "Converting users ...");
        // Convert into UserWithRole objects suitable for Role analysis
        HashSet<UserWithRole> users = new HashSet<UserWithRole>();
        for (UserWithFeatures userFeatures : uwf) {
            UserWithRole u = userFeatures.convertToUserWithRole();
            users.add(u);
        }

        // Actual role analysis
        Logger.getLogger(RoleAnalysisBolt.class.getName()).log(Level.INFO,
                "Processing users (Role Analysis) ...");
        RoleAssociation ra = new RoleAssociation();
        ra.process(users);

        try (PrintStream out = new PrintStream(
                new File("/home/martin/test/roleAnalysisBolt/out" + message.hashCode() + ".log"), "UTF8")) {
            for (UserWithRole uwr : users) {
                out.println(uwr.id + "\t" + uwr.username + "\t" + uwr.role);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(RoleAnalysisBolt.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(RoleAnalysisBolt.class.getName()).log(Level.SEVERE, null, ex);
        }
        PServerConfiguration config = new PServerConfiguration();
        config.setClientName(this.clientName);
        config.setClientPass(this.clientPasswd);
        config.setHost(this.hostname);
        config.setMode(this.mode);
        PServerRoleClient pservRoleClient = new PServerRoleClient(config);

        // if(initServerData) {
        // pservRoleClient.initializePserverModel();
        // }
        // for (UserWithRole u : users) {
        // pservRoleClient.addUser(u);
        // }

    } catch (IOException ex) {
        Logger.getLogger(RoleAnalysisBolt.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.opendaylight.controller.topology.web.Topology.java

/**
 * Topology of nodes and hosts in the network in JSON format.
 *
 * Mainly intended for consumption by the visual topology.
 *
 * @return - JSON output for visual topology
 *//*from   ww w.j av  a 2s  .  c  om*/
@RequestMapping(value = "/visual.json", method = RequestMethod.GET)
@ResponseBody
public Collection<Map<String, Object>> getLinkData(@RequestParam(required = false) String container,
        HttpServletRequest request) {
    String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;

    // Derive the privilege this user has on the current container
    String userName = request.getUserPrincipal().getName();
    Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);

    if (privilege == Privilege.NONE) {
        return null;
    }

    ITopologyManager topologyManager = (ITopologyManager) ServiceHelper.getInstance(ITopologyManager.class,
            containerName, this);
    if (topologyManager == null) {
        return null;
    }
    ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
            containerName, this);
    if (switchManager == null) {
        return null;
    }

    Map<Node, Set<Edge>> nodeEdges = topologyManager.getNodeEdges();
    Map<Node, Set<NodeConnector>> hostEdges = topologyManager.getNodesWithNodeConnectorHost();
    int hostEdgesHashCode = getHostHashCode(hostEdges, topologyManager);
    List<Switch> nodes = switchManager.getNetworkDevices();

    List<SwitchConfig> switchConfigurations = new ArrayList<SwitchConfig>();
    for (Switch sw : nodes) {
        Node n = sw.getNode();
        SwitchConfig config = switchManager.getSwitchConfig(n.toString());
        switchConfigurations.add(config);
    }

    // initialize cache if needed
    if (!metaCache.containsKey(containerName)) {
        metaCache.put(containerName, new HashMap<String, Map<String, Object>>());
        // initialize hashes
        metaNodeHash.put(containerName, null);
        metaHostHash.put(containerName, null);
        metaNodeSingleHash.put(containerName, null);
        metaNodeConfigurationHash.put(containerName, null);
    }

    // return cache if topology hasn't changed
    if ((metaNodeHash.get(containerName) != null && metaHostHash.get(containerName) != null
            && metaNodeSingleHash.get(containerName) != null
            && metaNodeConfigurationHash.get(containerName) != null)
            && metaNodeHash.get(containerName).equals(nodeEdges.hashCode())
            && metaHostHash.get(containerName).equals(hostEdgesHashCode)
            && metaNodeSingleHash.get(containerName).equals(nodes.hashCode())
            && metaNodeConfigurationHash.get(containerName).equals(switchConfigurations.hashCode())) {
        return metaCache.get(containerName).values();
    }

    // cache has changed, we must assign the new values
    metaNodeHash.put(containerName, nodeEdges.hashCode());
    metaHostHash.put(containerName, hostEdgesHashCode);
    metaNodeSingleHash.put(containerName, nodes.hashCode());
    metaNodeConfigurationHash.put(containerName, switchConfigurations.hashCode());

    stagedNodes = new HashMap<String, Map<String, Object>>();
    newNodes = new HashMap<String, Map<String, Object>>();

    // nodeEdges addition
    addNodes(nodeEdges, topologyManager, switchManager, containerName);

    // single nodes addition
    addSingleNodes(nodes, switchManager, containerName);

    // hostNodes addition
    addHostNodes(hostEdges, topologyManager, containerName);

    repositionTopology(containerName);

    return metaCache.get(containerName).values();
}

From source file:com.wavemaker.json.JSONMarshallerTest.java

public void testValueTransformer() throws Exception {

    JSONState state = new JSONState();

    Map<String, Object> enclosed = new HashMap<String, Object>();
    enclosed.put("hi", "foo");

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("bar", enclosed);

    assertEquals("{\"bar\":{\"hi\":\"foo\"}}", JSONMarshaller.marshal(map, state));

    state.setValueTransformer(new ValueTransformer() {

        @Override/*from   www .  ja  va2  s.c o  m*/
        public Tuple.Three<Object, FieldDefinition, Integer> transformToJSON(Object input,
                FieldDefinition fieldDefinition, int arrayLevel, Object root, String path,
                TypeState typeState) {

            if ("bar.hi".equals(path)) {
                GenericFieldDefinition fd = new GenericFieldDefinition();
                fd.setTypeDefinition(typeState.getType(String.class.getName()));
                return new Tuple.Three<Object, FieldDefinition, Integer>(
                        input + " transformed, root: " + root.hashCode(), fd, 0);
            } else if ("bar.bye".equals(path)) {
                GenericFieldDefinition fd = new GenericFieldDefinition();
                fd.setTypeDefinition(typeState.getType(Short.TYPE.getName()));
                return new Tuple.Three<Object, FieldDefinition, Integer>(12, fd, 0);
            } else {
                return null;
            }
        }

        @Override
        public Tuple.Three<Object, FieldDefinition, Integer> transformToJava(Object input,
                FieldDefinition fieldDefinition, int arrayLevel, Object root, String path,
                TypeState typeState) {

            // unused in this test
            return null;
        }
    });

    assertEquals("{\"bar\":{\"hi\":\"foo transformed, root: " + map.hashCode() + "\"}}",
            JSONMarshaller.marshal(map, state));

    enclosed.remove("hi");
    enclosed.put("bye", "fdks");
    assertEquals("{\"bar\":{\"bye\":12}}", JSONMarshaller.marshal(map, state));
}

From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java

@Test
public void verifyOK() throws Exception {
    final Principal principal = mock(Principal.class);
    when(principal.getId()).thenReturn(PRINCIPAL_ID);

    final Authentication authentication = mock(Authentication.class);
    when(authentication.getPrincipal()).thenReturn(principal);

    final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class);
    when(ticketGrantingTicket.isExpired()).thenReturn(false);
    when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication);

    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket);

    final Map<String, Scope> scopeMap = new HashMap<>();
    scopeMap.put("scope1", new Scope("scope1", "description2"));
    scopeMap.put("scope2", new Scope("scope2", "description2"));

    final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class);
    when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap);

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID);
    mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE);
    mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, OAuthConstants.APPROVAL_PROMPT_FORCE);
    mockRequest.setSession(mockSession);

    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.setCentralOAuthService(centralOAuthService);
    oauth20WrapperController.afterPropertiesSet();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());

    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(scopeMap.hashCode(), map.get("scopeMap").hashCode());

    assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET));
}

From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java

@Test
public void verifyOKWhenBypassApprovalFalse() throws Exception {
    final Principal principal = mock(Principal.class);
    when(principal.getId()).thenReturn(PRINCIPAL_ID);

    final Authentication authentication = mock(Authentication.class);
    when(authentication.getPrincipal()).thenReturn(principal);

    final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class);
    when(ticketGrantingTicket.isExpired()).thenReturn(false);
    when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication);

    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket);

    final Map<String, Scope> scopeMap = new HashMap<>();
    scopeMap.put("scope1", new Scope("scope1", "description2"));
    scopeMap.put("scope2", new Scope("scope2", "description2"));

    final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class);
    when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap);

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID);
    mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE);
    mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, OAuthConstants.APPROVAL_PROMPT_FORCE);
    mockSession.putValue(OAuthConstants.BYPASS_APPROVAL_PROMPT, false);
    mockRequest.setSession(mockSession);

    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.setCentralOAuthService(centralOAuthService);
    oauth20WrapperController.afterPropertiesSet();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());

    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(scopeMap.hashCode(), map.get("scopeMap").hashCode());

    assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET));
}

From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java

@Test
public void verifyNoPromptWithoutExistingToken() throws Exception {
    final Principal principal = mock(Principal.class);
    when(principal.getId()).thenReturn(PRINCIPAL_ID);

    final Authentication authentication = mock(Authentication.class);
    when(authentication.getPrincipal()).thenReturn(principal);

    final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class);
    when(ticketGrantingTicket.isExpired()).thenReturn(false);
    when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication);

    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket);

    final Map<String, Scope> scopeMap = new HashMap<>();
    scopeMap.put("scope1", new Scope("scope1", "description2"));
    scopeMap.put("scope2", new Scope("scope2", "description2"));

    final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class);
    when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap);
    when(centralOAuthService.isAccessToken(TokenType.ONLINE, CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet()))
            .thenReturn(false);/*from  w ww . ja  v a  2  s  .  c o m*/
    when(centralOAuthService.isRefreshToken(CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())).thenReturn(true);

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID);
    mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID);
    mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.ONLINE);
    mockRequest.setSession(mockSession);

    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.setCentralOAuthService(centralOAuthService);
    oauth20WrapperController.afterPropertiesSet();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());

    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(scopeMap.hashCode(), map.get("scopeMap").hashCode());

    assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET));
}

From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java

@Test
public void verifyAutoPromptWithoutExistingToken() throws Exception {
    final Principal principal = mock(Principal.class);
    when(principal.getId()).thenReturn(PRINCIPAL_ID);

    final Authentication authentication = mock(Authentication.class);
    when(authentication.getPrincipal()).thenReturn(principal);

    final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class);
    when(ticketGrantingTicket.isExpired()).thenReturn(false);
    when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication);

    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket);

    final Map<String, Scope> scopeMap = new HashMap<>();
    scopeMap.put("scope1", new Scope("scope1", "description2"));
    scopeMap.put("scope2", new Scope("scope2", "description2"));

    final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class);
    when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap);
    when(centralOAuthService.isAccessToken(TokenType.ONLINE, CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet()))
            .thenReturn(true);//from   w w w . j ava  2s. com
    when(centralOAuthService.isRefreshToken(CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())).thenReturn(false);

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID);
    mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID);
    mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, "auto");
    mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE);
    mockRequest.setSession(mockSession);

    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.setCentralOAuthService(centralOAuthService);
    oauth20WrapperController.afterPropertiesSet();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());

    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(scopeMap.hashCode(), map.get("scopeMap").hashCode());

    assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET));
}

From source file:com.google.gwt.emultest.java.util.TreeMapTest.java

/**
 * Test method for 'java.lang.Object.hashCode()'.
 *
 * @see java.util.Map#hashCode()/*from   w  w  w. j a v a 2  s.  c  o  m*/
 */
public void testHashCode() {
    K[] keys = getKeys();
    V[] values = getValues();
    Map<K, V> map0 = createMap();
    Map<K, V> map1 = createMap();

    int hashCode0 = map0.hashCode();
    int hashCode1 = map1.hashCode();
    assertTrue("empty maps have different hash codes", hashCode0 == hashCode1);

    // Check that hashCode changes
    map0.put(keys[0], values[0]);
    hashCode0 = map0.hashCode();
    assertTrue("hash code didn't change", hashCode0 != hashCode1);

    // The above is actually not a completely dependable test because hash codes
    // are funky at the edges. The hash code of an abstract map is determined by
    // accumulating the hash code of the contained Entry(s). The TreeMap Entry
    // hash code implementation will always result in 0 if the exclusive or of
    // the key and value for the Entry is 0.

    Map<String, String> map2 = new TreeMap<String, String>();
    Map<Integer, Integer> map3 = new TreeMap<Integer, Integer>();

    map2.put("", "");

    map3.put(0, Integer.MIN_VALUE);
    map3.put(Integer.MIN_VALUE, 0);

    int hashCode2 = map2.hashCode();
    int hashCode3 = map3.hashCode();
    assertEquals("empty string/0 hash codes not the same", hashCode2, hashCode3);
}