java.util.HashMap.computeIfPresent()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(248)

本文整理了Java中java.util.HashMap.computeIfPresent()方法的一些代码示例,展示了HashMap.computeIfPresent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.computeIfPresent()方法的具体详情如下:
包路径:java.util.HashMap
类名称:HashMap
方法名:computeIfPresent

HashMap.computeIfPresent介绍

暂无

代码示例

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String computeIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
  return super.computeIfPresent(key, remappingFunction);
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String computeIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
  return super.computeIfPresent(key, remappingFunction);
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String computeIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
  return super.computeIfPresent(key, remappingFunction);
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String computeIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
  return super.computeIfPresent(key, remappingFunction);
}

代码示例来源:origin: com.typesafe.play/play

/**
 * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String computeIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
  return super.computeIfPresent(key, remappingFunction);
}

代码示例来源:origin: com.typesafe.play/play

/**
 * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String computeIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
  return super.computeIfPresent(key, remappingFunction);
}

代码示例来源:origin: TEAMMATES/teammates

private void testGetInstructorsForCourse() throws Exception {
  ______TS("success: get all instructors for a course");
  String courseId = "idOfTypicalCourse1";
  List<InstructorAttributes> instructors = instructorsLogic.getInstructorsForCourse(courseId);
  assertEquals(5, instructors.size());
  HashMap<String, Boolean> idMap = new HashMap<>();
  idMap.put("idOfInstructor1OfCourse1", false);
  idMap.put("idOfInstructor2OfCourse1", false);
  idMap.put("idOfInstructor3", false);
  for (InstructorAttributes i : instructors) {
    idMap.computeIfPresent(i.googleId, (key, value) -> true);
  }
  assertTrue(idMap.get("idOfInstructor1OfCourse1").booleanValue());
  assertTrue(idMap.get("idOfInstructor2OfCourse1").booleanValue());
  assertTrue(idMap.get("idOfInstructor3").booleanValue());
  ______TS("failure: no instructors for a given course");
  courseId = "new-course";
  coursesLogic.createCourse(courseId, "New course", "UTC");
  instructors = instructorsLogic.getInstructorsForCourse(courseId);
  assertEquals(0, instructors.size());
  ______TS("failure: null parameters");
  AssertionError ae = assertThrows(AssertionError.class, () -> instructorsLogic.getInstructorsForCourse(null));
  AssertHelper.assertContains("Supplied parameter was null", ae.getMessage());
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override
public String computeIfPresent(String key,
    BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
  return map.computeIfPresent(key, remappingFunction);
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
  return map.computeIfPresent(key, remappingFunction);
}

代码示例来源:origin: kishida/sqlparser

void removeModifiedTuple(ModifiedTuple mt){
    modifiedTuples.computeIfPresent(mt.oldtuple.rid, (rid, list) -> {
      list.remove(mt);
      return list.isEmpty() ? null : list;
    });
  }
}

代码示例来源:origin: com.microsoft.azure/azure-cosmosdb-gateway

@Override
public V computeIfPresent(String key, BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
  return super.computeIfPresent(safeToLower(key), remappingFunction);
}

代码示例来源:origin: exercism/java

private List<Integer> reorderBooks(final List<Integer> books) {
  // Counting how often a book number appears in the basket list
  HashMap<Integer, Integer> numberCount = new HashMap<>();
  for (Integer book : books) {
    numberCount.computeIfPresent(book, (key, value) -> value + 1);
    numberCount.putIfAbsent(book, 1);
  }
  return books.stream()
      .sorted((bookNumberOne, bookNumberTwo) -> {
        Integer countOne = numberCount.get(bookNumberOne);
        Integer countTwo = numberCount.get(bookNumberTwo);
        // Books whose numbers appear more often should be in front of the basket list
        if (countOne > countTwo) {
          return -1;
        } else if (countOne.equals(countTwo)) {
          return 0;
        } else {
          return 1;
        }
      })
      .collect(Collectors.toList());
}

代码示例来源:origin: pravega/pravega

@Override
  public void merge(String streamSegmentName, long dataLength, int numOfEvents, long txnCreationTime) {
    segments.computeIfPresent(streamSegmentName, (x, y) -> {
      y.addAndGet(numOfEvents);
      return y;
    });
  }
}

代码示例来源:origin: pravega/pravega

@Override
public void record(String streamSegmentName, long dataLength, int numOfEvents) {
  segments.computeIfPresent(streamSegmentName, (x, y) -> {
    y.addAndGet(numOfEvents);
    return y;
  });
}

代码示例来源:origin: org.onosproject/onos-of-provider-message

@Override
public void handleIncomingMessage(Dpid dpid, OFMessage msg) {
  if (msg.getType() == OFType.PACKET_IN ||
      msg.getType() == OFType.FLOW_MOD ||
      msg.getType() == OFType.STATS_REPLY) {
    aggregators.computeIfPresent(dpid, (k, v) -> {
      v.increment(msg);
      return v;
    });
  }
}

代码示例来源:origin: org.onosproject/onos-of-provider-message

@Override
  public void handleOutgoingMessage(Dpid dpid, List<OFMessage> msgs) {
    for (OFMessage msg : msgs) {
      if (msg.getType() == OFType.PACKET_OUT ||
          msg.getType() == OFType.FLOW_MOD ||
          msg.getType() == OFType.STATS_REQUEST) {
        aggregators.computeIfPresent(dpid, (k, v) -> {
          v.increment(msg);
          return v;
        });
      }
    }
  }
}

相关文章