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

The following examples show how to use org.apache.commons.lang3.tuple.MutablePair#setLeft() . 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: ParseService.java    From yauaa with Apache License 2.0 6 votes vote down vote up
private Pair<String, String> prefixSplitter(String input) {
    MutablePair<String, String> result = new MutablePair<>("", input);
    if (input.startsWith("Device")) {
        result.setLeft("Device");
        result.setRight(input.replaceFirst("Device", ""));
    } else if (input.startsWith("OperatingSystem")) {
        result.setLeft("Operating System");
        result.setRight(input.replaceFirst("OperatingSystem", ""));
    } else if (input.startsWith("LayoutEngine")) {
        result.setLeft("Layout Engine");
        result.setRight(input.replaceFirst("LayoutEngine", ""));
    } else if (input.startsWith("Agent")) {
        result.setLeft("Agent");
        result.setRight(input.replaceFirst("Agent", ""));
    }
    return result;
}
 
Example 2
Source File: HdfsHelper.java    From DataLink with Apache License 2.0 5 votes vote down vote up
public static MutablePair<Text, Boolean> transportOneRecord(
        Record record, char fieldDelimiter, List<Configuration> columnsConfiguration, TaskPluginCollector taskPluginCollector) {
    MutablePair<List<Object>, Boolean> transportResultList =  transportOneRecord(record,columnsConfiguration,taskPluginCollector);
    //保存<转换后的数据,是否是脏数据>
    MutablePair<Text, Boolean> transportResult = new MutablePair<Text, Boolean>();
    transportResult.setRight(false);
    if(null != transportResultList){
        Text recordResult = new Text(StringUtils.join(transportResultList.getLeft(), fieldDelimiter));
        transportResult.setRight(transportResultList.getRight());
        transportResult.setLeft(recordResult);
    }
    return transportResult;
}
 
Example 3
Source File: VoxelShapeCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example 4
Source File: VoxelShapeCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static AxisAlignedBB getAABB(VoxelShape shape) {
    MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape);
    if (entry.getLeft() == null) {
        entry.setLeft(shape.getBoundingBox());
    }
    return entry.getLeft();
}
 
Example 5
Source File: CommentsNodeImpl.java    From Diorite with MIT License 5 votes vote down vote up
@Override
public void setComment(String path, @Nullable String comment)
{
    MutablePair<String, CommentsNodeImpl> nodePair = this.dataMap.computeIfAbsent(path, k -> new MutablePair<>(null, null));
    if (comment == null)
    {
        nodePair.setLeft(null);
        return;
    }
    nodePair.setLeft(comment);
}
 
Example 6
Source File: Average.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public MutablePair<Double, Long> accumulate(MutablePair<Double, Long> accu, Double input)
{
  accu.setLeft(accu.getLeft() * ((double)accu.getRight() / (accu.getRight() + 1)) + input / (accu.getRight() + 1));
  accu.setRight(accu.getRight() + 1);
  return accu;
}
 
Example 7
Source File: Average.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public MutablePair<Double, Long> merge(MutablePair<Double, Long> accu1, MutablePair<Double, Long> accu2)
{
  accu1.setLeft(accu1.getLeft() * ((double)accu1.getRight() / accu1.getRight() + accu2.getRight()) +
      accu2.getLeft() * ((double)accu2.getRight() / accu1.getRight() + accu2.getRight()));
  accu1.setRight(accu1.getRight() + accu2.getRight());
  return accu1;
}
 
Example 8
Source File: PushJobDelegate.java    From syncope with Apache License 2.0 5 votes vote down vote up
protected void reportHandled(final String anyType, final String key) {
    MutablePair<Integer, String> pair = handled.get(anyType);
    if (pair == null) {
        pair = MutablePair.of(0, null);
        handled.put(anyType, pair);
    }
    pair.setLeft(pair.getLeft() + 1);
    pair.setRight(key);
}
 
Example 9
Source File: PullJobDelegate.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Override
public void reportHandled(final ObjectClass objectClass, final Name name) {
    MutablePair<Integer, String> pair = handled.get(objectClass);
    if (pair == null) {
        pair = MutablePair.of(0, null);
        handled.put(objectClass, pair);
    }
    pair.setLeft(pair.getLeft() + 1);
    pair.setRight(name.getNameValue());
}
 
Example 10
Source File: UnstructuredStorageWriterUtil.java    From DataLink with Apache License 2.0 4 votes vote down vote up
/**
 * @return MutablePair<String, Boolean> left: formated data line; right: is
 *         dirty data or not, true means meeting dirty data
 * */
