Java Code Examples for com.google.common.collect.ListMultimap#isEmpty()

The following examples show how to use com.google.common.collect.ListMultimap#isEmpty() . 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: InitiateWriteTraversal.java    From tasmo with Apache License 2.0 6 votes vote down vote up
private void processValues(ListMultimap<InitiateTraverserKey, PathTraverser> valueTraversers,
        String timerName,
        WrittenEventContext batchContext,
        TenantIdAndCentricId tenantIdAndCentricId,
        TenantIdAndCentricId globalCentricId,
        TenantIdAndCentricId userCentricId,
        WrittenEvent writtenEvent,
        long threadTimestamp) throws Exception {
    if (valueTraversers != null && !valueTraversers.isEmpty()) {
        LOG.startTimer(timerName);
        try {
            processValues(batchContext, tenantIdAndCentricId, globalCentricId, userCentricId, writtenEvent, valueTraversers, threadTimestamp);
        } finally {
            LOG.stopTimer(timerName);
        }
    }
}
 
Example 2
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void doIndexWritesWithExceptions(BatchMutateContext context, boolean post)
          throws IOException {
    ListMultimap<HTableInterfaceReference, Mutation> indexUpdates = post ? context.postIndexUpdates : context.preIndexUpdates;
    //short circuit, if we don't need to do any work

    if (context == null || indexUpdates == null || indexUpdates.isEmpty()) {
        return;
    }

    // get the current span, or just use a null-span to avoid a bunch of if statements
    try (TraceScope scope = Trace.startSpan("Completing " + (post ? "post" : "pre") + " index writes")) {
        Span current = scope.getSpan();
        if (current == null) {
            current = NullSpan.INSTANCE;
        }
        current.addTimelineAnnotation("Actually doing " + (post ? "post" : "pre") + " index update for first time");
        if (post) {
            postWriter.write(indexUpdates, false, context.clientVersion);
        } else {
            preWriter.write(indexUpdates, false, context.clientVersion);
        }
    }
}
 
Example 3
Source File: SwapTradeCsvPlugin.java    From Strata with Apache License 2.0 6 votes vote down vote up
private static SwapTrade parseVariableNotional(SwapTrade trade, List<CsvRow> variableRows) {
  ImmutableList<SwapLeg> legs = trade.getProduct().getLegs();
  ListMultimap<Integer, ValueStep> steps =
      extractSteps(variableRows, legs, NOTIONAL_FIELD, str -> LoaderUtils.parseDouble(str));
  if (steps.isEmpty()) {
    return trade;
  }
  // adjust the trade, inserting the variable element
  ImmutableList.Builder<SwapLeg> legBuilder = ImmutableList.builder();
  for (int i = 0; i < legs.size(); i++) {
    SwapLeg swapLeg = legs.get(i);
    List<ValueStep> legSteps = steps.get(i);
    if (!legSteps.isEmpty() && swapLeg instanceof RateCalculationSwapLeg) {
      RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg;
      NotionalSchedule notionalSchedule = leg.getNotionalSchedule().toBuilder()
          .amount(ValueSchedule.of(leg.getNotionalSchedule().getAmount().getInitialValue(), legSteps))
          .build();
      swapLeg = leg.toBuilder().notionalSchedule(notionalSchedule).build();
    }
    legBuilder.add(swapLeg);
  }
  return replaceLegs(trade, legBuilder.build());
}
 
Example 4
Source File: SwapTradeCsvPlugin.java    From Strata with Apache License 2.0 6 votes vote down vote up
private static SwapTrade parseVariableKnownAmount(SwapTrade trade, List<CsvRow> variableRows) {
  ImmutableList<SwapLeg> legs = trade.getProduct().getLegs();
  ListMultimap<Integer, ValueStep> steps =
      extractSteps(variableRows, legs, KNOWN_AMOUNT_FIELD, str -> LoaderUtils.parseDouble(str));
  if (steps.isEmpty()) {
    return trade;
  }
  // adjust the trade, inserting the variable element
  ImmutableList.Builder<SwapLeg> legBuilder = ImmutableList.builder();
  for (int i = 0; i < legs.size(); i++) {
    SwapLeg swapLeg = legs.get(i);
    List<ValueStep> legSteps = steps.get(i);
    if (!legSteps.isEmpty() && swapLeg instanceof KnownAmountSwapLeg) {
      KnownAmountSwapLeg leg = (KnownAmountSwapLeg) swapLeg;
      swapLeg = leg.toBuilder()
          .amount(ValueSchedule.of(leg.getAmount().getInitialValue(), legSteps))
          .build();
    }
    legBuilder.add(swapLeg);
  }
  return replaceLegs(trade, legBuilder.build());
}
 
