Example usage for java.util HashSet isEmpty

List of usage examples for java.util HashSet isEmpty

Introduction

In this page you can find the example usage for java.util HashSet isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:org.sakaiproject.memory.impl.EhcacheCache.java

@Override
public void putAll(Map<? extends K, ? extends V> map) {
    if (map != null && !map.isEmpty()) {
        HashSet<Element> elements = new HashSet<Element>(map.size());
        for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
            if (entry.getKey() != null) {
                elements.add(new Element(entry.getKey(), entry.getValue()));
            }/*from   w  w w. ja va  2 s  .c om*/
        }
        if (!elements.isEmpty()) {
            cache.putAll(elements);
        }
    }
}

From source file:com.facebook.FacebookAppLinkResolver.java

/**
 * Asynchronously resolves App Link data for multiple Urls
 *
 * @param uris A list of Uri objects to resolve into App Links
 * @return A Task that, when successful, will return a Map of Uri->AppLink for each Uri that was successfully
 * resolved into an App Link. Uris that could not be resolved into App Links will not be present in the Map.
 * In the case of general server errors, the task will be completed with the corresponding error.
 *///from   www . ja va2  s  . c  o m
public Task<Map<Uri, AppLink>> getAppLinkFromUrlsInBackground(List<Uri> uris) {
    final Map<Uri, AppLink> appLinkResults = new HashMap<Uri, AppLink>();
    final HashSet<Uri> urisToRequest = new HashSet<Uri>();
    StringBuilder graphRequestFields = new StringBuilder();

    for (Uri uri : uris) {
        AppLink appLink = null;
        synchronized (cachedAppLinks) {
            appLink = cachedAppLinks.get(uri);
        }

        if (appLink != null) {
            appLinkResults.put(uri, appLink);
        } else {
            if (!urisToRequest.isEmpty()) {
                graphRequestFields.append(',');
            }
            graphRequestFields.append(uri.toString());
            urisToRequest.add(uri);
        }
    }

    if (urisToRequest.isEmpty()) {
        return Task.forResult(appLinkResults);
    }

    final Task<Map<Uri, AppLink>>.TaskCompletionSource taskCompletionSource = Task.create();

    Bundle appLinkRequestParameters = new Bundle();

    appLinkRequestParameters.putString("ids", graphRequestFields.toString());
    appLinkRequestParameters.putString("fields", String.format("%s.fields(%s,%s)", APP_LINK_KEY,
            APP_LINK_ANDROID_TARGET_KEY, APP_LINK_WEB_TARGET_KEY));

    Request appLinkRequest = new Request(null, /* Session */
            "", /* Graph path */
            appLinkRequestParameters, /* Query parameters */
            null, /* HttpMethod */
            new Request.Callback() { /* Callback */
                @Override
                public void onCompleted(Response response) {
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        taskCompletionSource.setError(error.getException());
                        return;
                    }

                    GraphObject responseObject = response.getGraphObject();
                    JSONObject responseJson = responseObject != null ? responseObject.getInnerJSONObject()
                            : null;
                    if (responseJson == null) {
                        taskCompletionSource.setResult(appLinkResults);
                        return;
                    }

                    for (Uri uri : urisToRequest) {
                        String uriString = uri.toString();
                        if (!responseJson.has(uriString)) {
                            continue;
                        }

                        JSONObject urlData = null;
                        try {
                            urlData = responseJson.getJSONObject(uri.toString());
                            JSONObject appLinkData = urlData.getJSONObject(APP_LINK_KEY);

                            JSONArray rawTargets = appLinkData.getJSONArray(APP_LINK_ANDROID_TARGET_KEY);

                            int targetsCount = rawTargets.length();
                            List<AppLink.Target> targets = new ArrayList<AppLink.Target>(targetsCount);

                            for (int i = 0; i < targetsCount; i++) {
                                AppLink.Target target = getAndroidTargetFromJson(rawTargets.getJSONObject(i));
                                if (target != null) {
                                    targets.add(target);
                                }
                            }

                            Uri webFallbackUrl = getWebFallbackUriFromJson(uri, appLinkData);
                            AppLink appLink = new AppLink(uri, targets, webFallbackUrl);

                            appLinkResults.put(uri, appLink);
                            synchronized (cachedAppLinks) {
                                cachedAppLinks.put(uri, appLink);
                            }
                        } catch (JSONException e) {
                            // The data for this uri was missing or badly formed.
                            continue;
                        }
                    }

                    taskCompletionSource.setResult(appLinkResults);
                }
            });

    appLinkRequest.executeAsync();

    return taskCompletionSource.getTask();
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ComplexUnnestToProductRule.java

