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

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

Introduction

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

Prototype

@Override
public R getRight() 

Source Link

Usage

From source file:com.linkedin.pinot.core.query.aggregation.groupby.AggregationGroupByOperatorService.java

/**
 * Translate the reducedGroupByResults (output of broker's reduce) to AggregationResult object
 * to be used to build the BrokerResponse.
 *
 * @param reducedGroupByResults//from  w  ww  .  j a v  a2  s .  co  m
 * @return
 */
public List<AggregationResult> renderAggregationGroupByResult(
        List<Map<String, Serializable>> reducedGroupByResults) {
    if (reducedGroupByResults == null || reducedGroupByResults.size() != _aggregationFunctionList.size()) {
        return null;
    }

    List<AggregationResult> aggregationResults = new ArrayList<AggregationResult>();
    for (int i = 0; i < _aggregationFunctionList.size(); ++i) {
        int groupSize = _groupByColumns.size();

        Map<String, Serializable> reducedGroupByResult = reducedGroupByResults.get(i);
        AggregationFunction aggregationFunction = _aggregationFunctionList.get(i);

        String functionName = aggregationFunction.getFunctionName();
        List<GroupByResult> groupByResults = new ArrayList<GroupByResult>();

        if (!reducedGroupByResult.isEmpty()) {
            /* Reverse sort order for min functions. */
            boolean reverseOrder = aggregationFunction.getFunctionName().startsWith(MIN_PREFIX);

            // The MinMaxPriorityQueue will only add TOP N
            MinMaxPriorityQueue<ImmutablePair<Serializable, String>> minMaxPriorityQueue = getMinMaxPriorityQueue(
                    reducedGroupByResult.values().iterator().next(), _groupByTopN, reverseOrder);

            if (minMaxPriorityQueue != null) {
                for (String groupedKey : reducedGroupByResult.keySet()) {
                    minMaxPriorityQueue
                            .add(new ImmutablePair(reducedGroupByResult.get(groupedKey), groupedKey));
                }

                ImmutablePair res;
                while ((res = (ImmutablePair) minMaxPriorityQueue.pollFirst()) != null) {
                    String groupByColumnsString = (String) res.getRight();
                    List<String> groupByColumns = Arrays.asList(groupByColumnsString.split(
                            GroupByConstants.GroupByDelimiter.groupByMultiDelimeter.toString(), groupSize));

                    Serializable value = (Serializable) res.getLeft();
                    GroupByResult groupValue = new GroupByResult();

                    groupValue.setGroup(groupByColumns);
                    groupValue.setValue(formatValue(value));
                    groupByResults.add(groupValue);
                }
            }
        }

        AggregationResult aggregationResult = new AggregationResult(groupByResults, _groupByColumns,
                functionName);
        aggregationResults.add(aggregationResult);
    }

    return aggregationResults;
}

From source file:com.linkedin.pinot.core.query.aggregation.groupby.AggregationGroupByOperatorService.java

public List<JSONObject> renderGroupByOperators(List<Map<String, Serializable>> finalAggregationResult) {
    try {/*from   w  w w  .j  a va  2  s.c o  m*/
        if (finalAggregationResult == null
                || finalAggregationResult.size() != _aggregationFunctionList.size()) {
            return null;
        }
        List<JSONObject> retJsonResultList = new ArrayList<JSONObject>();
        for (int i = 0; i < _aggregationFunctionList.size(); ++i) {
            JSONArray groupByResultsArray = new JSONArray();

            int groupSize = _groupByColumns.size();
            Map<String, Serializable> reducedGroupByResult = finalAggregationResult.get(i);
            AggregationFunction aggregationFunction = _aggregationFunctionList.get(i);

            if (!reducedGroupByResult.isEmpty()) {
                boolean reverseOrder = aggregationFunction.getFunctionName().startsWith(MIN_PREFIX);

                MinMaxPriorityQueue<ImmutablePair<Serializable, String>> minMaxPriorityQueue = getMinMaxPriorityQueue(
                        reducedGroupByResult.values().iterator().next(), _groupByTopN, reverseOrder);

                if (minMaxPriorityQueue != null) {
                    // The MinMaxPriorityQueue will only add TOP N
                    for (String groupedKey : reducedGroupByResult.keySet()) {
                        minMaxPriorityQueue
                                .add(new ImmutablePair(reducedGroupByResult.get(groupedKey), groupedKey));
                    }

                    ImmutablePair res;
                    while ((res = (ImmutablePair) minMaxPriorityQueue.pollFirst()) != null) {
                        JSONObject groupByResultObject = new JSONObject();
                        groupByResultObject.put("group",
                                new JSONArray(((String) res.getRight()).split(
                                        GroupByConstants.GroupByDelimiter.groupByMultiDelimeter.toString(),
                                        groupSize)));
                        //          if (res.getFirst() instanceof Number) {
                        //            groupByResultObject.put("value", df.format(res.getFirst()));
                        //          } else {
                        //            groupByResultObject.put("value", res.getFirst());
                        //          }
                        //          groupByResultsArray.put(realGroupSize - 1 - j, groupByResultObject);
                        groupByResultObject.put("value",
                                aggregationFunction.render((Serializable) res.getLeft()).get("value"));
                        groupByResultsArray.put(groupByResultObject);
                    }
                }
            }

            JSONObject result = new JSONObject();
            result.put("function", aggregationFunction.getFunctionName());
            result.put("groupByResult", groupByResultsArray);
            result.put("groupByColumns", new JSONArray(_groupByColumns));
            retJsonResultList.add(result);
        }
        return retJsonResultList;
    } catch (JSONException e) {
        LOGGER.error("Caught exception while processing group by aggregation", e);
        Utils.rethrowException(e);
        throw new AssertionError("Should not reach this");
    }
}