Example 5
Source File: InitiateWriteTraversal.java    From tasmo with Apache License 2.0 6 votes vote down vote up
private void processValues(ListMultimap<InitiateTraverserKey, PathTraverser> valueTraversers,
        String timerName,
        WrittenEventContext batchContext,
        TenantIdAndCentricId tenantIdAndCentricId,
        TenantIdAndCentricId globalCentricId,
        TenantIdAndCentricId userCentricId,
        WrittenEvent writtenEvent,
        long threadTimestamp) throws Exception {
    if (valueTraversers != null && !valueTraversers.isEmpty()) {
        LOG.startTimer(timerName);
        try {
            processValues(batchContext, tenantIdAndCentricId, globalCentricId, userCentricId, writtenEvent, valueTraversers, threadTimestamp);
        } finally {
            LOG.stopTimer(timerName);
        }
    }
}
 
Example 6
Source File: RuleVisitor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void visitGeneratedClosure(ClassNode node) {
    MethodNode method = AstUtils.getGeneratedClosureImplMethod(node);
    Statement closureCode = method.getCode();
    SourceLocation sourceLocation = closureCode.getNodeMetaData(AST_NODE_METADATA_LOCATION_KEY);
    if (sourceLocation != null) {
        AnnotationNode metadataAnnotation = new AnnotationNode(ANNOTATION_CLASS_NODE);

        metadataAnnotation.addMember("scriptSourceDescription", new ConstantExpression(sourceLocation.getScriptSourceDescription()));
        metadataAnnotation.addMember("lineNumber", new ConstantExpression(sourceLocation.getLineNumber()));
        metadataAnnotation.addMember("columnNumber", new ConstantExpression(sourceLocation.getColumnNumber()));

        ListMultimap<String, Integer> inputs = closureCode.getNodeMetaData(AST_NODE_METADATA_INPUTS_KEY);
        if (!inputs.isEmpty()) {
            List<Expression> pathValues = Lists.newArrayListWithCapacity(inputs.size());
            List<Expression> lineNumberValues = Lists.newArrayListWithCapacity(inputs.size());
            for (Map.Entry<String, List<Integer>> input : Multimaps.asMap(inputs).entrySet()) {
                pathValues.add(new ConstantExpression(input.getKey()));
                lineNumberValues.add(new ConstantExpression(input.getValue().get(0)));
            }

            metadataAnnotation.addMember("inputPaths", new ListExpression(pathValues));
            metadataAnnotation.addMember("inputLineNumbers", new ListExpression(lineNumberValues));
        }

        node.addAnnotation(metadataAnnotation);
    }
}
 
Example 7
Source File: AbstractResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the repository has resources of a given {@link ResourceType}.
 * @param resourceType the type of resource to check.
 * @return true if the repository contains resources of the given type, false otherwise.
 */
public boolean hasResourcesOfType(@NonNull ResourceType resourceType) {
    synchronized (ITEM_MAP_LOCK) {
        ListMultimap<String, ResourceItem> map = getMap(resourceType, false);
        return map != null && !map.isEmpty();
    }
}
 
Example 8
Source File: AbstractResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the repository has resources of a given {@link ResourceType}.
 * @param resourceType the type of resource to check.
 * @return true if the repository contains resources of the given type, false otherwise.
 */
public boolean hasResourcesOfType(@NonNull ResourceType resourceType) {
    synchronized (ITEM_MAP_LOCK) {
        ListMultimap<String, ResourceItem> map = getMap(resourceType, false);
        return map != null && !map.isEmpty();
    }
}
 