private boolean findPlanPartition(AbstractLogicalOperator op, HashSet<LogicalVariable> innerUsedVars,
        HashSet<LogicalVariable> outerUsedVars, List<ILogicalOperator> innerOps,
        List<ILogicalOperator> outerOps, List<ILogicalOperator> topSelects, boolean belowSecondUnnest)
        throws AlgebricksException {
    if (belowSecondUnnest && innerUsedVars.isEmpty()) {
        // Trivially joinable.
        return true;
    }/*from   w ww.  j  a v a2 s.  c o  m*/
    if (!belowSecondUnnest) {
        // Bail on the following operators.
        switch (op.getOperatorTag()) {
        case AGGREGATE:
        case SUBPLAN:
        case GROUP:
        case UNNEST_MAP:
            return false;
        }
    }
    switch (op.getOperatorTag()) {
    case UNNEST:
    case DATASOURCESCAN: {
        // We may have reached this state by descending through a subplan.
        outerOps.add(op);
        return true;
    }
    case INNERJOIN:
    case LEFTOUTERJOIN: {
        // Make sure that no variables that are live under this join are needed by the inner.
        List<LogicalVariable> liveVars = new ArrayList<LogicalVariable>();
        VariableUtilities.getLiveVariables(op, liveVars);
        for (LogicalVariable liveVar : liveVars) {
            if (innerUsedVars.contains(liveVar)) {
                return false;
            }
        }
        outerOps.add(op);
        return true;
    }
    case SELECT: {
        // Remember this select to pulling it above the join.
        if (innerUsedVars.isEmpty()) {
            outerOps.add(op);
        } else {
            topSelects.add(op);
        }
        break;
    }
    case PROJECT: {
        // Throw away projects from the plan since we are pulling selects up.
        break;
    }
    case EMPTYTUPLESOURCE:
    case NESTEDTUPLESOURCE: {
        if (belowSecondUnnest) {
            // We have successfully partitioned the plan into independent parts to be plugged into the join.
            return true;
        } else {
            // We could not find a second unnest or a join.
            return false;
        }
    }
    default: {
        // The inner is trivially independent.
        if (!belowSecondUnnest && innerUsedVars.isEmpty()) {
            outerOps.add(op);
            break;
        }

        // Examine produced vars to determine which partition uses them.
        List<LogicalVariable> producedVars = new ArrayList<LogicalVariable>();
        VariableUtilities.getProducedVariables(op, producedVars);
        int outerMatches = 0;
        int innerMatches = 0;
        for (LogicalVariable producedVar : producedVars) {
            if (outerUsedVars.contains(producedVar)) {
                outerMatches++;
            }
            if (innerUsedVars.contains(producedVar)) {
                innerMatches++;
            }
        }

        HashSet<LogicalVariable> targetUsedVars = null;
        if (outerMatches == producedVars.size() && !producedVars.isEmpty()) {
            // All produced vars used by outer partition.
            outerOps.add(op);
            targetUsedVars = outerUsedVars;
        }
        if (innerMatches == producedVars.size() && !producedVars.isEmpty()) {
            // All produced vars used by inner partition.
            innerOps.add(op);
            targetUsedVars = innerUsedVars;
        }
        if (innerMatches == 0 && outerMatches == 0) {
            // Op produces variables that are not used in the part of the plan we've seen (or it doesn't produce any vars).
            // Try to figure out where it belongs by analyzing the used variables.
            List<LogicalVariable> usedVars = new ArrayList<LogicalVariable>();
            VariableUtilities.getUsedVariables(op, usedVars);
            for (LogicalVariable usedVar : usedVars) {
                boolean canBreak = false;
                if (outerUsedVars.contains(usedVar)) {
                    outerOps.add(op);
                    targetUsedVars = outerUsedVars;
                    canBreak = true;
                }
                if (innerUsedVars.contains(usedVar)) {
                    innerOps.add(op);
                    targetUsedVars = innerUsedVars;
                    canBreak = true;
                }
                if (canBreak) {
                    break;
                }
            }
            // TODO: For now we bail here, but we could remember such ops and determine their target partition at a later point.
            if (targetUsedVars == null) {
                return false;
            }
        } else if (innerMatches != 0 && outerMatches != 0) {
            // The current operator produces variables that are used by both partitions, so the inner and outer are not independent and, therefore, we cannot create a join.
            // TODO: We may still be able to split the operator to create a viable partitioning.
            return false;
        }
        // Update used variables of partition that op belongs to.
        if (op.hasNestedPlans() && op.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
            AbstractOperatorWithNestedPlans opWithNestedPlans = (AbstractOperatorWithNestedPlans) op;
            opWithNestedPlans.getUsedVariablesExceptNestedPlans(targetUsedVars);
        } else {
            VariableUtilities.getUsedVariables(op, targetUsedVars);
        }
        break;
    }
    }
    if (!op.hasInputs()) {
        if (!belowSecondUnnest) {
            // We could not find a second unnest or a join.
            return false;
        } else {
            // We have successfully partitioned the plan into independent parts to be plugged into the join.
            return true;
        }
    }
    return findPlanPartition((AbstractLogicalOperator) op.getInputs().get(0).getValue(), innerUsedVars,
            outerUsedVars, innerOps, outerOps, topSelects, belowSecondUnnest);
}

