从受保护的java方法返回Map

时间:2017-05-09 06:16:43

标签: java compiler-errors hashmap

protected void createIdUpdateMapForMapObjects()
{
    for (Iterator it = d_mapObjectList.iterator(); it.hasNext(); )
    {
        MapObject mapObj       = (MapObject) it.next();
        long      transientId  = mapObj.id();
        long      persistentId = g.getNewId();
        boolean minDPTObjectIdSet = false;
        long      minDPTObjectId ;
        long      maxDPTObjectId = g.upperBound();

        if(minDPTObjectIdSet == false) {
            minDPTObjectId = persistentId;
            System.out.println("min dpt" + minDPTObjectId);
            System.out.println("max dpt" + maxDPTObjectId);
            //insertDPTObjectId("minDPTObjectId", minDPTObjectId, "Starting change ID");
            //insertDPTObjectId("maxDPTObjectId", maxDPTObjectId, "End change ID");
            minDPTObjectIdSet = true;

        }

public Map<String, Long> getMinMaxDPTObjectId(String Name, long minmaxDPTObjectId) {
    Map<String,Long> minMaxDPTObjectId = new HashMap<String,Long>();

    minMaxDPTObjectId.put("minDPTObjectId",minDPTObjectId);
        //minDPTObjectId which i need to get from above method
    minMaxDPTObjectId.put("maxDPTObjectId",maxDPTObjectId);
        //same 

    return minMaxDPTObjectId;
}

我无法将minDPTObjectId和maxDPTObjectId的值返回到必须在另一个包中使用的Map 我认为返回地图将是一个不错的选择,但坚持如何做到这一点

1 个答案:

答案 0 :(得分:0)

public Map createIdUpdateMapForMapObjects()
{
    IdGenerator g = d_idm.getGenerator(OraclePropertyAdapter.NEXTID);    // could be null
    Map<String, Long> minMaxDPTObjectIdMap             = null;
    for (Iterator it = d_mapObjectList.iterator(); it.hasNext(); )
    {
        MapObject mapObj       = (MapObject) it.next();
        long      transientId  = mapObj.id();
        long      persistentId = g.getNewId();
        boolean minDPTObjectIdSet = false;
        long      minDPTObjectId ;
        long      maxDPTObjectId = g.upperBound();
        minMaxDPTObjectIdMap = new HashMap<String, Long>();
        minMaxDPTObjectIdMap.put("maxDPTObjectId",maxDPTObjectId);

        if(minDPTObjectIdSet == false) {
            minDPTObjectId = persistentId;
            minMaxDPTObjectIdMap.put("minDPTObjectId",minDPTObjectId);
            minDPTObjectIdSet = true;
}
           return minMaxDPTObjectIdMap;

这看起来不错吗?