Example 9
Source File: CycleDetectingLock.java    From businessworks with Apache License 2.0 5 votes vote down vote up
@Override public ListMultimap<Long, ID> lockOrDetectPotentialLocksCycle() {
  final long currentThreadId = Thread.currentThread().getId();
  synchronized (CycleDetectingLockFactory.class) {
    checkState();
    ListMultimap<Long, ID> locksInCycle = detectPotentialLocksCycle();
    if (!locksInCycle.isEmpty()) {
      // potential deadlock is found, we don't try to take this lock
      return locksInCycle;
    }

    lockThreadIsWaitingOn.put(currentThreadId, this);
  }

  // this may be blocking, but we don't expect it to cause a deadlock
  lockImplementation.lock();

  synchronized (CycleDetectingLockFactory.class) {
    // current thread is no longer waiting on this lock
    lockThreadIsWaitingOn.remove(currentThreadId);
    checkState();

    // mark it as owned by us
    lockOwnerThreadId = currentThreadId;
    lockReentranceCount++;
    // add this lock to the list of locks owned by a current thread
    locksOwnedByThread.put(currentThreadId, this);
  }
  // no deadlock is found, locking successful
  return ImmutableListMultimap.of();
}
 
Example 10
Source File: RuleVisitor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void visitGeneratedClosure(ClassNode node) {
    MethodNode method = AstUtils.getGeneratedClosureImplMethod(node);
    Statement closureCode = method.getCode();
    SourceLocation sourceLocation = closureCode.getNodeMetaData(AST_NODE_METADATA_LOCATION_KEY);
    if (sourceLocation != null) {
        AnnotationNode metadataAnnotation = new AnnotationNode(ANNOTATION_CLASS_NODE);

        metadataAnnotation.addMember("scriptSourceDescription", new ConstantExpression(sourceLocation.getScriptSourceDescription()));
        metadataAnnotation.addMember("lineNumber", new ConstantExpression(sourceLocation.getLineNumber()));
        metadataAnnotation.addMember("columnNumber", new ConstantExpression(sourceLocation.getColumnNumber()));

        ListMultimap<String, Integer> inputs = closureCode.getNodeMetaData(AST_NODE_METADATA_INPUTS_KEY);
        if (!inputs.isEmpty()) {
            List<Expression> pathValues = Lists.newArrayListWithCapacity(inputs.size());
            List<Expression> lineNumberValues = Lists.newArrayListWithCapacity(inputs.size());
            for (Map.Entry<String, List<Integer>> input : Multimaps.asMap(inputs).entrySet()) {
                pathValues.add(new ConstantExpression(input.getKey()));
                lineNumberValues.add(new ConstantExpression(input.getValue().get(0)));
            }

            metadataAnnotation.addMember("inputPaths", new ListExpression(pathValues));
            metadataAnnotation.addMember("inputLineNumbers", new ListExpression(lineNumberValues));
        }

        node.addAnnotation(metadataAnnotation);
    }
}
 
Example 11
Source File: SwapTradeCsvPlugin.java    From Strata with Apache License 2.0 5 votes vote down vote up
private static SwapTrade parseVariableFixedRate(SwapTrade trade, List<CsvRow> variableRows) {
  ImmutableList<SwapLeg> legs = trade.getProduct().getLegs();
  ListMultimap<Integer, ValueStep> steps =
      extractSteps(variableRows, legs, FIXED_RATE_FIELD, str -> LoaderUtils.parseDoublePercent(str));
  if (steps.isEmpty()) {
    return trade;
  }
  // adjust the trade, inserting the variable element
  ImmutableList.Builder<SwapLeg> legBuilder = ImmutableList.builder();
  for (int i = 0; i < legs.size(); i++) {
    SwapLeg swapLeg = legs.get(i);
    List<ValueStep> legSteps = steps.get(i);
    if (!legSteps.isEmpty() && swapLeg instanceof RateCalculationSwapLeg) {
      RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg;
      if (leg.getCalculation() instanceof FixedRateCalculation) {
        FixedRateCalculation baseCalc = (FixedRateCalculation) leg.getCalculation();
        swapLeg = leg.toBuilder()
            .calculation(baseCalc.toBuilder()
                .rate(ValueSchedule.of(baseCalc.getRate().getInitialValue(), legSteps))
                .build())
            .build();
      }
    }
    legBuilder.add(swapLeg);
  }
  return replaceLegs(trade, legBuilder.build());
}