From source file:com.facebook.applinks.FacebookAppLinkResolver.java

/**
 * Asynchronously resolves App Link data for multiple URLs
 *
 * @param uris A list of Uri objects to resolve into App Links
 * @return A Task that, when successful, will return a Map of Uri->AppLink for each Uri that was
 * successfully resolved into an App Link. Uris that could not be resolved into App Links will
 * not be present in the Map. In the case of general server errors, the task will be completed
 * with the corresponding error.//from ww w. j  a  v  a  2  s  .  co  m
 */
public Task<Map<Uri, AppLink>> getAppLinkFromUrlsInBackground(List<Uri> uris) {
    final Map<Uri, AppLink> appLinkResults = new HashMap<Uri, AppLink>();
    final HashSet<Uri> urisToRequest = new HashSet<Uri>();
    StringBuilder graphRequestFields = new StringBuilder();

    for (Uri uri : uris) {
        AppLink appLink = null;
        synchronized (cachedAppLinks) {
            appLink = cachedAppLinks.get(uri);
        }

        if (appLink != null) {
            appLinkResults.put(uri, appLink);
        } else {
            if (!urisToRequest.isEmpty()) {
                graphRequestFields.append(',');
            }
            graphRequestFields.append(uri.toString());
            urisToRequest.add(uri);
        }
    }

    if (urisToRequest.isEmpty()) {
        return Task.forResult(appLinkResults);
    }

    final Task<Map<Uri, AppLink>>.TaskCompletionSource taskCompletionSource = Task.create();

    Bundle appLinkRequestParameters = new Bundle();

    appLinkRequestParameters.putString("ids", graphRequestFields.toString());
    appLinkRequestParameters.putString("fields", String.format("%s.fields(%s,%s)", APP_LINK_KEY,
            APP_LINK_ANDROID_TARGET_KEY, APP_LINK_WEB_TARGET_KEY));
    GraphRequest appLinkRequest = new GraphRequest(
            // We will use the current access token if we have one else we will use the client
            // token
            AccessToken.getCurrentAccessToken(), /* Access Token */
            "", /* Graph path */
            appLinkRequestParameters, /* Query parameters */
            null, /* HttpMethod */
            new GraphRequest.Callback() { /* Callback */
                @Override
                public void onCompleted(GraphResponse response) {
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        taskCompletionSource.setError(error.getException());
                        return;
                    }

                    JSONObject responseJson = response.getJSONObject();
                    if (responseJson == null) {
                        taskCompletionSource.setResult(appLinkResults);
                        return;
                    }

                    for (Uri uri : urisToRequest) {
                        String uriString = uri.toString();
                        if (!responseJson.has(uriString)) {
                            continue;
                        }

                        JSONObject urlData = null;
                        try {
                            urlData = responseJson.getJSONObject(uri.toString());
                            JSONObject appLinkData = urlData.getJSONObject(APP_LINK_KEY);

                            JSONArray rawTargets = appLinkData.getJSONArray(APP_LINK_ANDROID_TARGET_KEY);

                            int targetsCount = rawTargets.length();
                            List<AppLink.Target> targets = new ArrayList<AppLink.Target>(targetsCount);

                            for (int i = 0; i < targetsCount; i++) {
                                AppLink.Target target = getAndroidTargetFromJson(rawTargets.getJSONObject(i));
                                if (target != null) {
                                    targets.add(target);
                                }
                            }

                            Uri webFallbackUrl = getWebFallbackUriFromJson(uri, appLinkData);
                            AppLink appLink = new AppLink(uri, targets, webFallbackUrl);

                            appLinkResults.put(uri, appLink);
                            synchronized (cachedAppLinks) {
                                cachedAppLinks.put(uri, appLink);
                            }
                        } catch (JSONException e) {
                            // The data for this uri was missing or badly formed.
                            continue;
                        }
                    }

                    taskCompletionSource.setResult(appLinkResults);
                }
            });

    appLinkRequest.executeAsync();

    return taskCompletionSource.getTask();
}

