Refine search
public DayOfWeek(String value) { super(value); for (Integer dayOfWeek : this.absoluteValues) { if (dayOfWeek == 7) { this.absoluteValues.remove(dayOfWeek); this.absoluteValues.add(new Integer(0)); } } if (OFFSET != 0) { for (Integer dayOfWeek : this.absoluteValues) { this.offsetAdjustedDaysOfWeek.add(dayOfWeek - OFFSET); } } else { this.offsetAdjustedDaysOfWeek = this.absoluteValues; } }
/** * Split a given {@link Segment} n-times in round robin fashion. * <br/> * * @param segment The {@link Segment} to split. * @param numberOfTimes The number of times to split it. * @return a collection of {@link Segment}'s. */ public static List<Segment> splitBalanced(Segment segment, int numberOfTimes) { final SortedSet<Segment> toBeSplit = new TreeSet<>(Comparator.comparing(Segment::getMask) .thenComparing(Segment::getSegmentId)); toBeSplit.add(segment); for (int i = 0; i < numberOfTimes; i++) { final Segment workingSegment = toBeSplit.first(); toBeSplit.remove(workingSegment); toBeSplit.addAll(Arrays.asList(workingSegment.split())); } ArrayList<Segment> result = new ArrayList<>(toBeSplit); result.sort(Comparator.comparing(Segment::getSegmentId)); return result; }
/** * If the swap was successful, update the (1) replicas of the source broker (2) replicas of the candidate broker, and * (3) the priority queue of candidate brokers to swap replicas with. * * @param swappedInReplica the replica swapped in to the source broker from the candidate broker, null otherwise. * @param swappedOutReplica the replica swapped out from the source broker to candidate broker, null otherwise. * @param sourceReplicas replicas of the source broker before the swap. * @param candidateReplicasToSwapWith replicas of the candidate broker before the swap. * @param candidateBrokerPQ a priority queue of candidate brokers to swap replicas with (priority: by broker utilization) * @param cb the candidate broker to swap with. */ private void swapUpdate(Replica swappedInReplica, Replica swappedOutReplica, SortedSet<Replica> sourceReplicas, SortedSet<Replica> candidateReplicasToSwapWith, PriorityQueue<CandidateBroker> candidateBrokerPQ, CandidateBroker cb) { if (swappedInReplica != null) { // Update the list of replicas in source broker after the swap operations. sourceReplicas.remove(swappedOutReplica); sourceReplicas.add(swappedInReplica); candidateReplicasToSwapWith.remove(swappedInReplica); candidateReplicasToSwapWith.add(swappedOutReplica); // The broker is still considered as an eligible candidate replica, because the swap was successful -- i.e. there // might be other potential candidate replicas on it to swap with. candidateBrokerPQ.add(cb); } }
void ensureNotDirectlyModifiable(SortedSet<Integer> unmod) { try { unmod.add(4); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } try { unmod.remove(4); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } try { unmod.addAll(Collections.singleton(4)); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } try { Iterator<Integer> iterator = unmod.iterator(); iterator.next(); iterator.remove(); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } }
@Override public void onFailure() { // If the bucket creation failed, we need to undo the changes // we made to the model attemptedBucketCreations.add(move); // remove the bucket from lowRedundancyBuckets before mutating the state lowRedundancyBuckets.remove(bucket); bucket.removeMember(targetMember); if (bucket.getRedundancy() < requiredRedundancy) { lowRedundancyBuckets.add(bucket); } resetAverages(); } });
private void markReadyToDeliverV2(MessageID messageID, long finalSequenceNumber) { MessageInfo messageInfo = messageCache.remove(messageID); if (messageInfo == null) { throw new IllegalStateException("Message ID not found in to deliver list. this can't happen. " + "Message ID is " + messageID); } boolean needsUpdatePosition = messageInfo.isUpdatePositionNeeded(finalSequenceNumber); synchronized (deliverySet) { sequenceNumberManager.update(finalSequenceNumber); if (needsUpdatePosition) { deliverySet.remove(messageInfo); messageInfo.updateAndMarkReadyToDeliver(finalSequenceNumber); deliverySet.add(messageInfo); } else { messageInfo.updateAndMarkReadyToDeliver(finalSequenceNumber); } notifyIfNeeded(); } }
long[] getBiggestObjectsByRetainedSize(int number) { SortedSet<RetainedSizeEntry> bigObjects = new TreeSet<RetainedSizeEntry>(); long[] bigIds = new long[number]; long min = 0; for (long index=0;index<fileSize;index+=ENTRY_SIZE) { long id = getID(index); if (id != 0) { long retainedSize = createEntry(index).getRetainedSize(); if (bigObjects.size()<number) { bigObjects.add(new RetainedSizeEntry(id,retainedSize)); min = ((RetainedSizeEntry)bigObjects.last()).retainedSize; } else if (retainedSize>min) { bigObjects.remove(bigObjects.last()); bigObjects.add(new RetainedSizeEntry(id,retainedSize)); min = ((RetainedSizeEntry)bigObjects.last()).retainedSize; } } } int i = 0; Iterator<RetainedSizeEntry> it = bigObjects.iterator(); while(it.hasNext()) { bigIds[i++]=((RetainedSizeEntry)it.next()).instanceId; } return bigIds; }
public void remoteOverRedundancyBucket(BucketRollup bucket, Member targetMember) { Move bestMove = new Move(null, targetMember, bucket); Map<String, Long> colocatedRegionSizes = getColocatedRegionSizes(bucket); if (!this.operator.removeBucket(targetMember.getMemberId(), bucket.getId(), colocatedRegionSizes)) { this.attemptedBucketRemoves.add(bestMove); } else { this.overRedundancyBuckets.remove(bucket); bucket.removeMember(targetMember); // put the bucket back into the list if we still need to satisfy redundancy for // this bucket if (bucket.getOnlineRedundancy() > this.requiredRedundancy) { this.overRedundancyBuckets.add(bucket); } resetAverages(); } }
break; toTry.remove(nInfo); tried.add(nInfo); if (_log.shouldLog(Log.DEBUG)) _log.debug("Try " + i + ": " + nInfo); _log.debug("Got pong"); } else if (replyType == REPLY_PEERS) { heardFrom.add(waiter.getSentTo()); if (_log.shouldLog(Log.DEBUG)) _log.debug("Got peers"); break; } else if (replyType == REPLY_NODES) { heardFrom.add(waiter.getSentTo()); List<NodeInfo> reply = (List<NodeInfo>) waiter.getReplyObject(); if (_log.shouldLog(Log.DEBUG))
public void testAsMapSortedReadsThrough() { SortedSet<String> strings = new NonNavigableSortedSet(); Collections.addAll(strings, "one", "two", "three"); SortedMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertNull(map.comparator()); assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5), map); assertNull(map.get("four")); strings.add("four"); assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5, "four", 4), map); assertEquals(Integer.valueOf(4), map.get("four")); SortedMap<String, Integer> headMap = map.headMap("two"); assertEquals(ImmutableSortedMap.of("four", 4, "one", 3, "three", 5), headMap); strings.add("five"); strings.remove("one"); assertEquals(ImmutableSortedMap.of("five", 4, "four", 4, "three", 5), headMap); assertThat(map.entrySet()) .containsExactly( mapEntry("five", 4), mapEntry("four", 4), mapEntry("three", 5), mapEntry("two", 3)) .inOrder(); }