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

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

Introduction

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

Prototype

@Override
    public boolean equals(@Nullable Object object) 

Source Link

Usage

From source file:org.openo.msb.wrapper.consul.cache.ConsulCache.java

ConsulCache(Function<V, K> keyConversion, CallbackConsumer<V> callbackConsumer, final long backoffDelayQty,
        final TimeUnit backoffDelayUnit) {

    this.keyConversion = keyConversion;
    this.callBackConsumer = callbackConsumer;

    this.responseCallback = new ConsulResponseCallback<List<V>>() {
        @Override//w  w w .  ja  v  a2s.c  o  m
        public void onComplete(ConsulResponse<List<V>> consulResponse) {

            if (!isRunning()) {
                return;
            }
            updateIndex(consulResponse);
            ImmutableMap<K, V> full = convertToMap(consulResponse);

            boolean changed = !full.equals(lastResponse.get());
            //                LOGGER.info("node changed:"+changed+"----"+full);
            if (changed) {
                // changes
                lastResponse.set(full);
            }

            if (changed) {
                for (Listener<K, V> l : listeners) {
                    l.notify(full);
                }
            }

            if (state.compareAndSet(State.starting, State.started)) {
                initLatch.countDown();
            }
            runCallback();
        }

        @Override
        public void onFailure(Throwable throwable) {

            if (!isRunning()) {
                return;
            }
            LOGGER.error(String.format("Error getting response from consul. will retry in %d %s",
                    backoffDelayQty, backoffDelayUnit), throwable);

            executorService.schedule(new Runnable() {
                @Override
                public void run() {
                    runCallback();
                }
            }, backoffDelayQty, backoffDelayUnit);
        }
    };
}

From source file:com.facebook.buck.parser.SerialDaemonicParserState.java

private void invalidateIfProjectBuildFileParserStateChanged(Cell cell) {
    ImmutableMap<String, String> cellEnv = cell.getBuckConfig().getEnvironment();
    Iterable<String> defaultIncludes = new ParserConfig(cell.getBuckConfig()).getDefaultIncludes();
    Iterable<String> expected = cachedIncludes.get(cell.getRoot());

    boolean invalidateCaches = false;

    if (!cellEnv.equals(cachedEnvironment)) {
        // Contents of System.getenv() have changed. Cowardly refuse to accept we'll parse everything
        // the same way.
        invalidateCaches = true;/*  ww  w  .j a va2s. c  o  m*/
    } else if (expected == null || !Iterables.elementsEqual(defaultIncludes, expected)) {
        // Someone's changed the default includes. That's almost definitely caused all our lovingly
        // cached data to be enormously wonky.
        invalidateCaches = true;
    }

    if (!invalidateCaches) {
        return;
    }

    invalidateAllCaches();

    cachedEnvironment = cellEnv;
    cachedIncludes.put(cell.getRoot(), defaultIncludes);
    knownCells.add(cell);
}

From source file:com.facebook.buck.parser.ParallelDaemonicParserState.java

private void invalidateIfProjectBuildFileParserStateChanged(Cell cell) {
    ImmutableMap<String, String> cellEnv = cell.getBuckConfig().getEnvironment();
    Iterable<String> defaultIncludes = new ParserConfig(cell.getBuckConfig()).getDefaultIncludes();

    boolean invalidateCaches = false;
    try (AutoCloseableLock updateLock = cachedStateLock.updateLock()) {
        Iterable<String> expected = cachedIncludes.get(cell.getRoot());

        if (!cellEnv.equals(cachedEnvironment)) {
            // Contents of System.getenv() have changed. Cowardly refuse to accept we'll parse
            // everything the same way.
            invalidateCaches = true;//from w ww.j a v a2 s. c  om
        } else if (expected == null || !Iterables.elementsEqual(defaultIncludes, expected)) {
            // Someone's changed the default includes. That's almost definitely caused all our lovingly
            // cached data to be enormously wonky.
            invalidateCaches = true;
        }

        if (!invalidateCaches) {
            return;
        }

        try (AutoCloseableLock writeLock = cachedStateLock.writeLock()) {
            cachedEnvironment = cellEnv;
            cachedIncludes.put(cell.getRoot(), defaultIncludes);
        }
    }
    synchronized (this) {
        invalidateAllCaches();
        knownCells.add(cell);
    }
}

From source file:google.registry.rdap.RdapJsonFormatter.java