From source file:org.apache.hyracks.algebricks.rewriter.rules.ComplexUnnestToProductRule.java

private boolean findPlanPartition(AbstractLogicalOperator op, HashSet<LogicalVariable> innerUsedVars,
        HashSet<LogicalVariable> outerUsedVars, List<ILogicalOperator> innerOps,
        List<ILogicalOperator> outerOps, List<ILogicalOperator> topSelects, boolean belowSecondUnnest)
        throws AlgebricksException {
    if (belowSecondUnnest && innerUsedVars.isEmpty()) {
        // Trivially joinable.
        return true;
    }/*from  www  . j a  va 2s.  co m*/
    if (!belowSecondUnnest) {
        // Bail on the following operators.
        switch (op.getOperatorTag()) {
        case AGGREGATE:
        case SUBPLAN:
        case GROUP:
        case UNNEST_MAP:
            return false;
        }
    }
    switch (op.getOperatorTag()) {
    case UNNEST:
    case DATASOURCESCAN: {
        // We may have reached this state by descending through a subplan.
        outerOps.add(op);
        return true;
    }
    case INNERJOIN:
    case LEFTOUTERJOIN: {
        // Make sure that no variables that are live under this join are needed by the inner.
        List<LogicalVariable> liveVars = new ArrayList<LogicalVariable>();
        VariableUtilities.getLiveVariables(op, liveVars);
        for (LogicalVariable liveVar : liveVars) {
            if (innerUsedVars.contains(liveVar)) {
                return false;
            }
        }
        outerOps.add(op);
        return true;
    }
    case SELECT: {
        // Remember this select to pulling it above the join.
        if (innerUsedVars.isEmpty()) {
            outerOps.add(op);
        } else {
            topSelects.add(op);
        }
        break;
    }
    case PROJECT: {
        // Throw away projects from the plan since we are pulling selects up.
        break;
    }
    case EMPTYTUPLESOURCE:
    case NESTEDTUPLESOURCE: {
        if (belowSecondUnnest) {
            // We have successfully partitioned the plan into independent parts to be plugged into the join.
            return true;
        } else {
            // We could not find a second unnest or a join.
            return false;
        }
    }
    default: {
        // The inner is trivially independent.
        if (!belowSecondUnnest && innerUsedVars.isEmpty()) {
            outerOps.add(op);
            break;
        }

        // Examine produced vars to determine which partition uses them.
        List<LogicalVariable> producedVars = new ArrayList<LogicalVariable>();
        VariableUtilities.getProducedVariables(op, producedVars);
        int outerMatches = 0;
        int innerMatches = 0;
        for (LogicalVariable producedVar : producedVars) {
            if (outerUsedVars.contains(producedVar)) {
                outerMatches++;
            }
            if (innerUsedVars.contains(producedVar)) {
                innerMatches++;
            }
        }

        HashSet<LogicalVariable> targetUsedVars = null;
        if (outerMatches == producedVars.size() && !producedVars.isEmpty()) {
            // All produced vars used by outer partition.
            outerOps.add(op);
            targetUsedVars = outerUsedVars;
        }
        if (innerMatches == producedVars.size() && !producedVars.isEmpty()) {
            // All produced vars used by inner partition.
            innerOps.add(op);
            targetUsedVars = innerUsedVars;
        }
        if (innerMatches == 0 && outerMatches == 0) {
            // Op produces variables that are not used in the part of the plan we've seen (or it doesn't produce any vars).
            // Try to figure out where it belongs by analyzing the used variables.
            List<LogicalVariable> usedVars = new ArrayList<LogicalVariable>();
            VariableUtilities.getUsedVariables(op, usedVars);
            for (LogicalVariable usedVar : usedVars) {
                boolean canBreak = false;
                if (outerUsedVars.contains(usedVar)) {
                    outerOps.add(op);
                    targetUsedVars = outerUsedVars;
                    canBreak = true;
                }
                if (innerUsedVars.contains(usedVar)) {
                    innerOps.add(op);
                    targetUsedVars = innerUsedVars;
                    canBreak = true;
                }
                if (canBreak) {
                    break;
                }
            }
        } else if (innerMatches != 0 && outerMatches != 0) {
            // The current operator produces variables that are used by both partitions, so the inner and outer are not independent and, therefore, we cannot create a join.
            // TODO: We may still be able to split the operator to create a viable partitioning.
            return false;
        }

        // TODO: For now we bail here, but we could remember such ops and determine their target partition at a later point.
        if (targetUsedVars == null) {
            return false;
        }

        // Update used variables of partition that op belongs to.
        if (op.hasNestedPlans() && op.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
            AbstractOperatorWithNestedPlans opWithNestedPlans = (AbstractOperatorWithNestedPlans) op;
            opWithNestedPlans.getUsedVariablesExceptNestedPlans(targetUsedVars);
        } else {
            VariableUtilities.getUsedVariables(op, targetUsedVars);
        }
        break;
    }
    }
    if (!op.hasInputs()) {
        if (!belowSecondUnnest) {
            // We could not find a second unnest or a join.
            return false;
        } else {
            // We have successfully partitioned the plan into independent parts to be plugged into the join.
            return true;
        }
    }
    return findPlanPartition((AbstractLogicalOperator) op.getInputs().get(0).getValue(), innerUsedVars,
            outerUsedVars, innerOps, outerOps, topSelects, belowSecondUnnest);
}

