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

The following are Jave code examples for showing how to use isEmpty() of the com.google.common.collect.Multimap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ProjectAres   File: MapUtils.java   Source Code and License Vote up 6 votes
public static <K, V> Multimap<K, V> combine(Iterable<Multimap<K, V>> maps) {
    Multimap<K, V> singleton = null;
    ImmutableMultimap.Builder<K, V> builder = null;
    for(Multimap<K, V> map : maps) {
        if(!map.isEmpty()) {
            if(singleton == null) {
                singleton = map;
            } else {
                if(builder == null) {
                    builder = ImmutableMultimap.builder();
                }
                builder.putAll(singleton);
                builder.putAll(map);
            }
        }
    }

    if(builder != null) {
        return builder.build();
    } else if(singleton != null) {
        return singleton;
    } else {
        return ImmutableMultimap.of();
    }
}
 
Example 2
Project: Elasticsearch   File: GeneratedColumnComparisonReplacer.java   Source Code and License Vote up 5 votes
public Symbol addComparisons(Symbol symbol, DocTableInfo tableInfo) {
    Multimap<ReferenceInfo, GeneratedReferenceInfo> referencedSingleReferences = extractGeneratedReferences(tableInfo);
    if (referencedSingleReferences.isEmpty()) {
        return symbol;
    } else {
        Context ctx = new Context(referencedSingleReferences);
        return process(symbol, ctx);
    }
}
 
Example 3
Project: guava-mock   File: GoogleHelpers.java   Source Code and License Vote up 4 votes
static void assertEmpty(Multimap<?, ?> multimap) {
  if (!multimap.isEmpty()) {
    fail("Not true that " + multimap + " is empty");
  }
}
 
Example 4
Project: Equella   File: InstitutionServiceImpl.java   Source Code and License Vote up 4 votes
private synchronized void setAllInstitutions(Map<Long, InstitutionStatus> map)
{
	allInstitutions = ImmutableMap.copyOf(map);

	Multimap<Long, Institution> newlyAvailable = ArrayListMultimap.create();
	Multimap<Long, Institution> newlyUnavailable = ArrayListMultimap.create(availableInstitutions);
	Builder<Long, Institution> availableBuilder = ImmutableMultimap.builder();
	ImmutableMap.Builder<Long, Long> schemaBuilder = ImmutableMap.builder();
	ImmutableMap.Builder<Long, Institution> instBuilder = ImmutableMap.builder();
	for( Entry<Long, InstitutionStatus> entry : allInstitutions.entrySet() )
	{
		InstitutionStatus instStatus = entry.getValue();
		Institution institution = instStatus.getInstitution();
		Long schemaId = instStatus.getSchemaId();
		if( instStatus.isValid() && institution.isEnabled() )
		{
			availableBuilder.put(schemaId, institution);
			if( !newlyUnavailable.remove(schemaId, institution) )
			{
				newlyAvailable.put(schemaId, institution);
			}
		}
		long uniqueId = institution.getUniqueId();
		schemaBuilder.put(uniqueId, schemaId);
		instBuilder.put(uniqueId, institution);
	}

	availableInstitutions = availableBuilder.build();
	schemaMap = schemaBuilder.build();
	instMap = instBuilder.build();

	if( !newlyAvailable.isEmpty() )
	{
		eventService.publishApplicationEvent(new InstitutionEvent(InstitutionEventType.AVAILABLE, newlyAvailable));
	}

	if( !newlyUnavailable.isEmpty() )
	{
		eventService
				.publishApplicationEvent(new InstitutionEvent(InstitutionEventType.UNAVAILABLE, newlyUnavailable));
	}
}
 
Example 5
Project: businessworks   File: Initializer.java   Source Code and License Vote up 4 votes
/**
 * Reentrant. If {@code instance} was registered for injection at injector-creation time, this
 * method will ensure that all its members have been injected before returning.
 */