public static MutablePair<String, Boolean> transportOneRecord(
        Record record, String nullFormat, String dateFormat,
        char fieldDelimiter, String fileFormat,
        TaskPluginCollector taskPluginCollector) {
    // warn: default is null
    if (null == nullFormat) {
        nullFormat = "null";
    }
    MutablePair<String, Boolean> transportResult = new MutablePair<String, Boolean>();
    transportResult.setRight(false);
    List<String> splitedRows = new ArrayList<String>();
    int recordLength = record.getColumnNumber();
    if (0 != recordLength) {
        Column column;
        for (int i = 0; i < recordLength; i++) {
            column = record.getColumn(i);
            if (null != column.getRawData()) {
                boolean isDateColumn = column instanceof DateColumn;
                if (!isDateColumn) {
                    splitedRows.add(column.asString());
                } else {
                    // if (null != dateFormat) {
                    if (StringUtils.isNotBlank(dateFormat)) {
                        try {
                            SimpleDateFormat dateParse = new SimpleDateFormat(
                                    dateFormat);
                            splitedRows.add(dateParse.format(column
                                    .asDate()));
                        } catch (Exception e) {
                            // warn: 此处认为似乎脏数据
                            String message = String.format(
                                    "使用您配置的格式 [%s] 转换 [%s] 错误.",
                                    dateFormat, column.asString());
                            taskPluginCollector.collectDirtyRecord(record,
                                    message);
                            transportResult.setRight(true);
                            break;
                        }
                    } else {
                        splitedRows.add(column.asString());
                    }
                }
            } else {
                // warn: it's all ok if nullFormat is null
                splitedRows.add(nullFormat);
            }
        }
    }

    transportResult.setLeft(UnstructuredStorageWriterUtil
            .doTransportOneRecord(splitedRows, fieldDelimiter, fileFormat));
    return transportResult;
}
 
Example 11
Source File: HdfsHelper.java    From DataLink with Apache License 2.0 4 votes vote down vote up
public static MutablePair<List<Object>, Boolean> transportOneRecord(
        Record record,List<Configuration> columnsConfiguration,
        TaskPluginCollector taskPluginCollector){

    MutablePair<List<Object>, Boolean> transportResult = new MutablePair<List<Object>, Boolean>();
    transportResult.setRight(false);
    List<Object> recordList = Lists.newArrayList();
    int recordLength = record.getColumnNumber();
    if (0 != recordLength) {
        Column column;
        for (int i = 0; i < recordLength; i++) {
            column = record.getColumn(i);
            //todo as method
String rowData = column.getRawData() == null ? null : column.getRawData().toString();
            if (null != column.getRawData() && StringUtils.isNotBlank(rowData)) {
                SupportHiveDataType columnType = SupportHiveDataType.valueOf(
                        columnsConfiguration.get(i).getString(Key.TYPE).toUpperCase());
                //根据writer端类型配置做类型转换
                try {
                    switch (columnType) {
                        case TINYINT:
                            recordList.add(Byte.valueOf(rowData));
                            break;
                        case SMALLINT:
                            recordList.add(Short.valueOf(rowData));
                            break;
                        case INT:
                            recordList.add(Integer.valueOf(rowData));
                            break;
                        case BIGINT:
                            recordList.add(column.asLong());
                            break;
                        case FLOAT:
                            recordList.add(Float.valueOf(rowData));
                            break;
                        case DOUBLE:
                            recordList.add(column.asDouble());
                            break;
                        case DECIMAL://decimal,added by lubiao
                        	recordList.add(HiveDecimal.create(column.asBigDecimal()));
                        	break;
                        case BINARY://binary,added by lubiao
                        	recordList.add(new BytesWritable(column.asBytes()));
                        	break;
                        case STRING:
                        case VARCHAR:
                        case CHAR:
                            recordList.add(column.asString());
                            break;
                        case BOOLEAN:
                            recordList.add(column.asBoolean());
                            break;
                        case DATE:
                            recordList.add(new java.sql.Date(column.asDate().getTime()));
                            break;
                        case TIMESTAMP:
                            recordList.add(new java.sql.Timestamp(column.asDate().getTime()));
                            break;
                        default:
                            ErrorRecord.addError(String.format(
                                    "您的配置文件中的列配置信息有误. 因为DataX 不支持数据库写入这种字段类型. 字段名:[%s], 字段类型:[%d]. 请修改表中该字段的类型或者不同步该字段.",
                                    columnsConfiguration.get(i).getString(Key.NAME),
                                    columnsConfiguration.get(i).getString(Key.TYPE)));
                            throw DataXException
                                    .asDataXException(
                                            HdfsWriterErrorCode.ILLEGAL_VALUE,
                                            String.format(
                                                    "您的配置文件中的列配置信息有误. 因为DataX 不支持数据库写入这种字段类型. 字段名:[%s], 字段类型:[%d]. 请修改表中该字段的类型或者不同步该字段.",
                                                    columnsConfiguration.get(i).getString(Key.NAME),
                                                    columnsConfiguration.get(i).getString(Key.TYPE)));
                    }
                } catch (Exception e) {
                    // warn: 此处认为脏数据
                    String message = String.format(
                            "字段类型转换错误:你目标字段为[%s]类型,实际字段值为[%s].",
                            columnsConfiguration.get(i).getString(Key.TYPE), column.getRawData().toString());
                    taskPluginCollector.collectDirtyRecord(record, message);
                    transportResult.setRight(true);
                    break;
                }
            }else {
                // warn: it's all ok if nullFormat is null
                recordList.add(null);
            }
        }
    }
    transportResult.setLeft(recordList);
    return transportResult;
}