예제 #1
0
  @Test
  @SuppressWarnings("unchecked")
  public void collectionsStreamInterface() throws Exception {
    Map<String, String> testMap =
        getRuntime().getObjectsView().open(UUID.randomUUID(), SMRMap.class);

    testMap.put("a", "b");
    getRuntime().getObjectsView().TXBegin();
    if (testMap.values().stream().anyMatch(x -> x.equals("c"))) {
      throw new Exception("test");
    }
    testMap.compute("b", (k, v) -> "c");
    getRuntime().getObjectsView().TXEnd();
    assertThat(testMap).containsEntry("b", "c");
  }
예제 #2
0
  @Override
  public void storeSink(McastRoute route, ConnectPoint sink, Type operation) {
    MulticastData data =
        mcastRoutes.compute(
            route,
            (k, v) -> {
              switch (operation) {
                case ADD:
                  if (v == null) {
                    v = MulticastData.empty();
                  }
                  v.appendSink(sink);
                  break;
                case REMOVE:
                  if (v != null) {
                    v.removeSink(sink);
                  }
                  break;
                default:
                  log.warn("Unknown mcast operation type: {}", operation);
              }
              return v;
            });

    if (data != null) {
      switch (operation) {
        case ADD:
          delegate.notify(
              new McastEvent(
                  McastEvent.Type.SINK_ADDED,
                  McastRouteInfo.mcastRouteInfo(route, sink, data.source())));
          break;
        case REMOVE:
          if (data != null) {
            delegate.notify(
                new McastEvent(
                    McastEvent.Type.SINK_REMOVED,
                    McastRouteInfo.mcastRouteInfo(route, sink, data.source())));
          }
          break;
        default:
          log.warn("Unknown mcast operation type: {}", operation);
      }
    }
  }
예제 #3
0
  @Override
  public void storeSource(McastRoute route, ConnectPoint source) {
    MulticastData data =
        mcastRoutes.compute(
            route,
            (k, v) -> {
              if (v == null) {
                return new MulticastData(source);
              } else {
                v.setSource(source);
              }
              return v;
            });

    if (data != null) {
      delegate.notify(
          new McastEvent(
              McastEvent.Type.SOURCE_ADDED,
              McastRouteInfo.mcastRouteInfo(route, data.sinks(), source)));
    }
  }
  public String removeDuplicateLetters(String s) {
    Deque<Character> stack = new LinkedList<>();
    Map<Character, Integer> count = new HashMap<>();
    for (int i = 0; i < s.length(); i++) {
      count.compute(
          s.charAt(i),
          (key, val) -> {
            if (val == null) {
              return 1;
            } else {
              return val + 1;
            }
          });
    }

    Set<Character> visited = new HashSet<>();
    for (int i = 0; i < s.length(); i++) {
      char ch = s.charAt(i);
      count.put(ch, count.get(ch) - 1);
      if (visited.contains(ch)) {
        continue;
      }
      while (!stack.isEmpty() && stack.peekFirst() > ch && count.get(stack.peekFirst()) > 0) {
        visited.remove(stack.peekFirst());
        stack.pollFirst();
      }

      stack.offerFirst(ch);
      visited.add(ch);
    }

    StringBuffer buff = new StringBuffer();
    while (!stack.isEmpty()) {
      buff.append(stack.pollLast());
    }
    return buff.toString();
  }
예제 #5
0
 public V compute(
     K key, @NotNull BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
   return map.compute(key, remappingFunction);
 }