public T get(Errors errors) throws ErrorsException {
  // skipping acquiring lock if initialization is already finished
  if (state == InjectableReferenceState.READY) {
    return instance;
  }

  // acquire lock for current binding to initialize an instance
  Multimap<?, ?> lockCycle = lock.lockOrDetectPotentialLocksCycle();
  if (!lockCycle.isEmpty()) {
    // Potential deadlock detected and creation lock is not taken.
    // According to injectAll()'s contract return non-initialized instance.

    // This condition should not be possible under the current Guice implementation.
    // This clause exists for defensive programming purposes.

    // Reasoning:
    // get() is called either directly from injectAll(), holds no locks and can not create
    // a cycle, or it is called through a singleton scope, which resolves deadlocks by itself.
    // Before calling get() object has to be requested for injection.
    // Initializer.requestInjection() is called either for constant object bindings, which wrap
    // creation into a Singleton scope, or from Binder.requestInjection(), which
    // has to use Singleton scope to reuse the same InjectableReference to potentially
    // create a lock cycle.
    return instance;
  }
  try {
    // lock acquired, current thread owns this instance initialization
    switch (state) {
      case READY:
        return instance;
      // When instance depends on itself in the same thread potential dead lock
      // is not detected. We have to prevent a stack overflow and we use
      // an "injecting" stage to short-circuit a call.
      case INJECTING:
        return instance;
      case VALIDATED:
        state = InjectableReferenceState.INJECTING;
        break;
      case NEW:
        throw new IllegalStateException("InjectableReference is not validated yet");
      default:
        throw new IllegalStateException("Unknown state: " + state);
    }

    // if in Stage.TOOL, we only want to inject & notify toolable injection points.
    // (otherwise we'll inject all of them)
    membersInjector.injectAndNotify(instance,
        errors.withSource(source),
        key,
        provisionCallback,
        source,
        injector.options.stage == Stage.TOOL);

    // mark instance as ready to skip a lock on subsequent calls
    state = InjectableReferenceState.READY;
    return instance;
  } finally {
    // always release our creation lock, even on failures
    lock.unlock();
  }
}
 
Example 6
Project: athena   File: BasicPceccHandler.java   Source Code and License Vote up 4 votes
/**
  * Deallocates unused labels to device pools.
  *
  * @param tunnel tunnel between ingress to egress
  */
 public void releaseLabel(Tunnel tunnel) {
    boolean isLastLabelToPush = false;

    checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
    checkNotNull(pceStore, PCE_STORE_NULL);

    Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create();
    PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId());
    if (pceccTunnelInfo != null) {
        List<LspLocalLabelInfo> lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList();
        if ((lspLocalLabelInfoList != null) && (lspLocalLabelInfoList.size() > 0)) {
            for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) {
                LspLocalLabelInfo lspLocalLabelInfo = iterator.next();
                DeviceId deviceId = lspLocalLabelInfo.deviceId();
                LabelResourceId inLabelId = lspLocalLabelInfo.inLabelId();
                LabelResourceId outLabelId = lspLocalLabelInfo.outLabelId();
                PortNumber inPort = lspLocalLabelInfo.inPort();
                PortNumber outPort = lspLocalLabelInfo.outPort();

                // Check whether this is last link label to push
                if (!iterator.hasNext()) {
                   isLastLabelToPush = true;
                }

                // Push into device
                if ((inLabelId != null) && (inPort != null)) {
                    installLocalLabelRule(deviceId, inLabelId, inPort, tunnel.tunnelId(), isLastLabelToPush,
                                          Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.REMOVE);
                }

                if ((outLabelId != null) && (outPort != null)) {
                    installLocalLabelRule(deviceId, outLabelId, outPort, tunnel.tunnelId(), isLastLabelToPush,
                                          Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.REMOVE);
                }

                // List is stored from egress to ingress. So, using IN label id to release.
                // Only one local label is assigned to device (destination node)
                // and that is used as OUT label for source node.
                // No need to release label for last node in the list from pool because label was not allocated to
                // ingress node (source node).
                if ((iterator.hasNext()) && (inLabelId != null)) {
                    LabelResource labelRsc = new DefaultLabelResource(deviceId, inLabelId);
                    release.put(deviceId, labelRsc);
                }
            }
        }

        // Release from label pool
        if (!release.isEmpty()) {
           labelRsrcService.releaseToDevicePool(release);
        }

        // Remove tunnel info only if tunnel consumer id is not saved.
        // If tunnel consumer id is saved, this tunnel info will be removed during releasing bandwidth.
        if (pceccTunnelInfo.tunnelConsumerId() == null) {
            pceStore.removeTunnelInfo(tunnel.tunnelId());
        }
    } else {
        log.error("Unable to find PCECC tunnel info in store for a tunnel {}.", tunnel.toString());
    }
}
 
Example 7
Project: googles-monorepo-demo   File: GoogleHelpers.java   Source Code and License Vote up 4 votes
static void assertEmpty(Multimap<?, ?> multimap) {
  if (!multimap.isEmpty()) {
    fail("Not true that " + multimap + " is empty");
  }
}