MCPcopy Create free account
hub / github.com/apache/poi / put

Method put

src/java/org/apache/poi/util/BinaryTree.java:1425–1493  ·  view source on GitHub ↗

Associates the specified value with the specified key in this map. @param key key with which the specified value is to be associated. @param value value to be associated with the specified key. @return null @exception ClassCastException if the class of the specified key

(Object key, Object value)

Source from the content-addressed store, hash-verified

1423 * existing value
1424 */
1425 public Object put(Object key, Object value)
1426 throws ClassCastException, NullPointerException,
1427 IllegalArgumentException
1428 {
1429 checkKeyAndValue(key, value);
1430 Node node = _root[ _KEY ];
1431
1432 if (node == null)
1433 {
1434 Node root = new Node(( Comparable ) key, ( Comparable ) value);
1435
1436 _root[ _KEY ] = root;
1437 _root[ _VALUE ] = root;
1438 grow();
1439 }
1440 else
1441 {
1442 while (true)
1443 {
1444 int cmp = compare(( Comparable ) key, node.getData(_KEY));
1445
1446 if (cmp == 0)
1447 {
1448 throw new IllegalArgumentException(
1449 "Cannot store a duplicate key (\"" + key
1450 + "\") in this Map");
1451 }
1452 else if (cmp < 0)
1453 {
1454 if (node.getLeft(_KEY) != null)
1455 {
1456 node = node.getLeft(_KEY);
1457 }
1458 else
1459 {
1460 Node newNode = new Node(( Comparable ) key,
1461 ( Comparable ) value);
1462
1463 insertValue(newNode);
1464 node.setLeft(newNode, _KEY);
1465 newNode.setParent(node, _KEY);
1466 doRedBlackInsert(newNode, _KEY);
1467 grow();
1468 break;
1469 }
1470 }
1471 else
1472 { // cmp > 0
1473 if (node.getRight(_KEY) != null)
1474 {
1475 node = node.getRight(_KEY);
1476 }
1477 else
1478 {
1479 Node newNode = new Node(( Comparable ) key,
1480 ( Comparable ) value);
1481
1482 insertValue(newNode);

Callers 15

testSizeMethod · 0.95
testIsEmptyMethod · 0.95
testContainsKeyMethod · 0.95
testContainsValueMethod · 0.95
testGetMethod · 0.95
testPutMethod · 0.95
testRemoveMethod · 0.95
testPutAllMethod · 0.95
testClearMethod · 0.95
testKeySetMethod · 0.95
testValuesMethod · 0.95
testEntrySetMethod · 0.95

Calls 11

checkKeyAndValueMethod · 0.95
growMethod · 0.95
compareMethod · 0.95
getDataMethod · 0.95
getLeftMethod · 0.95
insertValueMethod · 0.95
setLeftMethod · 0.95
setParentMethod · 0.95
doRedBlackInsertMethod · 0.95
getRightMethod · 0.95
setRightMethod · 0.95

Tested by 15

testSizeMethod · 0.76
testIsEmptyMethod · 0.76
testContainsKeyMethod · 0.76
testContainsValueMethod · 0.76
testGetMethod · 0.76
testPutMethod · 0.76
testRemoveMethod · 0.76
testPutAllMethod · 0.76
testClearMethod · 0.76
testKeySetMethod · 0.76
testValuesMethod · 0.76
testEntrySetMethod · 0.76