From source file:org.apache.sysml.hops.codegen.opt.ReachabilityGraph.java

private ArrayList<Pair<CutSet, Double>> evaluateCutSets(ArrayList<ArrayList<NodeLink>> candCS,
        ArrayList<ArrayList<NodeLink>> remain) {
    ArrayList<Pair<CutSet, Double>> cutSets = new ArrayList<>();

    for (ArrayList<NodeLink> cand : candCS) {
        HashSet<NodeLink> probe = new HashSet<>(cand);

        //determine subproblems for cutset candidates
        HashSet<NodeLink> part1 = new HashSet<>();
        rCollectInputs(_root, probe, part1);
        HashSet<NodeLink> part2 = new HashSet<>();
        for (NodeLink rNode : cand)
            rCollectInputs(rNode, probe, part2);

        //select, score and create cutsets
        if (!CollectionUtils.containsAny(part1, part2) && !part1.isEmpty() && !part2.isEmpty()) {
            //score cutsets (smaller is better)
            double base = UtilFunctions.pow(2, _matPoints.size());
            double numComb = UtilFunctions.pow(2, cand.size());
            double score = (numComb - 1) / numComb * base + 1 / numComb * UtilFunctions.pow(2, part1.size())
                    + 1 / numComb * UtilFunctions.pow(2, part2.size());

            //construct cutset
            cutSets.add(Pair.of(new CutSet(cand.stream().map(p -> p._p).toArray(InterestingPoint[]::new),
                    part1.stream().map(p -> p._p).toArray(InterestingPoint[]::new),
                    part2.stream().map(p -> p._p).toArray(InterestingPoint[]::new)), score));
        } else {//w  ww . j  a v  a  2s  .c o m
            remain.add(cand);
        }
    }

    return cutSets;
}

