Example usage for java.util Map clear

List of usage examples for java.util Map clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the mappings from this map (optional operation).

Usage

From source file:ch.ralscha.extdirectspring.controller.RouterControllerSseTest.java

@Test
public void sseRequiredHeaderWithValue() throws Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("id", "1");

    HttpHeaders headers = new HttpHeaders();
    headers.add("header", "headerValue");
    headers.add("anotherName", "headerValue1");
    headers.add("anotherName", "headerValue2");

    List<SSEvent> events = ControllerUtil.performSseRequest(mockMvc, "sseProvider", "messageRequestHeader2",
            params, headers, null);/*from w w  w  .  j a v  a 2  s.  c om*/
    assertThat(events).hasSize(1);
    SSEvent event = events.get(0);

    assertThat(event.getEvent()).isNull();
    assertThat(event.getComment()).isNull();
    assertThat(event.getData()).startsWith("1;headerValue1");
    assertThat(event.getId()).isNull();
    assertThat(event.getRetry()).isNull();

    params.clear();
    params.put("id", "2");

    events = ControllerUtil.performSseRequest(mockMvc, "sseProvider", "messageRequestHeader2", params, null,
            null, true);
    assertThat(events).hasSize(1);
    event = events.get(0);

    assertThat(event.getEvent()).isEqualTo("error");
    assertThat(event.getComment()).isNull();
    assertThat(event.getData()).startsWith("Server Error");
    assertThat(event.getId()).isNull();
    assertThat(event.getRetry()).isNull();
}

From source file:com.greenline.hrs.admin.user.service.UserInfoService.java

/**
 * ?????//from w  w  w.  j  a  v  a  2 s .c o m
 *
 * @param offset ???
 * @param size   ??
 * @return , ??list.
 */
public List<UserNormalInfo> getUserInfoList(int offset, int size) {

    List<UserNickName> userNickNames = userNickNameBiz.getList(offset, size);
    if (userNickNames.isEmpty()) {
        return Collections.EMPTY_LIST;
    }
    Map<Long, UserNormalInfo> userNormalInfoMap = new HashMap<Long, UserNormalInfo>(userNickNames.size() * 2);
    List<Long> userIds = new ArrayList<Long>(userNickNames.size() * 2);
    List<UserNormalInfo> userNormalInfos = new ArrayList<UserNormalInfo>(userNickNames.size() * 2);
    UserNormalInfo userNormalInfo = null;
    for (UserNickName userNickName : userNickNames) {
        //?nickName?normalInfo
        userNormalInfo = new UserNormalInfo();
        userNormalInfo.setUid(userNickName.getUid());
        userNormalInfo.setNickName(userNickName.getNickName());
        userIds.add(userNickName.getUid());
        //normalInfoMap
        userNormalInfoMap.put(userNickName.getUid(), userNormalInfo);
    }
    //??,GC
    userNickNames.clear();

    List<UserBasicInfo> userBasicInfos = userBasicInfoBiz.getUserList(userIds);

    for (UserBasicInfo userBasicInfo : userBasicInfos) {
        //?uid???
        userNormalInfo = userNormalInfoMap.get(userBasicInfo.getUid());
        BeanUtils.copyProperties(userBasicInfo, userNormalInfo);
        userNormalInfos.add(userNormalInfo);
    }
    //??,GC
    userBasicInfos.clear();
    userNormalInfoMap.clear();

    return userNormalInfos;
}

From source file:com.inmobi.databus.partition.TestPartitionReaderWithLeastFullCheckpoint.java

