Java Code Examples for org.apache.commons.lang3.tuple.MutablePair#getRight()

The following examples show how to use org.apache.commons.lang3.tuple.MutablePair#getRight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommentsNodeImpl.java    From Diorite with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: CommentsNodeImpl.java    From Diorite with MIT License 6 votes vote down vote up
@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();
    }
}
 
Example 3
Source File: CommentsNodeImpl.java    From Diorite with MIT License 6 votes vote down vote up
@Override
public CommentsNodeImpl getNode(String path)
{
    MutablePair<String, CommentsNodeImpl> nodePair = this.dataMap.get(path);
    CommentsNodeImpl node = (nodePair == null) ? null : nodePair.getRight();
    if (node == null)
    {
        MutablePair<String, CommentsNodeImpl> anyNodePair = this.dataMap.get(ANY);
        node = (anyNodePair == null) ? null : anyNodePair.getRight();
        if (node == null)
        {
            CommentsNodeImpl commentsNode = new CommentsNodeImpl(this);
            if (nodePair != null)
            {
                nodePair.setRight(commentsNode);
            }
            else
            {
                this.dataMap.put(path, new MutablePair<>(null, commentsNode));
            }
            return commentsNode;
        }
        return node;
    }
    return node;
}
 
Example 4
Source File: DeltaFIFO.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * keep the one with the most information if both are deletions.
 *
 * @param d1 the most one
 * @param d2 the elder one
 * @return the most one
 */
private MutablePair<DeltaType, KubernetesObject> isDeletionDup(
    MutablePair<DeltaType, KubernetesObject> d1, MutablePair<DeltaType, KubernetesObject> d2) {
  if (!d1.getLeft().equals(DeltaType.Deleted) || !d2.getLeft().equals(DeltaType.Deleted)) {
    return null;
  }
  Object obj = d2.getRight();
  if (obj instanceof DeletedFinalStateUnknown) {
    return d1;
  }
  return d2;
}
 
Example 5
Source File: EventCorrelator.java    From java with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: EventAggregator.java    From java with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: VoxelShapeCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static VoxelShape getShape(Cuboid6 cuboid) {
    VoxelShape shape = cuboidToShapeCache.getIfPresent(cuboid);
    if (shape == null) {
        shape = VoxelShapes.create(cuboid.min.x, cuboid.min.y, cuboid.min.z, cuboid.max.x, cuboid.max.y, cuboid.max.z);
        cuboidToShapeCache.put(cuboid, shape);
        MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape);
        if (entry.getRight() == null) {
            entry.setRight(cuboid);
        }
    }
    return shape;
}
 
Example 8
Source File: VoxelShapeCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Cuboid6 getCuboid(VoxelShape shape) {
    MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape);
    if (entry.getRight() == null) {
        entry.setRight(new Cuboid6(// I hope this is okay, don't want to rely on AABB cache.
                shape.getStart(Direction.Axis.X), shape.getStart(Direction.Axis.Y), shape.getStart(Direction.Axis.Z),//
                shape.getEnd(Direction.Axis.X), shape.getEnd(Direction.Axis.Y), shape.getEnd(Direction.Axis.Z)//
        ));
    }
    return entry.getRight();
}
 
Example 9
Source File: CommentsNodeImpl.java    From Diorite with MIT License 5 votes vote down vote up
@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;
}
 
Example 10
Source File: CommentsNodeImpl.java    From Diorite with MIT License 5 votes vote down vote up
@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);
        }
    }
}
 
Example 11
Source File: CommentsWriter.java    From Diorite with MIT License 5 votes vote down vote up
@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);
}
 
Example 12
Source File: AbstractJdbcPollInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@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);
      }
    }
  }
}
 
Example 13
Source File: Application.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 14
Source File: UnstructuredStorageWriterUtil.java    From DataLink with Apache License 2.0 4 votes vote down vote up
private static void doWriteToStream(RecordReceiver lineReceiver,
        BufferedWriter writer, String contex, Configuration config,
        TaskPluginCollector taskPluginCollector) throws IOException {

    String nullFormat = config.getString(Key.NULL_FORMAT);

    // 兼容format & dataFormat
    String dateFormat = config.getString(Key.DATE_FORMAT);

    // warn: default false
    String fileFormat = config.getString(Key.FILE_FORMAT,
            Constant.FILE_FORMAT_TEXT);

    String delimiterInStr = config.getString(Key.FIELD_DELIMITER);
    if (null != delimiterInStr && 1 != delimiterInStr.length()) {
        throw DataXException.asDataXException(
                UnstructuredStorageWriterErrorCode.ILLEGAL_VALUE,
                String.format("仅仅支持单字符切分, 您配置的切分为 : [%]", delimiterInStr));
    }
    if (null == delimiterInStr) {
        LOG.warn(String.format("您没有配置列分隔符, 使用默认值[%s]",
                Constant.DEFAULT_FIELD_DELIMITER));
    }

    // warn: fieldDelimiter could not be '' for no fieldDelimiter
    char fieldDelimiter = config.getChar(Key.FIELD_DELIMITER,
            Constant.DEFAULT_FIELD_DELIMITER);

    List<String> headers = config.getList(Key.HEADER, String.class);
    if (null != headers && !headers.isEmpty()) {
        writer.write(UnstructuredStorageWriterUtil.doTransportOneRecord(
                headers, fieldDelimiter, fileFormat));
    }

    Record record = null;
    while ((record = lineReceiver.getFromReader()) != null) {
        MutablePair<String, Boolean> transportResult = UnstructuredStorageWriterUtil
                .transportOneRecord(record, nullFormat, dateFormat,
                        fieldDelimiter, fileFormat, taskPluginCollector);
        if (!transportResult.getRight()) {
            writer.write(transportResult.getLeft());
        }
    }
}
 
Example 15
Source File: PartFileWriter.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
protected String getFileName(AbstractBlockReader.ReaderRecord<Slice> tuple)
{
  MutablePair<Integer,String> blockId = blockInfo.get(tuple.getBlockId());
  return blockId.getRight() + PARTSUFFIX + blockId.getLeft();
}
 
Example 16
Source File: PartFileWriter.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public void finalizeFile(String fileName) throws IOException
{
  MutablePair<Integer,String> blockId = blockInfo.get(Long.parseLong(fileName));
  super.finalizeFile(blockId.getRight() + PARTSUFFIX + blockId.getLeft());
}