From source file:br.usp.poli.lta.cereda.nfa2dfa.utils.Conversion.java

private Set<Set<Integer>> split(Set<Integer> S, Set<Set<Integer>> p) {
    Set<Set<Integer>> result = new HashSet<>();
    Set<Token> sigma = alphabet();
    Set<Integer> temp = null;

    HashSet<Integer> s2 = new HashSet<>();
    for (Token c : sigma) {
        for (int s : S) {
            if (temp == null) {
                temp = getSet(s, c, p);// w  ww . ja va  2s  . co  m
            } else {
                if (!temp.equals(getSet(s, c, p))) {
                    s2.add(s);
                }
            }
        }
        temp = null;
    }

    if (!s2.isEmpty()) {
        Set<Integer> s1 = new HashSet<>(S);
        s1.removeAll(s2);
        result.add(s1);
        result.add(s2);
    } else {
        result.add(S);
    }

    return result;
}

From source file:com.mousefeed.eclipse.NagPopUp.java

/**
 * Handle link activation.//w  ww. j av a 2  s  . co m
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
final void doLinkActivated() {
    Object data = null;

    final IWorkbench workbench = Activator.getDefault().getWorkbench();
    final ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);

    final Command command = commandService.getCommand(actionId);
    if (command != null) {
        final HashSet allParameterizedCommands = new HashSet();
        try {
            allParameterizedCommands.addAll(ParameterizedCommand.generateCombinations(command));
        } catch (final NotDefinedException e) {
            // It is safe to just ignore undefined commands.
        }
        if (!allParameterizedCommands.isEmpty()) {
            data = allParameterizedCommands.iterator().next();

            // only commands can be bound to keyboard shortcuts
            openWorkspacePreferences(data);
        }
    }

}

From source file:org.apache.samza.test.framework.TestRunner.java

/**
 * Gets the contents of the output stream represented by {@code outputDescriptor} after {@link TestRunner#run(Duration)}
 * has completed/*from   ww w. j  ava  2  s.  c om*/
 *
 * @param outputDescriptor describes the stream to be consumed
 * @param timeout timeout for consumption of stream in Ms
 * @param <StreamMessageType> type of message
 *
 * @return a map whose key is {@code partitionId} and value is messages in partition
 * @throws SamzaException Thrown when a poll is incomplete
 */