From source file:com.mobilecashout.osprey.plugin.PluginManager.java

public DeploymentAction[] actionsFromCommand(String command, DeploymentPlan deploymentPlan, String localRemote,
        DeploymentContext context) throws ProjectConfigurationError {
    if (null == command) {
        return new DeploymentAction[0];
    }/*from  www  .j  a  v a 2s  .  c o  m*/
    ImmutablePair<String, PluginInterface> resolvedPair = null;
    try {
        resolvedPair = resolve(command, localRemote);
    } catch (IncompatibleEnvironmentError incompatibleEnvironmentError) {
        throw new ProjectConfigurationError(String.format(
                "Plugin %s is not available for execution on %s environment",
                incompatibleEnvironmentError.getHashName(), incompatibleEnvironmentError.getEnvironment()));
    }
    if (null == resolvedPair) {
        throw new ProjectConfigurationError(String.format(
                "Plugin able to handle command <%s> in environment <%s> was not found", command, localRemote));
    }
    try {
        return resolvedPair.getRight().actionFromCommand(resolvedPair.getLeft(), deploymentPlan, context);
    } catch (DeploymentActionError deploymentActionError) {
        throw new ProjectConfigurationError(deploymentActionError);
    }
}

From source file:edu.umich.flowfence.service.NamespaceSharedPrefs.java

public synchronized Map<String, ?> getAll(String namespace) {
    if (mTaintSetNamespace.equals(Objects.requireNonNull(namespace))) {
        throw new IllegalArgumentException("Bad namespace " + namespace);
    }//from   ww w  .  j av a 2  s  .  c om

    final Map<String, ?> all = mBasePrefs.getAll();
    final Map<String, Object> rv = new HashMap<>();
    final boolean isTaintNS = mTaintNamespaces.contains(namespace);

    for (Map.Entry<String, ?> entry : all.entrySet()) {
        final ImmutablePair<String, String> typeAndKey = getTypeAndKey(entry.getKey());
        if (namespace.equals(typeAndKey.getLeft())) {
            final Object value;
            if (isTaintNS) {
                value = getTaintById((Integer) entry.getValue());
            } else {
                value = entry.getValue();
            }
            rv.put(typeAndKey.getRight(), value);
        }
    }

    return rv;
}

From source file:io.github.collaboratory.LauncherCWL.java

private Map<String, Object> runCWLCommand(String cwlFile, String jsonSettings, String outputDir,
        String workingDir) {//w w w . j  av a 2  s  .  c  o m
    // Get extras from config file
    ArrayList<String> extraFlags = (ArrayList) config.getList("cwltool-extra-parameters");

    if (extraFlags.size() > 0) {
        System.out.println("########### WARNING ###########");
        System.out.println(
                "You are using extra flags for CWLtool which may not be supported. Use at your own risk.");
    }

    // Trim the input
    extraFlags = (ArrayList) extraFlags.stream().map(flag -> trimAndPrintInput(flag))
            .collect(Collectors.toList());

    // Create cwltool command
    ArrayList<String> command = new ArrayList<>(Arrays.asList("cwltool", "--enable-dev", "--non-strict",
            "--enable-net", "--outdir", outputDir, "--tmpdir-prefix", workingDir, cwlFile, jsonSettings));
    command.addAll(1, extraFlags);

    final String joined = Joiner.on(" ").join(command);
    System.out.println("Executing: " + joined);
    final ImmutablePair<String, String> execute = Utilities.executeCommand(joined);
    // mutate stderr and stdout into format for output

    String stdout = execute.getLeft().replaceAll("(?m)^", "\t");
    String stderr = execute.getRight().replaceAll("(?m)^", "\t");

    final String cwltool = "cwltool";
    outputIntegrationOutput(outputDir, execute, stdout, stderr, cwltool);
    Map<String, Object> obj = (Map<String, Object>) yaml.load(execute.getLeft());
    return obj;
}

From source file:com.joyent.manta.client.multipart.ServerSideMultipartManager.java

/**
 * <p>Completes a multipart transfer by assembling the parts on Manta as an
 * synchronous operation.</p>//from w  ww .  j av a2 s.co m
 *
 * <p>Note: this performs a terminal operation on the partsStream and
 * thereby will close the stream.</p>
 *
 * @param upload multipart upload object
 * @param partsStream stream of multipart part objects
 * @throws IOException thrown if there is a problem connecting to Manta
 */
