Example usage for com.google.common.collect ImmutableMap size

List of usage examples for com.google.common.collect ImmutableMap size

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap size.

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings in this map.

Usage

From source file:springfox.documentation.schema.DefaultModelProvider.java

@Override
public com.google.common.base.Optional<Model> modelFor(ModelContext modelContext) {
    ResolvedType propertiesHost = modelContext.alternateFor(modelContext.resolvedType(resolver));
    if (isContainerType(propertiesHost) || isMapType(propertiesHost) || propertiesHost.getErasedType().isEnum()
            || isBaseType(propertiesHost) || modelContext.hasSeenBefore(propertiesHost)) {
        LOG.debug(//w w  w  . j  a va2 s  .c  om
                "Skipping model of type {} as its either a container type, map, enum or base type, or its already "
                        + "been handled",
                resolvedTypeSignature(propertiesHost).or("<null>"));
        return Optional.absent();
    }
    ImmutableMap<String, ModelProperty> propertiesIndex = uniqueIndex(properties(modelContext, propertiesHost),
            byPropertyName());
    LOG.debug("Inferred {} properties. Properties found {}", propertiesIndex.size(),
            Joiner.on(", ").join(propertiesIndex.keySet()));
    Map<String, ModelProperty> properties = newTreeMap();
    properties.putAll(propertiesIndex);
    return Optional.of(modelBuilder(propertiesHost, properties, modelContext));
}

From source file:org.codice.ddf.catalog.sourcepoller.PollerRunner.java

@SuppressWarnings("squid:S1181" /*Catching throwable intentionally*/)
private void poll(final long pollIntervalMinutes) {
    try {// ww  w. ja  va 2 s .c  o m
        final ImmutableMap<K, Callable<V>> itemsToPoll = getValueLoaders();
        final int currentItemsCount = itemsToPoll.size();

        LOGGER.trace(
                "Starting a process to poll the {} current item(s), where polls will time out at {} minute(s)",
                currentItemsCount, pollIntervalMinutes);
        // If there are any unhandled exceptions in this method, all future calls will be suppressed.
        poller.pollItems(pollIntervalMinutes, TimeUnit.MINUTES, itemsToPoll);
        LOGGER.trace("Successfully finished the process of polling the {} source(s)", currentItemsCount);
    } catch (InterruptedException e) {
        LOGGER.debug("A scheduled poll was interrupted.", pollIntervalMinutes, e);
        Thread.currentThread().interrupt();
    } catch (final VirtualMachineError e) {
        final String message = "A scheduled poll failed";
        LOGGER.debug(message, e);
        LOGGER.warn(
                "{}. See debug log for more details. The current items will NOT continue to be polled at a fixed rate of {} minutes. Try restarting the system.",
                message, pollIntervalMinutes);
        throw e;
    } catch (final PollerException e) {
        e.getCauses().forEach((k, t) -> LOGGER.debug("Unable to load a new value for {}", k, t));
        LOGGER.warn(
                "A scheduled poll failed. {}. See debug log for more details. The current items will continue to be polled at a fixed rate of {} minutes. Try restarting the system if future polls also fail.",
                e.getMessage(), pollIntervalMinutes);
    } catch (final Throwable e) {
        final String message = "A scheduled poll failed";
        LOGGER.debug(message, e);
        LOGGER.warn(
                "A scheduled poll failed. See debug log for more details. The current items will continue to be polled at a fixed rate of {} minutes. Try restarting the system if future polls also fail.",
                pollIntervalMinutes);
    }
}

From source file:dagger.internal.codegen.RequestFulfillmentRegistry.java

RequestFulfillmentRegistry(ImmutableMap<BindingKey, ResolvedBindings> resolvedBindingsMap,
        HasBindingMembers hasBindingMembers) {
    this.resolvedBindingsMap = resolvedBindingsMap;
    this.hasBindingMembers = hasBindingMembers;
    this.requestFulfillments = newLinkedHashMapWithExpectedSize(resolvedBindingsMap.size());
}

From source file:fr.aliacom.obm.common.setting.SettingDao.java

public Map<String, String> getSettings(ObmUser user) {
    Builder<String, String> mapBuilder = new Builder<String, String>();

    String domain = user.getDomain().getName();
    String userLogin = user.getLogin();

    Connection con = null;//from w  ww  .  j  a v  a2  s  . c o  m
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        con = obmHelper.getConnection();

        String q = "select userobmpref_option, userobmpref_value from UserObmPref "
                + "where userobmpref_user_id is null " + "and userobmpref_option not in "
                + "(select userobmpref_option from UserObmPref where userobmpref_user_id=(select userobm_id from UserObm "
                + "where userobm_login=? "
                + "and userobm_domain_id=(select domain_id from Domain where domain_name=?) " + ")) " + "union "
                + "select userobmpref_option, userobmpref_value from UserObmPref "
                + "where userobmpref_user_id=(select userobm_id from UserObm " + "where userobm_login=? "
                + "and userobm_domain_id=(select domain_id from Domain where domain_name=?) " + " )";

        ps = con.prepareStatement(q);
        int idx = 1;
        ps.setString(idx++, userLogin);
        ps.setString(idx++, domain);
        ps.setString(idx++, userLogin);
        ps.setString(idx++, domain);
        rs = ps.executeQuery();
        while (rs.next()) {
            mapBuilder.put(rs.getString(1), rs.getString(2));
        }
    } catch (SQLException se) {
        logger.error("Error fetching preferences for " + user + " at " + domain, se);
    } finally {
        obmHelper.cleanup(con, ps, rs);
    }

    ImmutableMap<String, String> data = mapBuilder.build();

    logger.info("return " + data.size() + " settings for userid: " + user + " at " + domain);
    return data;
}

