下面列出了org.apache.commons.lang3.tuple.MutablePair#getLeft ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Map<String, MutablePair<String, CommentsNodeImpl>> copyMap(CommentsNodeImpl parent)
{
Map<String, MutablePair<String, CommentsNodeImpl>> result = new HashMap<>(this.dataMap.size());
for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : this.dataMap.entrySet())
{
String keyToCpy = entry.getKey();
MutablePair<String, CommentsNodeImpl> valueToCpy = entry.getValue();
CommentsNodeImpl nodeToCpy = valueToCpy.getRight();
CommentsNodeImpl copiedNode;
if (nodeToCpy == null)
{
copiedNode = null;
}
else
{
copiedNode = new CommentsNodeImpl(parent);
copiedNode.dataMap.putAll(nodeToCpy.copyMap(parent));
}
MutablePair<String, CommentsNodeImpl> copied = new MutablePair<>(valueToCpy.getLeft(), copiedNode);
result.put(keyToCpy, copied);
}
return result;
}
@Override
public void trim()
{
for (Iterator<Entry<String, MutablePair<String, CommentsNodeImpl>>> iterator = this.dataMap.entrySet().iterator(); iterator.hasNext(); )
{
Entry<String, MutablePair<String, CommentsNodeImpl>> entry = iterator.next();
MutablePair<String, CommentsNodeImpl> value = entry.getValue();
CommentsNodeImpl right = value.getRight();
if (right != null)
{
right.trim();
}
if (((right == null) || right.dataMap.isEmpty()) && (value.getLeft() == null))
{
iterator.remove();
continue;
}
if (right == null)
{
continue;
}
right.trim();
}
}
@Override
@Nullable
public String getComment(String path)
{
MutablePair<String, CommentsNodeImpl> nodePair = this.dataMap.get(path);
if (nodePair != null)
{
String comment = nodePair.getLeft();
if (comment != null)
{
return comment;
}
}
MutablePair<String, CommentsNodeImpl> anyNodePair = this.dataMap.get(ANY);
if (anyNodePair != null)
{
return anyNodePair.getKey();
}
return null;
}
/**
* handleDeltas handles deltas and call processor distribute.
*
* @param deltas deltas
*/
private void handleDeltas(Deque<MutablePair<DeltaFIFO.DeltaType, KubernetesObject>> deltas) {
if (CollectionUtils.isEmpty(deltas)) {
return;
}
// from oldest to newest
for (MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta : deltas) {
DeltaFIFO.DeltaType deltaType = delta.getLeft();
switch (deltaType) {
case Sync:
case Added:
case Updated:
boolean isSync = deltaType == DeltaFIFO.DeltaType.Sync;
Object oldObj = this.indexer.get((ApiType) delta.getRight());
if (oldObj != null) {
this.indexer.update((ApiType) delta.getRight());
this.processor.distribute(
new ProcessorListener.UpdateNotification(oldObj, delta.getRight()), isSync);
} else {
this.indexer.add((ApiType) delta.getRight());
this.processor.distribute(
new ProcessorListener.AddNotification(delta.getRight()), isSync);
}
break;
case Deleted:
this.indexer.delete((ApiType) delta.getRight());
this.processor.distribute(
new ProcessorListener.DeleteNotification(delta.getRight()), false);
break;
}
}
}
public Optional<MutablePair<V1Event, V1Patch>> correlate(V1Event event) {
MutablePair<V1Event, String> aggregatedResult = this.aggregator.aggregate(event);
V1Event aggregatedEvent = aggregatedResult.getLeft();
String cacheKey = aggregatedResult.getRight();
MutablePair<V1Event, V1Patch> observeResult = this.logger.observe(aggregatedEvent, cacheKey);
if (!this.filter.test(event)) {
return Optional.empty();
}
return Optional.of(observeResult);
}
public synchronized MutablePair<V1Event, String> aggregate(V1Event event) {
DateTime now = DateTime.now();
MutablePair<String, String> aggregatedKeys = keyFunc.apply(event);
String aggregatedKey = aggregatedKeys.getLeft();
String localKey = aggregatedKeys.getRight();
AggregatedRecord record;
try {
record = this.spammingCache.get(aggregatedKey, AggregatedRecord::new);
} catch (ExecutionException e) {
throw new IllegalStateException(e);
}
record.lastTimestamp = now;
record.localKeys.add(localKey);
if (record.localKeys.size() < this.maxEvents) {
this.spammingCache.put(aggregatedKey, record);
return new MutablePair<>(event, EventUtils.getEventKey(event));
}
record.localKeys.remove(record.localKeys.stream().findAny().get()); // remove any keys
V1Event aggregatedEvent =
new V1EventBuilder(event)
.withMetadata(
new V1ObjectMetaBuilder()
.withName(EventUtils.generateName(event.getInvolvedObject().getName(), now))
.withNamespace(event.getInvolvedObject().getNamespace())
.build())
.withCount(1)
.withFirstTimestamp(now)
.withLastTimestamp(now)
.withMessage(this.messageFunc.apply(event))
.build();
this.spammingCache.put(aggregatedKey, record);
return new MutablePair<>(aggregatedEvent, aggregatedKey);
}
public static VoxelShape getShape(AxisAlignedBB aabb) {
VoxelShape shape = bbToShapeCache.getIfPresent(aabb);
if (shape == null) {
shape = VoxelShapes.create(aabb);
bbToShapeCache.put(aabb, shape);
MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape);
if (entry.getLeft() == null) {
entry.setLeft(aabb);
}
}
return shape;
}
public static AxisAlignedBB getAABB(VoxelShape shape) {
MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape);
if (entry.getLeft() == null) {
entry.setLeft(shape.getBoundingBox());
}
return entry.getLeft();
}
@SuppressWarnings("unchecked")
Map<String, MutablePair<String, ?>> buildMap()
{
Map<String, MutablePair<String, ?>> resultMap = new LinkedHashMap<>(this.dataMap.size());
for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : this.dataMap.entrySet())
{
MutablePair<String, CommentsNodeImpl> value = entry.getValue();
CommentsNodeImpl right = value.getRight();
String left = value.getLeft();
if ((right == null) && (left == null))
{
continue;
}
Map<String, MutablePair<String, ?>> rightMap = null;
if (right != null)
{
rightMap = right.buildMap();
if (rightMap.isEmpty())
{
rightMap = null;
if (left == null)
{
continue;
}
}
}
resultMap.put(entry.getKey(), new MutablePair<>(left, rightMap));
}
return resultMap;
}
@Override
public void join(CommentsNode toJoin_)
{
if (toJoin_ instanceof EmptyCommentsNode)
{
return;
}
if (! (toJoin_ instanceof CommentsNodeImpl))
{
throw new IllegalArgumentException("Can't join to unknown node type.");
}
CommentsNodeImpl toJoin = (CommentsNodeImpl) toJoin_;
for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : toJoin.dataMap.entrySet())
{
String nodeKey = entry.getKey();
MutablePair<String, CommentsNodeImpl> pair = entry.getValue();
String nodeComment = pair.getLeft();
CommentsNodeImpl subNode = pair.getRight();
if (nodeComment != null)
{
this.setComment(nodeKey, nodeComment);
}
if (subNode != null)
{
this.join(nodeKey, subNode);
}
}
}
@SuppressWarnings("unchecked")
private void write(Map<String, MutablePair<String, ?>> map) throws IOException
{
this.updateIndent(true);
int keys = map.entrySet().size();
int k = 0;
for (Entry<String, MutablePair<String, ?>> entry : map.entrySet())
{
k += 1;
MutablePair<String, ?> pair = entry.getValue();
String comment = pair.getLeft();
Map<String, MutablePair<String, ?>> rightMap = (Map<String, MutablePair<String, ?>>) pair.getRight();
int rightKeys = (rightMap == null) ? 0 : rightMap.size();
boolean newLine = keys > 3;
if (comment != null)
{
this.writeComment(comment);
}
String key = entry.getKey();
this.writeKey(key);
if (rightMap != null)
{
this.write(rightMap);
}
if (newLine)
{
this.writeNewLine(false);
}
}
this.writeNewLine(false);
this.updateIndent(false);
}
@Override
public void beginWindow(long windowId)
{
currentWindowId = windowId;
if (currentWindowId <= windowManager.getLargestCompletedWindow()) {
try {
replay(currentWindowId);
return;
} catch (SQLException e) {
throw new RuntimeException("Replay failed", e);
}
}
currentWindowRecoveryState = WindowData.of(currentWindowRecoveryState.key, lastEmittedRow, 0);
if (isPollerPartition) {
MutablePair<Object, Integer> keyOffset = fetchedKeyAndOffset.get();
if (keyOffset != null && keyOffset.getRight() < lastEmittedRow) {
if (!adjustKeyAndOffset.get()) {
// rebase offset
lastEmittedRow -= keyOffset.getRight();
currentWindowRecoveryState.lowerBound = lastEmittedRow;
currentWindowRecoveryState.key = keyOffset.getLeft();
adjustKeyAndOffset.set(true);
}
}
}
}
@Override
public MutablePair<MutableLong, MutableLong> accumulate(MutablePair<MutableLong, MutableLong> accumulatedValue, MutablePair<Double, Double> input)
{
if (input.getLeft() * input.getLeft() + input.getRight() * input.getRight() < 1) {
accumulatedValue.getLeft().increment();
}
accumulatedValue.getRight().increment();
return accumulatedValue;
}
@Override
public Double getOutput(MutablePair<Double, Long> accumulatedValue)
{
return accumulatedValue.getLeft();
}
@Override
protected String getFileName(AbstractBlockReader.ReaderRecord<Slice> tuple)
{
MutablePair<Integer,String> blockId = blockInfo.get(tuple.getBlockId());
return blockId.getRight() + PARTSUFFIX + blockId.getLeft();
}
@Override
public void finalizeFile(String fileName) throws IOException
{
MutablePair<Integer,String> blockId = blockInfo.get(Long.parseLong(fileName));
super.finalizeFile(blockId.getRight() + PARTSUFFIX + blockId.getLeft());
}