/**
 * Adds the required top-level boilerplate. RFC 7483 specifies that the top-level object should
 * include an entry indicating the conformance level. The ICANN RDAP Profile document (dated 3
 * December 2015) mandates several additional entries, in sections 1.4.4, 1.4.10, 1.5.18 and
 * 1.5.20. Note that this method will only work if there are no object-specific remarks already in
 * the JSON object being built. If there are, the boilerplate must be merged in.
 *
 * @param jsonBuilder a builder for a JSON map object
 * @param boilerplateType type of boilerplate to be added; the ICANN RDAP Profile document
 *        mandates extra boilerplate for domain objects
 * @param notices a list of notices to be inserted before the boilerplate notices. If the TOS
 *        notice is in this list, the method avoids adding a second copy.
 * @param remarks a list of remarks to be inserted before the boilerplate notices.
 * @param rdapLinkBase the base for link URLs
 *//* w ww.  j  a va2s  . c o m*/
void addTopLevelEntries(ImmutableMap.Builder<String, Object> jsonBuilder, BoilerplateType boilerplateType,
        List<ImmutableMap<String, Object>> notices, List<ImmutableMap<String, Object>> remarks,
        String rdapLinkBase) {
    jsonBuilder.put("rdapConformance", CONFORMANCE_LIST);
    ImmutableList.Builder<ImmutableMap<String, Object>> noticesBuilder = new ImmutableList.Builder<>();
    ImmutableMap<String, Object> tosNotice = getJsonTosNotice(rdapLinkBase);
    boolean tosNoticeFound = false;
    if (!notices.isEmpty()) {
        noticesBuilder.addAll(notices);
        for (ImmutableMap<String, Object> notice : notices) {
            if (notice.equals(tosNotice)) {
                tosNoticeFound = true;
                break;
            }
        }
    }
    if (!tosNoticeFound) {
        noticesBuilder.add(tosNotice);
    }
    jsonBuilder.put(NOTICES, noticesBuilder.build());
    ImmutableList.Builder<ImmutableMap<String, Object>> remarksBuilder = new ImmutableList.Builder<>();
    remarksBuilder.addAll(remarks);
    switch (boilerplateType) {
    case DOMAIN:
        remarksBuilder.addAll(RdapIcannStandardInformation.domainBoilerplateRemarks);
        break;
    case NAMESERVER:
    case ENTITY:
        remarksBuilder.addAll(RdapIcannStandardInformation.nameserverAndEntityBoilerplateRemarks);
        break;
    default: // things other than domains, nameservers and entities cannot contain remarks
        break;
    }
    ImmutableList<ImmutableMap<String, Object>> remarksToAdd = remarksBuilder.build();
    if (!remarksToAdd.isEmpty()) {
        jsonBuilder.put(REMARKS, remarksToAdd);
    }
}

From source file:org.dcache.resilience.data.PoolInfoMap.java

/** Called under read lock **/
private void comparePoolInfo(PoolInfoDiff diff, Set<String> commonPools, PoolMonitor poolMonitor) {
    PoolSelectionUnit psu = poolMonitor.getPoolSelectionUnit();
    CostModule costModule = poolMonitor.getCostModule();

    /*//w  w  w  .  ja v a2s  . co  m
     *  First add the info for all new pools to the diff.
     */
    diff.getNewPools().stream().forEach((p) -> {
        diff.getModeChanged().put(p, getPoolMode(psu.getPool(p)));
        diff.getTagsChanged().put(p, getPoolTags(p, costModule));
        diff.getPoolCost().put(p, getPoolCostInfo(p, costModule));
    });

    /*
     * Now check for differences with current pools that are still valid.
     */
    commonPools.stream().forEach((p) -> {
        PoolInformation info = poolInfo.get(getPoolIndex(p));
        PoolV2Mode newMode = getPoolMode(psu.getPool(p));
        PoolV2Mode oldMode = info.getMode();
        if (oldMode == null || (newMode != null && !oldMode.equals(newMode))) {
            diff.getModeChanged().put(p, newMode);
        }

        ImmutableMap<String, String> newTags = getPoolTags(p, costModule);
        ImmutableMap<String, String> oldTags = info.getTags();
        if (oldTags == null || (newTags != null && !oldTags.equals(newTags))) {
            diff.getTagsChanged().put(p, newTags);
        }

        /*
         * Since we are not altering the actual collections inside
         * the PoolInfoMap, but are simply modifying the PoolInformation
         * object, and since its own update method is synchronized,
         * we can take care of the update here while holding a read lock.
         */
        info.update(newMode, newTags, getPoolCostInfo(p, costModule));
    });

}