List of usage examples for com.google.common.base Predicates not
public static <T> Predicate<T> not(Predicate<T> predicate)
From source file:org.eclipse.sirius.diagram.ui.tools.internal.layout.PinnedElementsHandler.java
/** * Finds all the packable horizontal gaps with no edit-parts and moves the * parts beyond them to the top to reduce the gap to the minimum while still * respecting the parts' padding.//from w ww . j a v a 2 s. co m */ private void packVertically() { final int[] vRange = getVerticalRange(allEditParts, EXCLUDE_PADDING); final List<IGraphicalEditPart> movableParts = Lists .newArrayList(Collections2.filter(allEditParts, Predicates.not(isPinned))); Collections.sort(movableParts, topToBottomComparator); for (int i = 0; i < movableParts.size(); i++) { /* * Split the movable parts into two groups (top and bottom) on index * i. If there is a sufficiently large gap between the two groups, * move the elements of the bottom group to the top. */ final Set<IGraphicalEditPart> topSide = Sets.newHashSet(movableParts.subList(0, i)); final Rectangle topBox; final Insets topPadding; if (i == 0) { // Artificial box corresponding to the top margin of the figure // along which to pack. topBox = new Rectangle(0, vRange[0] - 1, 1, 1); topPadding = new Insets(0, 0, 0, 0); } else { topBox = getBoundingBox(topSide, EXCLUDE_PADDING); topPadding = getPadding(topSide); } final Set<IGraphicalEditPart> bottomSide = Sets .newHashSet(movableParts.subList(i, movableParts.size())); final Rectangle bottomBox = getBoundingBox(bottomSide, EXCLUDE_PADDING); final Insets bottomPadding = getPadding(bottomSide); final int currentGapWidth = bottomBox.getTop().y - topBox.getBottom().y; final int minGapWidth = Math.max(MINIMAL_GAP_WIDTH, Math.max(topPadding.bottom, bottomPadding.top)); if (i == 0 && isVerticalOriginFree(allEditParts, vRange[0])) { // We can move the bottomSide elements to the free space translate(bottomSide, new Dimension(0, -currentGapWidth)); } else if (currentGapWidth > minGapWidth) { translate(bottomSide, new Dimension(0, -(currentGapWidth - minGapWidth))); } } }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.util.SubEventsHelper.java
private Iterable<ISequenceEvent> getSequenceEventsToFilter(ISequenceEvent self, ISequenceEvent child, final Range range, final Collection<Lifeline> lifelines) { Set<ISequenceEvent> result = Sets.newHashSet(self.getSubEvents()); Predicate<ISequenceEvent> inRangePredicate = new Predicate<ISequenceEvent>() { public boolean apply(ISequenceEvent input) { Range inputRange = input.getVerticalRange(); return range.includesAtLeastOneBound(inputRange) || new ISequenceEventQuery(input).isReflectiveMessage() && inputRange.includesAtLeastOneBound(range); }//ww w .j a va 2 s .c o m }; Predicate<ISequenceEvent> inCoverage = new Predicate<ISequenceEvent>() { public boolean apply(ISequenceEvent input) { Collection<Lifeline> inputCoverage = Lists.newArrayList(getCoverage(input)); return Iterables.removeAll(inputCoverage, lifelines); } }; @SuppressWarnings("unchecked") Predicate<ISequenceEvent> predicateFilter = Predicates.and(Predicates.not(Predicates.equalTo(child)), inRangePredicate, inCoverage); return Iterables.filter(result, predicateFilter); }
From source file:org.sosy_lab.cpachecker.cpa.value.refiner.ValueAnalysisRefiner.java
/** * This method returns an unsorted, non-empty collection of target states * found during the analysis./*from w w w . jav a 2 s . co m*/ * * @param pReached the set of reached states * @return the target states */ private Collection<ARGState> getTargetStates(final ARGReachedSet pReached) { // obtain all target locations, excluding feasible ones // this filtering is needed to distinguish between multiple targets being available // because of stopAfterError=false (feasible) versus globalRefinement=true (new) Set<ARGState> targets = from(pReached.asReachedSet()).transform(AbstractStates.toState(ARGState.class)) .filter(AbstractStates.IS_TARGET_STATE).filter(Predicates.not(Predicates.in(feasibleTargets))) .toSet(); assert !targets.isEmpty(); logger.log(Level.FINEST, "number of targets found: " + targets.size()); targetCounter = targetCounter + targets.size(); return targets; }
From source file:org.immutables.value.processor.meta.ValueType.java
public Set<ValueAttribute> computeConstructorArguments() { return ImmutableSet.copyOf(attributes() .filter(Predicates.compose(Predicates.not(Predicates.equalTo(-1)), ToConstructorArgumentOrder.FUNCTION)) .toSortedList(Ordering.natural().onResultOf(ToConstructorArgumentOrder.FUNCTION))); }
From source file:dagger2.internal.codegen.BindingGraphValidator.java
/** * Validates a members injection binding, returning false (and reporting the error) if it wasn't * valid.// ww w . ja v a 2 s . co m */ private boolean validateMembersInjectionBinding(MembersInjectionBinding binding, final Deque<ResolvedRequest> path, final Builder<BindingGraph> reportBuilder) { return binding.key().type().accept(new SimpleTypeVisitor6<Boolean, Void>() { @Override protected Boolean defaultAction(TypeMirror e, Void p) { reportBuilder.addItem("Invalid members injection request.", path.peek().request().requestElement()); return false; } @Override public Boolean visitDeclared(DeclaredType type, Void ignored) { // If the key has type arguments, validate that each type argument is declared. // Otherwise the type argument may be a wildcard (or other type), and we can't // resolve that to actual types. If the arg was an array, validate the type // of the array. for (TypeMirror arg : type.getTypeArguments()) { boolean declared; switch (arg.getKind()) { case ARRAY: declared = MoreTypes.asArray(arg).getComponentType() .accept(new SimpleTypeVisitor6<Boolean, Void>() { @Override protected Boolean defaultAction(TypeMirror e, Void p) { return false; } @Override public Boolean visitDeclared(DeclaredType t, Void p) { for (TypeMirror arg : t.getTypeArguments()) { if (!arg.accept(this, null)) { return false; } } return true; } @Override public Boolean visitArray(ArrayType t, Void p) { return t.getComponentType().accept(this, null); } @Override public Boolean visitPrimitive(PrimitiveType t, Void p) { return true; } }, null); break; case DECLARED: declared = true; break; default: declared = false; } if (!declared) { ImmutableList<String> printableDependencyPath = FluentIterable.from(path) .transform(REQUEST_FROM_RESOLVED_REQUEST).transform(dependencyRequestFormatter) .filter(Predicates.not(Predicates.equalTo(""))).toList().reverse(); reportBuilder.addItem( String.format(MEMBERS_INJECTION_WITH_UNBOUNDED_TYPE, arg.toString(), type.toString(), Joiner.on('\n').join(printableDependencyPath)), path.peek().request().requestElement()); return false; } } TypeElement element = MoreElements.asType(type.asElement()); // Also validate that the key is not the erasure of a generic type. // If it is, that means the user referred to Foo<T> as just 'Foo', // which we don't allow. (This is a judgement call -- we *could* // allow it and instantiate the type bounds... but we don't.) if (!MoreTypes.asDeclared(element.asType()).getTypeArguments().isEmpty() && types.isSameType(types.erasure(element.asType()), type)) { ImmutableList<String> printableDependencyPath = FluentIterable.from(path) .transform(REQUEST_FROM_RESOLVED_REQUEST).transform(dependencyRequestFormatter) .filter(Predicates.not(Predicates.equalTo(""))).toList().reverse(); reportBuilder.addItem( String.format(ErrorMessages.MEMBERS_INJECTION_WITH_RAW_TYPE, type.toString(), Joiner.on('\n').join(printableDependencyPath)), path.peek().request().requestElement()); return false; } return true; // valid } }, null); }
From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java
private SortedMap<byte[], RowResult<byte[]>> filterRowResults(String tableName, Map<Cell, Value> rawResults, Map<Cell, byte[]> result) { getWithPostfiltering(tableName, rawResults, result, Value.GET_VALUE); Map<Cell, byte[]> filterDeletedValues = Maps.filterValues(result, Predicates.not(Value.IS_EMPTY)); return RowResults.viewOfSortedMap(Cells.breakCellsUpByRow(filterDeletedValues)); }
From source file:eu.esdihumboldt.hale.ui.service.entity.internal.EntityDefinitionServiceImpl.java
/** * @see eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService#editConditionContext(eu.esdihumboldt.hale.common.align.model.EntityDefinition, * eu.esdihumboldt.hale.common.instance.model.Filter) *//*w w w . j a v a 2s .co m*/ @Override public EntityDefinition editConditionContext(final EntityDefinition sibling, Filter filter) { List<ChildContext> path = sibling.getPropertyPath(); if (sibling.getSchemaSpace() == SchemaSpaceID.TARGET && path.isEmpty()) { // not supported for target type entities // XXX throw exception instead? return null; } // Check whether there actually is a change. If not, we are done. Condition oldCondition = AlignmentUtil.getContextCondition(sibling); if (Objects.equal(filter, oldCondition == null ? null : oldCondition.getFilter())) return sibling; // Create the new entity. Do not add context yet, since the user could // still abort the process (see below). EntityDefinition newDef = AlignmentUtil.getDefaultEntity(sibling); if (filter != null) newDef = createWithCondition(sibling, new Condition(filter)); AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class); Alignment alignment = as.getAlignment(); // Collect cells to replace. // All cells of the EntityDefinition's type can be affected. Collection<? extends Cell> potentiallyAffected = alignment.getCells(sibling.getType(), sibling.getSchemaSpace()); Predicate<Cell> associatedCellPredicate = new Predicate<Cell>() { @Override public boolean apply(Cell input) { return input != null && AlignmentUtil.associatedWith(sibling, input, false, true); } }; Collection<? extends Cell> affected = new HashSet<Cell>( Collections2.filter(potentiallyAffected, associatedCellPredicate)); // Check whether base alignment cells are affected. boolean baseCellsAffected = false; Predicate<Cell> baseCellPredicate = new Predicate<Cell>() { @Override public boolean apply(Cell input) { return input != null && input.isBaseCell(); } }; if (Iterables.find(affected, baseCellPredicate, null) != null) { // Check whether the user wants to continue. final Display display = PlatformUI.getWorkbench().getDisplay(); final AtomicBoolean abort = new AtomicBoolean(); display.syncExec(new Runnable() { @Override public void run() { MessageBox mb = new MessageBox(display.getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION); mb.setMessage("Some base alignment cells reference the entity definition you wish to change.\n" + "The change will only affect cells which aren't from any base alignment.\n\n" + "Do you still wish to continue?"); mb.setText("Continue?"); abort.set(mb.open() != SWT.YES); } }); if (abort.get()) return null; // Filter base alignment cells out. baseCellsAffected = true; affected = Collections2.filter(affected, Predicates.not(baseCellPredicate)); } // No more obstacles. Finish! // Add condition context if necessary if (filter != null) addConditionContext(sibling, filter); // Replace affected (filtered) cells. Map<Cell, MutableCell> replaceMap = new HashMap<Cell, MutableCell>(); for (Cell cell : affected) { DefaultCell newCell = new DefaultCell(cell); if (newDef.getSchemaSpace() == SchemaSpaceID.SOURCE) newCell.setSource(replace(newCell.getSource(), sibling, newDef)); else newCell.setTarget(replace(newCell.getTarget(), sibling, newDef)); replaceMap.put(cell, newCell); } as.replaceCells(replaceMap); // Remove old condition context, if it was neither the default context, // nor do any base alignment cells still use it. if (oldCondition != null && !baseCellsAffected) removeContext(sibling); return newDef; }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.vertical.SequenceVerticalLayout.java
private Map<ISequenceEvent, Range> computeBasicRanges(Map<EventEnd, Integer> endLocations) { final Map<ISequenceEvent, Range> sequenceEventsToRange = new LinkedHashMap<ISequenceEvent, Range>(); Predicate<ISequenceEvent> notMoved = Predicates.not(Predicates.in(sequenceEventsToRange.keySet())); // CombinedFragments for (EventEnd sortedEnd : semanticOrdering) { Predicate<ISequenceEvent> frames = Predicates.and(notMoved, Predicates.or( Predicates.instanceOf(CombinedFragment.class), Predicates.instanceOf(InteractionUse.class))); for (ISequenceEvent ise : Iterables.filter(endToISequencEvents.get(sortedEnd), frames)) { computeFinalRange(endLocations, sequenceEventsToRange, ise); }/*from w w w . jav a2 s. co m*/ } // Operands for (EventEnd sortedEnd : semanticOrdering) { Predicate<ISequenceEvent> operands = Predicates.and(notMoved, Predicates.instanceOf(Operand.class)); for (ISequenceEvent ise : Iterables.filter(endToISequencEvents.get(sortedEnd), operands)) { computeFinalRange(endLocations, sequenceEventsToRange, ise); } } // Other sequence events for (EventEnd sortedEnd : semanticOrdering) { for (ISequenceEvent ise : Iterables.filter(endToISequencEvents.get(sortedEnd), notMoved)) { computeFinalRange(endLocations, sequenceEventsToRange, ise); } } return sequenceEventsToRange; }
From source file:org.immutables.value.processor.meta.ValueType.java
public List<ValueAttribute> getConstructorOmited() { return FluentIterable.from(getImplementedAttributes()) .filter(Predicates.not(Predicates.in(getConstructorArguments()))).toList(); }
From source file:com.palantir.atlasdb.transaction.impl.SerializableTransaction.java
private void verifyCells(Transaction ro) { for (String table : cellsRead.keySet()) { final ConcurrentNavigableMap<Cell, byte[]> readsForTable = getReadsForTable(table); for (Iterable<Cell> batch : Iterables.partition(cellsRead.get(table), 1000)) { if (writesByTable.get(table) != null) { // We don't want to verify any reads that we wrote to cause we will just read our own values. // NB: If the value has changed between read and write, our normal SI checking handles this case batch = Iterables.filter(batch, Predicates.not(Predicates.in(writesByTable.get(table).keySet()))); }//from w w w .ja v a2s. c o m ImmutableSet<Cell> batchSet = ImmutableSet.copyOf(batch); Map<Cell, byte[]> currentBatch = ro.get(table, batchSet); ImmutableMap<Cell, byte[]> originalReads = Maps.toMap( Sets.intersection(batchSet, readsForTable.keySet()), Functions.forMap(readsForTable)); if (!areMapsEqual(currentBatch, originalReads)) { throw TransactionSerializableConflictException.create(table, getTimestamp(), System.currentTimeMillis() - timeCreated); } } } }