下面列出了com.google.common.collect.ListMultimap#isEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
}
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);
}
}
}
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());
}
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());
}
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);
}
}
}
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);
}
}
/**
* 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();
}
}
/**
* 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();
}
}
@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();
}
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);
}
}
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());
}