@Test
public void testDeltaCheckpointWithStoptime() throws Exception {
    buffer.clear();//ww w  .  ja v a 2  s  .com
    String fsUri = fs.getUri().toString();
    Map<Integer, PartitionCheckpoint> expectedDeltaPchk = new HashMap<Integer, PartitionCheckpoint>();
    PartitionReaderStatsExposer prMetrics = new PartitionReaderStatsExposer(testStream, "c1",
            partitionId.toString(), consumerNumber, fsUri);
    Date startTime = DatabusStreamWaitingReader.getDateFromStreamDir(streamDir, databusFiles[1]);
    Calendar cal = Calendar.getInstance();
    cal.setTime(startTime);
    cal.add(Calendar.HOUR_OF_DAY, 1);
    cal.add(Calendar.MINUTE, -5);
    Date stopTime = cal.getTime();
    PartitionReader preader = new PartitionReader(partitionId, partitionCheckpointList, fs, buffer, streamDir,
            conf, inputFormatClass, startTime, 1000, isDatabusData(), prMetrics, false, partitionMinList,
            stopTime);
    preader.init();
    preader.execute();
    Date fromTime = getTimeStampFromFile(databusFiles[1]);
    Date toTime = getTimeStampFromFile(databusFiles[1]);
    TestUtil.prepareExpectedDeltaPck(fromTime, toTime, expectedDeltaPchk, null, streamDir, partitionMinList,
            partitionCheckpointList, true, false);
    TestUtil.assertBuffer(DatabusStreamWaitingReader.getHadoopStreamFile(fs.getFileStatus(databusFiles[1])), 2,
            00, 100, partitionId, buffer, isDatabusData(), expectedDeltaPchk);
    expectedDeltaPchk.clear();
    fromTime = getTimeStampFromFile(databusFiles[1]);
    toTime = getTimeStampFromFile(databusFiles[2]);
    TestUtil.prepareExpectedDeltaPck(fromTime, toTime, expectedDeltaPchk, fs.getFileStatus(databusFiles[1]),
            streamDir, partitionMinList, partitionCheckpointList, true, true);
    TestUtil.assertBuffer(DatabusStreamWaitingReader.getHadoopStreamFile(fs.getFileStatus(databusFiles[2])), 3,
            00, 100, partitionId, buffer, isDatabusData(), expectedDeltaPchk);
    expectedDeltaPchk.clear();
    fromTime = getTimeStampFromFile(databusFiles[2]);
    cal.add(Calendar.MINUTE, 1);
    toTime = cal.getTime();
    TestUtil.prepareExpectedDeltaPck(fromTime, toTime, expectedDeltaPchk, fs.getFileStatus(databusFiles[2]),
            streamDir, partitionMinList, partitionCheckpointList, false, true);
    QueueEntry entry = buffer.take();
    Assert.assertEquals(((DeltaPartitionCheckPoint) entry.getMessageChkpoint()).getDeltaCheckpoint(),
            expectedDeltaPchk);
    Assert.assertEquals(prMetrics.getLatestMinuteAlreadyRead(), stopTime.getTime());
}

From source file:io.cloudslang.lang.runtime.steps.ExecutableExecutionData.java

public void startExecutable(@Param(ScoreLangConstants.EXECUTABLE_INPUTS_KEY) List<Input> executableInputs,
        @Param(ScoreLangConstants.RUN_ENV) RunEnvironment runEnv,
        @Param(ScoreLangConstants.USER_INPUTS_KEY) Map<String, ? extends Value> userInputs,
        @Param(EXECUTION_RUNTIME_SERVICES) ExecutionRuntimeServices executionRuntimeServices,
        @Param(ScoreLangConstants.NODE_NAME_KEY) String nodeName,
        @Param(ScoreLangConstants.NEXT_STEP_ID_KEY) Long nextStepId,
        @Param(ScoreLangConstants.EXECUTABLE_TYPE) ExecutableType executableType) {
    try {/*  ww  w. j  a v  a2s . co m*/
        Map<String, Value> callArguments = runEnv.removeCallArguments();

        if (userInputs != null) {
            callArguments.putAll(userInputs);
        }
        LanguageEventData.StepType stepType = LanguageEventData.convertExecutableType(executableType);
        sendStartBindingInputsEvent(executableInputs, runEnv, executionRuntimeServices,
                "Pre Input binding for " + stepType, stepType, nodeName, callArguments);

        Map<String, Value> boundInputValues = inputsBinding.bindInputs(executableInputs, callArguments,
                runEnv.getSystemProperties());

        Map<String, Value> actionArguments = new HashMap<>();

        actionArguments.putAll(boundInputValues);

        //done with the user inputs, don't want it to be available in next startExecutable steps..
        if (userInputs != null) {
            userInputs.clear();
        }

        updateCallArgumentsAndPushContextToStack(runEnv, new Context(boundInputValues), actionArguments);

        sendEndBindingInputsEvent(executableInputs, boundInputValues, runEnv, executionRuntimeServices,
                "Post Input binding for " + stepType, stepType, nodeName, callArguments);

        executionRuntimeServices.setShouldCheckGroup();

        // put the next step position for the navigation
        runEnv.putNextStepPosition(nextStepId);
        runEnv.getExecutionPath().down();
    } catch (RuntimeException e) {
        logger.error("There was an error running the start executable execution step of: \'" + nodeName
                + "\'.\n\tError is: " + e.getMessage());
        throw new RuntimeException("Error running: \'" + nodeName + "\'.\n\t " + e.getMessage(), e);
    }
}

