Example usage for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair

List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair.

Prototype

public ImmutablePair(final L left, final R right) 

Source Link

Document

Create a new pair instance.

Usage

From source file:org.apache.apex.malhar.lib.window.impl.SpillableSessionWindowedStorage.java

@Override
public void migrateWindow(Window.SessionWindow<K> fromWindow, Window.SessionWindow<K> toWindow) {
    K key = fromWindow.getKey();//from   ww w  .j  a v a2  s .c  om
    ImmutablePair<Window, K> oldKey = new ImmutablePair<Window, K>(fromWindow, key);
    ImmutablePair<Window, K> newKey = new ImmutablePair<Window, K>(toWindow, key);
    V value = windowKeyToValueMap.get(oldKey);
    if (value == null) {
        throw new NoSuchElementException();
    }
    windowKeyToValueMap.remove(oldKey);
    windowKeyToValueMap.put(newKey, value);
    keyToWindowsMap.remove(key, fromWindow);
    keyToWindowsMap.put(key, toWindow);
    windowToKeysMap.removeAll(fromWindow);
    windowToKeysMap.put(toWindow, key);
}

From source file:org.apache.apex.malhar.lib.window.impl.SpillableSessionWindowedStorage.java

@Override
public Collection<Map.Entry<Window.SessionWindow<K>, V>> getSessionEntries(K key, long timestamp, long gap) {
    List<Map.Entry<Window.SessionWindow<K>, V>> results = new ArrayList<>();
    Set<Window.SessionWindow<K>> sessionWindows = keyToWindowsMap.get(key);
    if (sessionWindows != null) {
        for (Window.SessionWindow<K> window : sessionWindows) {
            if (timestamp > window.getBeginTimestamp()) {
                if (window.getBeginTimestamp() + window.getDurationMillis() > timestamp) {
                    results.add(new AbstractMap.SimpleEntry<>(window,
                            windowKeyToValueMap.get(new ImmutablePair<Window, K>(window, key))));
                }/*from  www  . java2 s. co  m*/
            } else if (timestamp < window.getBeginTimestamp()) {
                if (window.getBeginTimestamp() - gap <= timestamp) {
                    results.add(new AbstractMap.SimpleEntry<>(window,
                            windowKeyToValueMap.get(new ImmutablePair<Window, K>(window, key))));
                }
            } else {
                results.add(new AbstractMap.SimpleEntry<>(window,
                        windowKeyToValueMap.get(new ImmutablePair<Window, K>(window, key))));
            }
        }
    }
    return results;
}

From source file:org.apache.apex.malhar.lib.window.impl.SpillableWindowedKeyedStorage.java

@Override
public void remove(Window window) {
    Set<K> keys = windowToKeysMap.get(window);
    if (keys != null) {
        for (K key : keys) {
            windowKeyToValueMap.remove(new ImmutablePair<>(window, key));
        }/* w  w w  .  j av  a 2  s  . co  m*/
    }
    windowToKeysMap.removeAll(window);
}

From source file:org.apache.apex.malhar.lib.window.impl.SpillableWindowedKeyedStorage.java

@Override
public void put(Window window, K key, V value) {
    if (!windowToKeysMap.containsEntry(window, key)) {
        windowToKeysMap.put(window, key);
    }//  w  ww .  j  av  a 2  s.c  om
    windowKeyToValueMap.put(new ImmutablePair<>(window, key), value);
}

From source file:org.apache.apex.malhar.lib.window.impl.SpillableWindowedKeyedStorage.java

@Override
public V get(Window window, K key) {
    return windowKeyToValueMap.get(new ImmutablePair<>(window, key));
}

From source file:org.apache.asterix.event.service.ZooKeeperService.java

private Pair<CharSequence, CharSequence> getProcessStreams(Process process) throws IOException {
    StringWriter stdout = new StringWriter();
    StringWriter stderr = new StringWriter();
    IOUtils.copy(process.getInputStream(), stdout, Charset.defaultCharset());
    IOUtils.copy(process.getErrorStream(), stderr, Charset.defaultCharset());
    return new ImmutablePair<>(stdout.getBuffer(), stderr.getBuffer());
}

From source file:org.apache.beam.runners.apex.translation.TranslationContext.java

/**
 * Register operator and output ports for the given collections.
 * @param operator//from   w  w  w .  ja v a  2  s  . c om
 * @param ports
 */
public void addOperator(Operator operator, Map<PCollection<?>, OutputPort<?>> ports) {
    boolean first = true;
    for (Map.Entry<PCollection<?>, OutputPort<?>> portEntry : ports.entrySet()) {
        if (first) {
            addOperator(operator, portEntry.getValue(), portEntry.getKey());
            first = false;
        } else {
            this.streams.put(portEntry.getKey(),
                    (Pair) new ImmutablePair<>(new OutputPortInfo(portEntry.getValue(), getCurrentTransform()),
                            new ArrayList<>()));
        }
    }
}

From source file:org.apache.beam.runners.apex.translation.TranslationContext.java

/**
 * Add the operator with its output port for the given result {link PCollection}.
 * @param operator//w ww  . j av a  2  s. co  m
 * @param port
 * @param output
 */
public void addOperator(Operator operator, OutputPort port, PCollection output) {
    // Apex DAG requires a unique operator name
    // use the transform's name and make it unique
    String name = getCurrentTransform().getFullName();
    for (int i = 1; this.operators.containsKey(name); i++) {
        name = getCurrentTransform().getFullName() + i;
    }
    this.operators.put(name, operator);
    this.streams.put(output,
            (Pair) new ImmutablePair<>(new OutputPortInfo(port, getCurrentTransform()), new ArrayList<>()));
}

From source file:org.apache.distributedlog.TestTruncate.java

private Pair<DistributedLogManager, AsyncLogWriter> populateData(Map<Long, DLSN> txid2DLSN,
        DistributedLogConfiguration confLocal, String name, int numLogSegments, int numEntriesPerLogSegment,
        boolean createInprogressLogSegment) throws Exception {
    long txid = 1;
    for (long i = 1; i <= numLogSegments; i++) {
        LOG.info("Writing Log Segment {}.", i);
        DistributedLogManager dlm = createNewDLM(confLocal, name);
        AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
        for (int j = 1; j <= numEntriesPerLogSegment; j++) {
            long curTxId = txid++;
            DLSN dlsn = Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(curTxId)));
            txid2DLSN.put(curTxId, dlsn);
        }/*  ww w . jav  a 2s .  com*/
        Utils.close(writer);
        dlm.close();
    }

    if (createInprogressLogSegment) {
        DistributedLogManager dlm = createNewDLM(confLocal, name);
        AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
        for (int j = 1; j <= 10; j++) {
            long curTxId = txid++;
            DLSN dlsn = Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(curTxId)));
            txid2DLSN.put(curTxId, dlsn);
        }
        return new ImmutablePair<DistributedLogManager, AsyncLogWriter>(dlm, writer);
    } else {
        return null;
    }
}

From source file:org.apache.drill.exec.ops.FragmentStats.java

public OperatorStats addOperatorStats(OperatorStats stats) {
    return operators.put(new ImmutablePair<>(stats.operatorId, stats.operatorType), stats);
}