@Override
public void complete(final ServerSideMultipartUpload upload,
        final Stream<? extends MantaMultipartUploadTuple> partsStream) throws IOException {
    Validate.notNull(upload, "Upload state object must not be null");

    final String path = upload.getPath();
    final String postPath = upload.getPartsDirectory();
    final HttpPost post = httpHelper.getRequestFactory().post(postPath + "/commit");

    final byte[] jsonRequest;
    final int numParts;

    try {
        ImmutablePair<byte[], Integer> pair = createCommitRequestBody(partsStream);
        jsonRequest = pair.getLeft();
        numParts = pair.getRight();
    } catch (NullPointerException | IllegalArgumentException e) {
        String msg = "Expected response field was missing or malformed";
        MantaMultipartException me = new MantaMultipartException(msg, e);
        annotateException(me, post, null, path, null);
        throw me;
    }

    final HttpEntity entity = new ExposedByteArrayEntity(jsonRequest, ContentType.APPLICATION_JSON);
    post.setEntity(entity);

    final int expectedStatusCode = HttpStatus.SC_CREATED;
    final CloseableHttpClient httpClient = httpHelper.getConnectionContext().getHttpClient();

    try (CloseableHttpResponse response = httpClient.execute(post)) {
        StatusLine statusLine = response.getStatusLine();

        validateStatusCode(expectedStatusCode, statusLine.getStatusCode(), "Unable to create multipart upload",
                post, response, path, jsonRequest);

        Header location = response.getFirstHeader(HttpHeaders.LOCATION);

        if (location != null && LOGGER.isInfoEnabled()) {
            LOGGER.info("Multipart upload [{}] for file [{}] from [{}] parts has completed", upload.getId(),
                    location.getValue(), numParts);
        }
    } catch (MantaMultipartException | MantaClientHttpResponseException me) {
        // Already annotated
        throw me;
    } catch (Exception e) {
        String msg = "Error initiating multipart upload completion";
        MantaMultipartException me = new MantaMultipartException(msg, e);
        annotateException(me, post, null, path, jsonRequest);
        throw me;
    }
}

From source file:edu.umich.flowfence.service.NamespaceSharedPrefs.java

private SharedPreferences.OnSharedPreferenceChangeListener registerListener() {
    SharedPreferences.OnSharedPreferenceChangeListener prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override//  ww  w.  j a  v  a  2s.  c o  m
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            ImmutablePair<String, String> typeAndKey = getTypeAndKey(key);
            Set<OnNamespacePreferenceChangeListener> listeners;
            synchronized (mListenerMap) {
                listeners = new HashSet<>(mListenerMap.keySet());
            }
            for (OnNamespacePreferenceChangeListener listener : listeners) {
                if (listener != null) {
                    listener.onNamespacePreferenceChanged(NamespaceSharedPrefs.this, typeAndKey.getLeft(),
                            typeAndKey.getRight());
                }
            }
        }
    };
    mBasePrefs.registerOnSharedPreferenceChangeListener(prefListener);
    return prefListener;
}

From source file:com.hortonworks.registries.schemaregistry.SchemaVersionLifecycleManager.java

public void deleteSchemaVersion(Long schemaVersionId) throws SchemaNotFoundException, SchemaLifecycleException {
    ImmutablePair<SchemaVersionLifecycleContext, SchemaVersionLifecycleState> pair = createSchemaVersionLifeCycleContextAndState(
            schemaVersionId);//from  w  w w.  j  a v  a  2  s  .c  om
    ((InbuiltSchemaVersionLifecycleState) pair.getRight()).delete(pair.getLeft());
}

From source file:com.hortonworks.registries.schemaregistry.SchemaVersionLifecycleManager.java

public void enableSchemaVersion(Long schemaVersionId) throws SchemaNotFoundException, SchemaLifecycleException,
        IncompatibleSchemaException, SchemaBranchNotFoundException {
    ImmutablePair<SchemaVersionLifecycleContext, SchemaVersionLifecycleState> pair = createSchemaVersionLifeCycleContextAndState(
            schemaVersionId);// w ww  . ja v  a2 s  . c  o  m
    ((InbuiltSchemaVersionLifecycleState) pair.getRight()).enable(pair.getLeft());
}

From source file:com.hortonworks.registries.schemaregistry.SchemaVersionLifecycleManager.java

public void archiveSchemaVersion(Long schemaVersionId)
        throws SchemaNotFoundException, SchemaLifecycleException {
    ImmutablePair<SchemaVersionLifecycleContext, SchemaVersionLifecycleState> pair = createSchemaVersionLifeCycleContextAndState(
            schemaVersionId);/* w  w w . ja  v a 2  s .c  o  m*/
    ((InbuiltSchemaVersionLifecycleState) pair.getRight()).archive(pair.getLeft());
}