public static <StreamMessageType> Map<Integer, List<StreamMessageType>> consumeStream(
        InMemoryOutputDescriptor outputDescriptor, Duration timeout) throws SamzaException {
    Preconditions.checkNotNull(outputDescriptor);
    String streamId = outputDescriptor.getStreamId();
    String systemName = outputDescriptor.getSystemName();
    Set<SystemStreamPartition> ssps = new HashSet<>();
    Set<String> streamIds = new HashSet<>();
    streamIds.add(streamId);
    SystemFactory factory = new InMemorySystemFactory();
    Config config = new MapConfig(outputDescriptor.toConfig(),
            outputDescriptor.getSystemDescriptor().toConfig());
    Map<String, SystemStreamMetadata> metadata = factory.getAdmin(systemName, config)
            .getSystemStreamMetadata(streamIds);
    SystemConsumer consumer = factory.getConsumer(systemName, config, null);
    String name = (String) outputDescriptor.getPhysicalName().orElse(streamId);
    metadata.get(name).getSystemStreamPartitionMetadata().keySet().forEach(partition -> {
        SystemStreamPartition temp = new SystemStreamPartition(systemName, streamId, partition);
        ssps.add(temp);
        consumer.register(temp, "0");
    });

    long t = System.currentTimeMillis();
    Map<SystemStreamPartition, List<IncomingMessageEnvelope>> output = new HashMap<>();
    HashSet<SystemStreamPartition> didNotReachEndOfStream = new HashSet<>(ssps);
    while (System.currentTimeMillis() < t + timeout.toMillis()) {
        Map<SystemStreamPartition, List<IncomingMessageEnvelope>> currentState = null;
        try {
            currentState = consumer.poll(ssps, 10);
        } catch (InterruptedException e) {
            throw new SamzaException("Timed out while consuming stream \n" + e.getMessage());
        }
        for (Map.Entry<SystemStreamPartition, List<IncomingMessageEnvelope>> entry : currentState.entrySet()) {
            SystemStreamPartition ssp = entry.getKey();
            output.computeIfAbsent(ssp, k -> new LinkedList<IncomingMessageEnvelope>());
            List<IncomingMessageEnvelope> currentBuffer = entry.getValue();
            Integer totalMessagesToFetch = Integer.valueOf(metadata.get(outputDescriptor.getStreamId())
                    .getSystemStreamPartitionMetadata().get(ssp.getPartition()).getNewestOffset());
            if (output.get(ssp).size() + currentBuffer.size() == totalMessagesToFetch) {
                didNotReachEndOfStream.remove(entry.getKey());
                ssps.remove(entry.getKey());
            }
            output.get(ssp).addAll(currentBuffer);
        }
        if (didNotReachEndOfStream.isEmpty()) {
            break;
        }
    }

    if (!didNotReachEndOfStream.isEmpty()) {
        throw new IllegalStateException("Could not poll for all system stream partitions");
    }

    return output.entrySet().stream().collect(
            Collectors.toMap(entry -> entry.getKey().getPartition().getPartitionId(), entry -> entry.getValue()
                    .stream().map(e -> (StreamMessageType) e.getMessage()).collect(Collectors.toList())));
}

From source file:models.Issue.java

@Override
public void updateProperties() {
    HashSet<String> updateProps = new HashSet<>();
    // update null milestone explicitly
    if (this.milestone == null) {
        updateProps.add("milestone");
    }/* w  w w . ja  v a2  s  . co  m*/
    // update null assignee explicitly
    if (this.assignee == null) {
        updateProps.add("assignee");
    }
    if (!updateProps.isEmpty()) {
        Ebean.update(this, updateProps);
    }
}