From source file:ru.org.linux.search.SearchController.java

private Map<Integer, String> buildGroupFacet(int sectionId, FacetField groupFacet) throws BadGroupException {
    ImmutableMap.Builder<Integer, String> builder = ImmutableSortedMap.naturalOrder();

    int totalCount = 0;

    for (FacetField.Count count : groupFacet.getValues()) {
        int groupId = Integer.parseInt(count.getName());

        Group group = groupDao.getGroup(groupId);

        if (group.getSectionId() != sectionId) {
            continue;
        }//  www.  ja  v  a 2 s .c  o  m

        String name = group.getTitle().toLowerCase();

        builder.put(groupId, name + " (" + count.getCount() + ')');

        totalCount += count.getCount();
    }

    builder.put(0, "? (" + Integer.toString(totalCount) + ')');

    ImmutableMap<Integer, String> r = builder.build();

    if (r.size() <= 2) {
        return null;
    } else {
        return r;
    }
}

From source file:org.grycap.gpf4med.ext.GraphConnectorManager.java

@Override
public void preload() {
    // lazy load, so initial access is needed
    final ImmutableMap<String, GraphConnector> connectors = listConnectors();
    if (connectors.size() > 0) {
        LOGGER.info(connectors.size() + " graph connectors loaded");
    } else {/*www.j  av  a 2  s  .co  m*/
        LOGGER.warn("No graph connectors loaded");
    }
}

From source file:org.locationtech.geogig.plumbing.merge.DiffMergeFeaturesOp.java

private Map<ObjectId, RevObject> getObjects() {

    final ObjectId ancestorMetadataId = commonAncestor.getMetadataId();
    final ObjectId mergetIntoMetadataId = mergeInto.getMetadataId();
    final ObjectId toMergeMetadataId = toMerge.getMetadataId();

    final ObjectId ancestorFeatureId = commonAncestor.getObjectId();
    final ObjectId featureAId = mergeInto.getObjectId();
    final ObjectId featureBId = toMerge.getObjectId();

    Set<ObjectId> ids = Sets.newHashSet(ancestorMetadataId, mergetIntoMetadataId, toMergeMetadataId,
            ancestorFeatureId, featureAId, featureBId);

    Iterator<RevObject> objsit = objectDatabase().getAll(ids, BulkOpListener.NOOP_LISTENER);

    ImmutableMap<ObjectId, RevObject> map = Maps.uniqueIndex(objsit, (o) -> o.getId());

    if (ids.size() != map.size()) {
        ids.forEach((id) -> checkState(map.containsKey(id), "Invalid reference: %s", id));
    }//ww w  .j a  v a  2 s  .  c o m
    return map;
}

From source file:google.registry.monitoring.metrics.VirtualMetric.java

@VisibleForTesting
ImmutableList<MetricPoint<V>> getTimestampedValues(Instant timestamp) {
    ImmutableMap<ImmutableList<String>, V> values = valuesSupplier.get();

    ImmutableList.Builder<MetricPoint<V>> metricPoints = new ImmutableList.Builder<>();
    for (Entry<ImmutableList<String>, V> entry : values.entrySet()) {
        metricPoints.add(MetricPoint.create(this, entry.getKey(), timestamp, timestamp, entry.getValue()));
    }//w  ww .  j a  v  a  2  s  .com

    cardinality = values.size();
    return metricPoints.build();
}

From source file:se.sics.caracaldb.global.DefaultPolicy.java

private void addMoreCandidates(LUTWorkingBuffer lut, TreeMultimap<Long, Integer> candidates,
        ImmutableMap<Address, Stats.Report> stats) {
    if (candidates.values().size() >= stats.size()) {
        return; // Already everyone a candidate...nothing to do
    }/*from w  w w .  j  a  va2 s.com*/
    int index = 0;
    for (Address addr : lut.hosts()) {
        if (!candidates.containsValue(index)) {
            Stats.Report rep = stats.get(addr);
            if (rep != null) {
                long curSize = rep.averageSize * rep.numberOfVNodes;
                candidates.put(curSize, index);
            }
        }
        index++;
    }
}

From source file:com.opengamma.strata.basics.currency.FxMatrixBuilder.java

FxMatrixBuilder(ImmutableMap<Currency, Integer> currencies, double[][] rates) {
    this.currencies = new LinkedHashMap<>(currencies);
    // Ensure there is space to add at least one new currency
    this.rates = copyArray(rates, size(currencies.size() + 1));
}