From source file:com.esd.ps.EmployerController.java

/**
 * //from   ww w .  j  a v  a2 s  . c  o m
 * @param packId
 * @param markTimeMethodId
 * @param markTimeMethodName
 * @return
 */
@RequestMapping(value = "/updateMarkTimeMethodpackId", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateMarkTimeMethodpackIdPOST(int packId, int markTimeMethodId,
        String markTimeMethodName) {
    logger.debug("packId:{},markTimeMethodId:{},markTimeMethodName:{}", packId, markTimeMethodId,
            markTimeMethodName);
    Map<String, Object> map = new HashMap<>();
    markTimeMethod markTimeMethod = markTimeMethodService.getByPrimaryKey(markTimeMethodId);
    packWithBLOBs pack = new packWithBLOBs();
    pack.setPackId(packId);
    pack.setTaskMarkTimeId(markTimeMethodId);
    pack.setTaskMarkTimeName(markTimeMethod.getName());

    packService.updateByPrimaryKeySelective(pack);
    map.clear();
    map.put(Constants.REPLAY, 1);
    return map;
}

From source file:com.l2jfree.gameserver.model.entity.Hero.java

public synchronized void computeNewHeroes(List<StatsSet> newHeroes) {
    updateHeroes(true);/*from   www.  j  a  v  a2s .c o m*/

    if (!_heroes.isEmpty()) {
        for (StatsSet hero : _heroes.values()) {
            String name = hero.getString(Olympiad.CHAR_NAME);

            L2Player player = L2World.getInstance().getPlayer(name);

            if (player == null)
                continue;
            try {
                player.setHero(false);

                for (int i = 0; i < Inventory.PAPERDOLL_TOTALSLOTS; i++) {
                    L2ItemInstance equippedItem = player.getInventory().getPaperdollItem(i);
                    if (equippedItem != null && equippedItem.isHeroItem())
                        player.getInventory().unEquipItemInSlotAndRecord(i);
                }

                for (L2ItemInstance item : player.getInventory().getAvailableItems(false, true)) {
                    if (item != null && item.isHeroItem()) {
                        player.destroyItem("Hero", item, null, true);

                        InventoryUpdate iu = new InventoryUpdate();
                        iu.addRemovedItem(item);
                        player.sendPacket(iu);
                    }
                }

                player.broadcastUserInfo();
            } catch (NullPointerException e) {
                _log.warn("", e);
            }
        }
    }

    if (newHeroes.size() == 0) {
        _heroes.clear();
        return;
    }

    Map<Integer, StatsSet> heroes = new FastMap<Integer, StatsSet>();

    for (StatsSet hero : newHeroes) {
        int charId = hero.getInteger(Olympiad.CHAR_ID);

        if (_completeHeroes != null && _completeHeroes.containsKey(charId)) {
            StatsSet oldHero = _completeHeroes.get(charId);
            int count = oldHero.getInteger(COUNT);
            oldHero.set(COUNT, count + 1);
            oldHero.set(PLAYED, 1);

            heroes.put(charId, oldHero);
        } else {
            StatsSet newHero = new StatsSet();
            newHero.set(Olympiad.CHAR_NAME, hero.getString(Olympiad.CHAR_NAME));
            newHero.set(Olympiad.CLASS_ID, hero.getInteger(Olympiad.CLASS_ID));
            newHero.set(COUNT, 1);
            newHero.set(PLAYED, 1);

            heroes.put(charId, newHero);
        }
    }

    deleteItemsInDb();
    deleteSkillsInDb();

    _heroes.clear();
    _heroes.putAll(heroes);
    heroes.clear();

    updateHeroes(false);

    for (StatsSet hero : _heroes.values()) {
        String name = hero.getString(Olympiad.CHAR_NAME);

        L2Player player = L2World.getInstance().getPlayer(name);

        if (player != null) {
            player.broadcastPacket(new SocialAction(player.getObjectId(), 16));
            player.setHero(true);
            L2Clan clan = player.getClan();
            if (clan != null) {
                clan.setReputationScore(clan.getReputationScore() + Config.HERO_POINTS, true);
                SystemMessage sm = new SystemMessage(
                        SystemMessageId.CLAN_MEMBER_C1_BECAME_HERO_AND_GAINED_S2_REPUTATION_POINTS);
                sm.addString(name);
                sm.addNumber(Config.HERO_POINTS);
                clan.broadcastToOnlineMembers(sm);
            }
            player.broadcastUserInfo();

            for (L2Skill skill : HeroSkillTable.getHeroSkills())
                player.addSkill(skill);
        } else {
            Connection con = null;

            try {
                con = L2DatabaseFactory.getInstance().getConnection(con);
                PreparedStatement statement = con.prepareStatement(GET_CLAN_NAME);
                statement.setString(1, name);
                ResultSet rset = statement.executeQuery();
                if (rset.next()) {
                    String clanName = rset.getString("clan_name");
                    if (clanName != null) {
                        L2Clan clan = ClanTable.getInstance().getClanByName(clanName);
                        if (clan != null) {
                            clan.setReputationScore(clan.getReputationScore() + Config.HERO_POINTS, true);
                            SystemMessage sm = new SystemMessage(
                                    SystemMessageId.CLAN_MEMBER_C1_BECAME_HERO_AND_GAINED_S2_REPUTATION_POINTS);
                            sm.addString(name);
                            sm.addNumber(Config.HERO_POINTS);
                            clan.broadcastToOnlineMembers(sm);
                        }
                    }
                }

                rset.close();
                statement.close();
            } catch (Exception e) {
                _log.warn("HeroSystem: Couldnt get Clanname of " + name, e);
            } finally {
                L2DatabaseFactory.close(con);
            }
        }
    }
}

From source file:jp.aegif.nemaki.cmis.aspect.type.impl.TypeManagerImpl.java

private TypeDefinitionContainer removeProeprtyDefinition(TypeDefinitionContainer tdc) {
    // Remove from its own typeDefinition
    TypeDefinition tdf = tdc.getTypeDefinition();
    TypeDefinition copy = DataUtil.copyTypeDefinition(tdf);
    Map<String, PropertyDefinition<?>> propDefs = copy.getPropertyDefinitions();
    if (MapUtils.isNotEmpty(propDefs)) {
        propDefs.clear();
    }/*from   ww  w. j av a2s.co m*/
    TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl(copy);

    // Remove from children recursively
    List<TypeDefinitionContainer> children = tdc.getChildren();
    if (CollectionUtils.isNotEmpty(children)) {
        List<TypeDefinitionContainer> l = new ArrayList<TypeDefinitionContainer>();
        for (TypeDefinitionContainer child : children) {
            l.add(removeProeprtyDefinition(child));
        }
        result.setChildren(l);
    }

    return result;
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerSseTest.java

@Test
public void sseRequiredCookieWithValue() throws Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("id", "1");

    List<Cookie> cookies = new ArrayList<Cookie>();
    cookies.add(new Cookie("cookie", "cookieValue"));
    cookies.add(new Cookie("anotherName", "cookieValue1"));
    cookies.add(new Cookie("anotherName", "cookieValue2"));

    List<SSEvent> events = ControllerUtil.performSseRequest(mockMvc, "sseProvider", "messageCookieValue2",
            params, null, cookies);/*from   w w  w .j ava 2 s. c om*/
    assertThat(events).hasSize(1);
    SSEvent event = events.get(0);

    assertThat(event.getEvent()).isNull();
    assertThat(event.getComment()).isNull();
    assertThat(event.getData()).startsWith("1;cookieValue1");
    assertThat(event.getId()).isNull();
    assertThat(event.getRetry()).isNull();

    params.clear();
    params.put("id", "2");

    events = ControllerUtil.performSseRequest(mockMvc, "sseProvider", "messageCookieValue2", params, null, null,
            true);
    assertThat(events).hasSize(1);
    event = events.get(0);

    assertThat(event.getEvent()).isEqualTo("error");
    assertThat(event.getComment()).isNull();
    assertThat(event.getData()).startsWith("Server Error");
    assertThat(event.getId()).isNull();
    assertThat(event.getRetry()).isNull();
}

From source file:com.impetus.kundera.persistence.PersistenceDelegator.java

/**
 * Flushes Dirty objects in {@link PersistenceCache} to databases.
 *//*from w w w. j  ava 2s. c  o  m*/
public void flush() {
    // Get flush stack from Flush Manager
    if (applyFlush()) {
        FlushStack fs = flushManager.getFlushStack();

        // Flush each node in flush stack from top to bottom unit it's empty
        log.debug("Flushing following flush stack to database(s) (showing stack objects from top to bottom):\n"
                + fs);

        if (fs != null) {
            while (!fs.isEmpty()) {
                Node node = fs.pop();

                // Only nodes in Managed and Removed state are flushed, rest
                // are
                // ignored
                if (node.isInState(ManagedState.class) || node.isInState(RemovedState.class)) {
                    EntityMetadata metadata = getMetadata(node.getDataClass());
                    node.setClient(getClient(metadata));

                    node.flush();

                    // Update Link value for all nodes attached to this one
                    Map<NodeLink, Node> parents = node.getParents();
                    Map<NodeLink, Node> children = node.getChildren();

                    if (parents != null && !parents.isEmpty()) {
                        for (NodeLink parentNodeLink : parents.keySet()) {
                            parentNodeLink.addLinkProperty(LinkProperty.LINK_VALUE,
                                    ObjectGraphUtils.getEntityId(node.getNodeId()));
                        }
                    }

                    if (children != null && !children.isEmpty()) {
                        for (NodeLink childNodeLink : children.keySet()) {
                            childNodeLink.addLinkProperty(LinkProperty.LINK_VALUE,
                                    ObjectGraphUtils.getEntityId(node.getNodeId()));
                        }
                    }
                }

            }

            // TODO : This needs to be look for different
            // permutation/combination
            // Flush Join Table data into database
            Map<String, JoinTableData> joinTableDataMap = flushManager.getJoinTableDataMap();
            for (JoinTableData jtData : joinTableDataMap.values()) {
                EntityMetadata m = KunderaMetadataManager.getEntityMetadata(jtData.getEntityClass());
                Client client = getClient(m);

                if (OPERATION.INSERT.equals(jtData.getOperation())) {
                    client.persistJoinTable(jtData);
                } else if (OPERATION.DELETE.equals(jtData.getOperation())) {
                    for (Object pk : jtData.getJoinTableRecords().keySet()) {
                        client.deleteByColumn(jtData.getJoinTableName(), m.getIdColumn().getName(), pk);
                    }
                }
                jtData.setProcessed(true);
            }
            joinTableDataMap.clear(); // All Join table operation performed,
                                      // clear it.

        }

    }
}