List of usage examples for com.google.common.collect Iterables elementsEqual
@CheckReturnValue public static boolean elementsEqual(Iterable<?> iterable1, Iterable<?> iterable2)
From source file:org.apache.cassandra.db.SuperColumn.java
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SuperColumn sc = (SuperColumn) o;/*from w w w . ja v a 2s . c o m*/ if (!name.equals(sc.name)) return false; if (getMarkedForDeleteAt() != sc.getMarkedForDeleteAt()) return false; if (getLocalDeletionTime() != sc.getLocalDeletionTime()) return false; return Iterables.elementsEqual(columns, sc.columns); }
From source file:info.magnolia.ui.framework.message.MessageStore.java
protected String buildQueryMessageStatement(String userName, List<MessageType> messageTypeList, Map<String, Boolean> sortCriteria) { MessageType[] messageTypes;// ww w .j a va 2 s . c o m if (Iterables.elementsEqual(messageTypeList, Arrays.asList(MessageType.values()))) { messageTypes = new MessageType[] {}; } else { messageTypes = messageTypeList.toArray(new MessageType[messageTypeList.size()]); } return String.format(QUERY_MESSAGE_STATEMENT, userName).concat(buildWhereTypesClause(messageTypes)) .concat(constructOrderBy(sortCriteria)); }
From source file:org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction.java
private void checkSingleExpectedValueUnsafe(final KeyColumn kc, final StaticBuffer ev, final ExpectedValueCheckingStore store) throws BackendException { final StaticBuffer nextBuf = BufferUtil.nextBiggerBuffer(kc.getColumn()); KeySliceQuery ksq = new KeySliceQuery(kc.getKey(), kc.getColumn(), nextBuf); // Call getSlice on the wrapped store using the quorum+ consistency tx Iterable<Entry> actualEntries = store.getBackingStore().getSlice(ksq, strongConsistentTx); if (null == actualEntries) actualEntries = ImmutableList.<Entry>of(); /*//from w ww . j a v a2 s . c o m * Discard any columns which do not exactly match kc.getColumn(). * * For example, it's possible that the slice returned columns which for * which kc.getColumn() is a prefix. */ actualEntries = Iterables.filter(actualEntries, new Predicate<Entry>() { @Override public boolean apply(Entry input) { if (!input.getColumn().equals(kc.getColumn())) { log.debug("Dropping entry {} (only accepting column {})", input, kc.getColumn()); return false; } log.debug("Accepting entry {}", input); return true; } }); // Extract values from remaining Entry instances Iterable<StaticBuffer> actualVals = Iterables.transform(actualEntries, new Function<Entry, StaticBuffer>() { @Override public StaticBuffer apply(Entry e) { StaticBuffer actualCol = e.getColumnAs(StaticBuffer.STATIC_FACTORY); assert null != actualCol; assert null != kc.getColumn(); assert 0 >= kc.getColumn().compareTo(actualCol); assert 0 > actualCol.compareTo(nextBuf); return e.getValueAs(StaticBuffer.STATIC_FACTORY); } }); final Iterable<StaticBuffer> expectedVals; if (null == ev) { expectedVals = ImmutableList.<StaticBuffer>of(); } else { expectedVals = ImmutableList.<StaticBuffer>of(ev); } if (!Iterables.elementsEqual(expectedVals, actualVals)) { throw new PermanentLockingException("Expected value mismatch for " + kc + ": expected=" + expectedVals + " vs actual=" + actualVals + " (store=" + store.getName() + ")"); } }
From source file:org.apache.abdera2.common.http.CacheControl.java
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CacheControl other = (CacheControl) obj; if (flags != other.flags) return false; if (max_age != other.max_age) return false; if (max_stale != other.max_stale) return false; if (min_fresh != other.min_fresh) return false; if (!Iterables.elementsEqual(nocache_headers, other.nocache_headers)) return false; if (!Iterables.elementsEqual(private_headers, other.private_headers)) return false; if (smax_age != other.smax_age) return false; if (staleiferror != other.staleiferror) return false; if (stalewhilerevalidate != other.stalewhilerevalidate) return false; return true;// w ww .j a v a 2 s . com }
From source file:org.decisiondeck.jlp.utils.LpSolverUtils.java
static public Equivalence<LpLinear<?>> getLinearEquivalence() { return new Equivalence<LpLinear<?>>() { @Override/*from ww w . j av a 2 s. c o m*/ public boolean doEquivalent(LpLinear<?> a, LpLinear<?> b) { return Iterables.elementsEqual(a, b); } @Override public int doHash(LpLinear<?> t) { int hashCode = 1; for (LpTerm<?> term : t) { hashCode = 31 * hashCode + term.hashCode(); } return hashCode; } }; }
From source file:org.eclipse.xtext.xbase.lib.IterableExtensions.java
/** * Determines whether two iterables contain equal elements in the same order. More specifically, this method returns * {@code true} if {@code iterable} and {@code other} contain the same number of elements and every element of * {@code iterable} is equal to the corresponding element of {@code other}. * /*from www . jav a 2 s . co m*/ * @param iterable * an iterable. May not be <code>null</code>. * @param other * an iterable. May not be <code>null</code>. * @return <code>true</code> if the two iterables contain equal elements in the same order. */ public static boolean elementsEqual(Iterable<?> iterable, Iterable<?> other) { return Iterables.elementsEqual(iterable, other); }
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;/* w w w . j a v a 2s. 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.DaemonicParserState.java
private void invalidateIfProjectBuildFileParserStateChanged(Cell cell) { Iterable<String> defaultIncludes = cell.getBuckConfig().getView(ParserConfig.class).getDefaultIncludes(); boolean invalidatedByDefaultIncludesChange = false; Iterable<String> expected; try (AutoCloseableLock updateLock = cachedStateLock.updateLock()) { expected = cachedIncludes.get(cell.getRoot()); 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. invalidatedByDefaultIncludesChange = true; }//from www .ja v a 2 s . com if (!invalidatedByDefaultIncludesChange) { return; } try (AutoCloseableLock writeLock = cachedStateLock.writeLock()) { cachedIncludes.put(cell.getRoot(), defaultIncludes); } } synchronized (this) { if (invalidateCellCaches(cell) && invalidatedByDefaultIncludesChange) { LOG.warn("Invalidating cache on default includes change (%s != %s)", expected, defaultIncludes); cacheInvalidatedByDefaultIncludesChangeCounter.inc(); } } }
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;// w w w . j a va 2s . 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; } try (AutoCloseableLock writeLock = cachedStateLock.writeLock()) { cachedEnvironment = cellEnv; cachedIncludes.put(cell.getRoot(), defaultIncludes); } } synchronized (this) { invalidateAllCaches(); knownCells.add(cell); } }
From source file:com.github.talberto.easybeans.atg.PropertyMapper.java
protected EnumPropertyMapper(NucleusEntityManager pEntityManager, PropertyDescriptor pBeanPropertyDescriptor, DynamicPropertyDescriptor pRepositoryPropertyDescriptor) { super(pEntityManager, pBeanPropertyDescriptor, pRepositoryPropertyDescriptor); checkArgument(pRepositoryPropertyDescriptor instanceof EnumPropertyDescriptor, "The DynamycPropertyDescriptor isn't an instance of EnumPropertyDescriptor"); mEnumRepositoryType = (EnumPropertyDescriptor) pRepositoryPropertyDescriptor; @SuppressWarnings("unchecked") Class<? extends Enum<?>> enumBeanType = (Class<? extends Enum<?>>) pBeanPropertyDescriptor .getPropertyType();/* w w w . j ava2s.c om*/ checkArgument(enumBeanType.isEnum(), "The bean property [%s] isn't of type enum", pBeanPropertyDescriptor.getName()); // Extract the methods or fail fast mCodeGetter = getCodeGetterMethod(enumBeanType); mValueGetter = getValueGetterMethod(enumBeanType); mFromCode = getFromCodeMethod(enumBeanType); mFromValue = getFromValueMethod(enumBeanType); // Check that the two enumerations are compatible List<EnumeratedOption> repoEnumOptions = Arrays.asList(mEnumRepositoryType.getEnumeratedOptions()); List<? extends Enum<?>> beanEnumConstants = Arrays.asList(enumBeanType.getEnumConstants()); List<RepositoryEnumItem> repoEnumItems = RepositoryEnumItem.ORDERING .immutableSortedCopy((Lists.transform(repoEnumOptions, sEnumOptToRepoEnumItem))); List<RepositoryEnumItem> beanEnumItems = RepositoryEnumItem.ORDERING.immutableSortedCopy( (Lists.transform(beanEnumConstants, new Function<Enum<?>, RepositoryEnumItem>() { @Override public RepositoryEnumItem apply(Enum<?> pInput) { try { int code = (Integer) mCodeGetter.invoke(pInput); String value = (String) mValueGetter.invoke(pInput); return new RepositoryEnumItem(code, value); } catch (Exception e) { throw new MappingException(String.format("Error transforming enum [%s]", pInput), e); } } }))); if (!Iterables.elementsEqual(repoEnumItems, beanEnumItems)) { throw new MappingException("The repository enumeration and the bean enumeration are not compatible"); } }