insert a node by its value @param newNode the node to be inserted @exception IllegalArgumentException if the node already exists in the value mapping
(Node newNode)
| 1289 | * in the value mapping |
| 1290 | */ |
| 1291 | private void insertValue(Node newNode) |
| 1292 | throws IllegalArgumentException |
| 1293 | { |
| 1294 | Node node = _root[ _VALUE ]; |
| 1295 | |
| 1296 | while (true) |
| 1297 | { |
| 1298 | int cmp = compare(newNode.getData(_VALUE), node.getData(_VALUE)); |
| 1299 | |
| 1300 | if (cmp == 0) |
| 1301 | { |
| 1302 | throw new IllegalArgumentException( |
| 1303 | "Cannot store a duplicate value (\"" |
| 1304 | + newNode.getData(_VALUE) + "\") in this Map"); |
| 1305 | } |
| 1306 | else if (cmp < 0) |
| 1307 | { |
| 1308 | if (node.getLeft(_VALUE) != null) |
| 1309 | { |
| 1310 | node = node.getLeft(_VALUE); |
| 1311 | } |
| 1312 | else |
| 1313 | { |
| 1314 | node.setLeft(newNode, _VALUE); |
| 1315 | newNode.setParent(node, _VALUE); |
| 1316 | doRedBlackInsert(newNode, _VALUE); |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | else |
| 1321 | { // cmp > 0 |
| 1322 | if (node.getRight(_VALUE) != null) |
| 1323 | { |
| 1324 | node = node.getRight(_VALUE); |
| 1325 | } |
| 1326 | else |
| 1327 | { |
| 1328 | node.setRight(newNode, _VALUE); |
| 1329 | newNode.setParent(node, _VALUE); |
| 1330 | doRedBlackInsert(newNode, _VALUE); |
| 1331 | break; |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | /* ********** START implementation of Map ********** */ |
| 1338 |