/** * Checks if the instance is of the type informed or type derived of the informed type. See more in {@link * SType#isTypeOf(SType)}. */ public boolean isTypeOf(@Nonnull SType<?> parentTypeCandidate) { return getType().isTypeOf(parentTypeCandidate); } }
public final boolean isDependentType(SType<?> type) { if (dependentTypes != null) { for (SType<?> d : dependentTypes) { if (type.isTypeOf(d)) { return true; } } } return superType != null && superType.isDependentType(type); }
public final boolean isDependentType(SType<?> type) { if (dependentTypes != null) { for (SType<?> d : dependentTypes) { if (type.isTypeOf(d)) { return true; } } } return superType != null && superType.isDependentType(type); }
/** Finds the common parent type of the two types. */ @Nonnull static final SType<?> findCommonType(@Nonnull SType<?> type1, @Nonnull SType<?> type2) { verifySameDictionary(type1, type2); for (SType<?> current = type1; ; current = current.getSuperType()) { if (type2.isTypeOf(current)) { return current; } } }
/** * Retorna uma Stream que percorre os descendentes de <code>node</code> do tipo especificado. * @param root instância inicial da busca * @param descendantType tipo do descendente * @return Stream das instâncias de descendentes do tipo especificado */ @SuppressWarnings("unchecked") public static <D extends SInstance> Stream<D> streamDescendants(SInstance root, boolean includeRoot, SType<D> descendantType) { return streamDescendants(root, includeRoot) .filter(it -> it.getType().isTypeOf(descendantType)) .map(it -> (D) it); }
/** * Lista os descendentes de <code>node</code> do tipo especificado. * @param instance instância inicial da busca * @param descendantType tipo do descendente * @return Lista das instâncias de descendentes do tipo especificado */ @SuppressWarnings("unchecked") public static <D extends SInstance, V> List<V> listDescendants(SInstance instance, SType<?> descendantType, Function<D, V> function) { List<V> result = new ArrayList<>(); final Deque<SInstance> deque = new ArrayDeque<>(); deque.add(instance); while (!deque.isEmpty()) { final SInstance node = deque.removeFirst(); if (node.getType().isTypeOf(descendantType)) { result.add(function.apply((D) node)); } else { deque.addAll(children(node)); } } return result; }
/** * Busca pelo primeiro descendente de <code>node</code> do tipo especificado. * @param instance instância inicial da busca * @param descendantType tipo do descendente * @return Optional da instância do primeiro descendente do tipo especificado */ @SuppressWarnings("unchecked") public static <D extends SInstance> Optional<D> findDescendant(SInstance instance, SType<D> descendantType) { final Deque<SInstance> deque = new ArrayDeque<>(); deque.add(instance); while (!deque.isEmpty()) { final SInstance node = deque.removeFirst(); if (node.getType().isTypeOf(descendantType)) { return Optional.of((D) node); } else { deque.addAll(children(node)); } } return Optional.empty(); }
/** * Busca por um ancestral de <code>node</code> do tipo especificado. * @param node instância inicial da busca * @param ancestorType tipo do ancestral * @return Optional da instância do ancestral do tipo especificado */ @SuppressWarnings("unchecked") public static <A extends SInstance & ICompositeInstance> Optional<A> findAncestor(SInstance node, SType<A> ancestorType) { for (SInstance parent = node.getParent(); parent != null; parent = parent.getParent()) { if (parent.getType().isTypeOf(ancestorType)) { return Optional.of((A) parent); } } return Optional.empty(); }
private boolean hasDirectOrInderectDependentType(SType<?> type) { if (dependentTypes != null) { for(SType<?> d : dependentTypes ) { if (type.isTypeOf(d)) { return true; } else if (d.hasDirectOrInderectDependentType(type)) { return true; } } } else if (superType != null) { return superType.hasDirectOrInderectDependentType(type); } return false; }
/** * Busca por um ancestral de <code>node</code> cujo tipo é um ancestral comum do tipo de <code>node</code> * e <code>targetType</code>. * @param node instância inicial da busca * @param targetType tipo de outro campo * @return Optional da instância do ancestral comum */ @SuppressWarnings("unchecked") public static <CA extends SInstance & ICompositeInstance> Optional<CA> findCommonAncestor(SInstance node, SType<?> targetType) { for (SScope type = targetType; type != null; type = type.getParentScope()) { for (SInstance ancestor = node; ancestor != null; ancestor = ancestor.getParent()) { if (SType.class.isAssignableFrom(type.getClass()) && ancestor.getType().isTypeOf((SType<?>) type) && ancestor instanceof ICompositeInstance) { return Optional.of((CA) ancestor); } } } return Optional.empty(); }
/** * Lista os ancestrais de <code>node</code>. * @param instance instância inicial da busca * @return Lista das instâncias de ancestrais do tipo especificado */ public static List<SInstance> listAscendants(SInstance instance, SType<?> limitInclusive, boolean selfIncluded) { List<SInstance> list = new ArrayList<>(); if (selfIncluded) { list.add(instance); } SInstance node = instance.getParent(); while (node != null && !node.getType().isTypeOf(limitInclusive)) { list.add(node); node = node.getParent(); } return list; }
/** Retorna o primeiro diff que encotrar na árvore que é do tipo informado ou de sub tipo do tipo informado. */ final Optional<DiffInfo> findFirst(SType<?> field) { return findFirst(diff -> (diff.getOriginal() != null && diff.getOriginal().getType().isTypeOf(field)) || (diff.getNewer() != null && diff.getNewer().getType().isTypeOf(field))); }
/** * This method create a predicate for verify if the instance have a element with the sortableProperty. * <p>Note: This verify with the name of the Stype. * * @return Predicate verify if have a Stype with the <code>sortableProperty</code> for a SIntance. */ private Predicate<SInstance> isCurrentSortInstance() { return i -> i.getType().isTypeOf(i.getType().getDictionary().getType(sortableProperty)) || SFormUtil.findChildByName(i, sortableProperty).isPresent(); }