java.util.concurrent.ConcurrentSkipListMap.replace()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(140)

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

ConcurrentSkipListMap.replace介绍

暂无

代码示例

代码示例来源:origin: lealone/Lealone

@Override
public boolean replace(K key, V oldValue, V newValue) {
  return skipListMap.replace(key, oldValue, newValue);
}

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

public boolean replace(K key, V oldValue, V newValue) {
  checkKeyBounds(key);
  return m.replace(key, oldValue, newValue);
}

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

public V replace(K key, V value) {
  checkKeyBounds(key);
  return m.replace(key, value);
}

代码示例来源:origin: apache/hbase

@Test
public void testReplace1() throws Exception {
 for (Map.Entry<Long, Long> e: csm.entrySet()) {
  Long newValue = ThreadLocalRandom.current().nextLong();
  assertEquals(csm.replace(e.getKey(), e.getValue() + 1, newValue),
    m.replace(e.getKey(), e.getValue() + 1, newValue));
  assertEquals(csm.replace(e.getKey(), e.getValue(), newValue),
    m.replace(e.getKey(), e.getValue(), newValue));
  assertEquals(newValue, m.get(e.getKey()));
  assertEquals(csm.get(e.getKey()), m.get(e.getKey()));
 }
 assertEquals(null, m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
}

代码示例来源:origin: apache/hbase

@Test
public void testReplace() throws Exception {
 for (Map.Entry<Long, Long> e:csm.entrySet()) {
  Long newValue = ThreadLocalRandom.current().nextLong();
  assertEquals(csm.replace(e.getKey(), newValue), m.replace(e.getKey(), newValue));
 }
 assertEquals(null, m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
}

代码示例来源:origin: googleapis/google-cloud-java

synchronized Response replace(String projectId, Project project) {
 Project originalProject = projects.get(projectId);
 if (originalProject == null) {
  return Error.PERMISSION_DENIED.response(
    "Error when replacing " + projectId + " because the project was not found.");
 } else if (!originalProject.getLifecycleState().equals("ACTIVE")) {
  return Error.FAILED_PRECONDITION.response(
    "Error when replacing " + projectId + " because the lifecycle state was not ACTIVE.");
 } else if (!Objects.equal(originalProject.getParent(), project.getParent())) {
  return Error.INVALID_ARGUMENT.response(
    "The server currently only supports setting the parent once "
      + "and does not allow unsetting it.");
 }
 project.setProjectId(projectId);
 project.setLifecycleState(originalProject.getLifecycleState());
 project.setCreateTime(originalProject.getCreateTime());
 project.setProjectNumber(originalProject.getProjectNumber());
 // replace cannot fail because both this method and removeProject are synchronized
 projects.replace(projectId, project);
 try {
  return new Response(HTTP_OK, jsonFactory.toString(project));
 } catch (IOException e) {
  return Error.INTERNAL_ERROR.response("Error when serializing project " + projectId);
 }
}

代码示例来源:origin: palantir/atlasdb

@Override
public void checkAndSet(CheckAndSetRequest request) throws CheckAndSetException {
  TableReference tableRef = request.table();
  Table table = getTableMap(tableRef);
  Cell cell = request.cell();
  Optional<byte[]> oldValue = request.oldValue();
  byte[] contents = request.newValue();
  Key key = getKey(table, cell, AtlasDbConstants.TRANSACTION_TS);
  if (oldValue.isPresent()) {
    byte[] storedValue = table.entries.get(key);
    boolean succeeded = Arrays.equals(storedValue, oldValue.get())
        && table.entries.replace(key, storedValue, copyOf(contents));
    if (!succeeded) {
      byte[] actual = table.entries.get(key); // Re-fetch, something may have happened between get and replace
      throwCheckAndSetException(cell, tableRef, oldValue.get(), actual);
    }
  } else {
    byte[] oldContents = putIfAbsent(table, key, contents);
    if (oldContents != null) {
      throwCheckAndSetException(cell, tableRef, null, oldContents);
    }
  }
}

代码示例来源:origin: palantir/atlasdb

@Override
public BooleanPaxosResponse accept(long seq, PaxosProposal proposal) {
  try {
    checkLogIfNeeded(seq);
  } catch (Exception e) {
    logger.error("Log read failed for request at sequence {}", SafeArg.of("sequence", seq), e);
    return new BooleanPaxosResponse(false); // nack
  }
  for (;;) {
    PaxosAcceptorState oldState = state.get(seq);
    // nack
    if (oldState != null && proposal.id.compareTo(oldState.lastPromisedId) < 0) {
      return new BooleanPaxosResponse(false);
    }
    // ack
    PaxosAcceptorState newState = oldState != null
        ? oldState.withState(proposal.id, proposal.id, proposal.val)
        : PaxosAcceptorState.newState(proposal.id);
    if ((oldState == null && state.putIfAbsent(seq, newState) == null)
        || (oldState != null && state.replace(seq, oldState, newState))) {
      log.writeRound(seq, newState);
      return new BooleanPaxosResponse(true);
    }
  }
}

代码示例来源:origin: palantir/atlasdb

: PaxosAcceptorState.newState(pid);
if ((oldState == null && state.putIfAbsent(seq, newState) == null)
    || (oldState != null && state.replace(seq, oldState, newState))) {
  log.writeRound(seq, newState);
  return PaxosPromise.accept(

代码示例来源:origin: MobiVM/robovm

public boolean replace(K key, V oldValue, V newValue) {
  checkKeyBounds(key);
  return m.replace(key, oldValue, newValue);
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

public boolean replace(K key, V oldValue, V newValue) {
  checkKeyBounds(key);
  return m.replace(key, oldValue, newValue);
}

代码示例来源:origin: com.bugvm/bugvm-rt

public V replace(K key, V value) {
  checkKeyBounds(key);
  return m.replace(key, value);
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

public boolean replace(K key, V oldValue, V newValue) {
  checkKeyBounds(key);
  return m.replace(key, oldValue, newValue);
}

代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166

public V replace(K key, V value) {
  checkKeyBounds(key);
  return m.replace(key, value);
}

代码示例来源:origin: MobiVM/robovm

public V replace(K key, V value) {
  checkKeyBounds(key);
  return m.replace(key, value);
}

代码示例来源:origin: ibinti/bugvm

public boolean replace(K key, V oldValue, V newValue) {
  checkKeyBounds(key);
  return m.replace(key, oldValue, newValue);
}

代码示例来源:origin: dremio/dremio-oss

@Override
public boolean validateAndPut(byte[] key, byte[] newValue, ByteValidator validator) {
 Preconditions.checkNotNull(newValue);
 byte[] oldValue = get(key);
 if (!validator.validate(oldValue)) {
  return false;
 }
 if (oldValue == null) {
  return map.putIfAbsent(key, ByteBuffer.wrap(newValue)) == null;
 } else {
  return map.replace(key, ByteBuffer.wrap(oldValue), ByteBuffer.wrap(newValue));
 }
}

代码示例来源:origin: org.apache.hbase/hbase-common

@Test
public void testReplace() throws Exception {
 for (Map.Entry<Long, Long> e:csm.entrySet()) {
  Long newValue = ThreadLocalRandom.current().nextLong();
  assertEquals(csm.replace(e.getKey(), newValue), m.replace(e.getKey(), newValue));
 }
 assertEquals(null, m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
}

代码示例来源:origin: org.apache.hbase/hbase-common

@Test
public void testReplace1() throws Exception {
 for (Map.Entry<Long, Long> e: csm.entrySet()) {
  Long newValue = ThreadLocalRandom.current().nextLong();
  assertEquals(csm.replace(e.getKey(), e.getValue() + 1, newValue),
    m.replace(e.getKey(), e.getValue() + 1, newValue));
  assertEquals(csm.replace(e.getKey(), e.getValue(), newValue),
    m.replace(e.getKey(), e.getValue(), newValue));
  assertEquals(newValue, m.get(e.getKey()));
  assertEquals(csm.get(e.getKey()), m.get(e.getKey()));
 }
 assertEquals(null, m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
}

代码示例来源:origin: com.aliyun.hbase/alihbase-common

@Test
public void testReplace() throws Exception {
 for (Map.Entry<Long, Long> e:csm.entrySet()) {
  Long newValue = ThreadLocalRandom.current().nextLong();
  assertEquals(csm.replace(e.getKey(), newValue), m.replace(e.getKey(), newValue));
 }
 assertEquals(null, m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
}

相关文章

ConcurrentSkipListMap类方法