List of usage examples for org.apache.commons.collections Predicate Predicate
Predicate
From source file:org.apache.ambari.server.orm.dao.HostConfigMappingDAO.java
@RequiresSession public Set<HostConfigMapping> findSelectedByHosts(long clusterId, Collection<String> hostNames) { populateCache();/*from w ww. ja v a 2 s . c o m*/ if (hostNames == null || hostNames.isEmpty()) { return Collections.emptySet(); } HashSet<HostConfigMapping> result = new HashSet<HostConfigMapping>(); for (final String hostName : hostNames) { if (!hostConfigMappingByHost.containsKey(hostName)) continue; Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostName)); CollectionUtils.filter(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getHostName().equals(hostName) && ((HostConfigMapping) arg0).getSelected() > 0; } }); result.addAll(set); } return result; }
From source file:org.apache.ambari.server.orm.dao.HostConfigMappingDAO.java
/** * @param clusterId/*from www . jav a2s .c o m*/ * @param hostName */ @Transactional public void removeHost(final long clusterId, String hostName) { populateCache(); Set<HostConfigMapping> set = hostConfigMappingByHost.get(hostName); //Remove from cache items with clusterId CollectionUtils.filter(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return !((HostConfigMapping) arg0).getClusterId().equals(clusterId); } }); //delete from db TypedQuery<HostConfigMappingEntity> query = entityManagerProvider.get() .createQuery( "SELECT entity FROM HostConfigMappingEntity entity " + "WHERE entity.clusterId = ?1 AND entity.hostName = ?2", HostConfigMappingEntity.class); List<HostConfigMappingEntity> list = daoUtils.selectList(query, Long.valueOf(clusterId), hostName); for (HostConfigMappingEntity entity : list) { entityManagerProvider.get().remove(entity); } }
From source file:org.apache.ambari.server.orm.dao.ServiceConfigDAO.java
@Transactional public void removeHostFromServiceConfigs(final Long hostId) { List<ServiceConfigEntity> allServiceConfigs = this.findAll(); for (ServiceConfigEntity serviceConfigEntity : allServiceConfigs) { List<Long> hostIds = serviceConfigEntity.getHostIds(); if (hostIds != null && hostIds.contains(hostId)) { // Remove the hostId CollectionUtils.filter(hostIds, new Predicate() { @Override//from w ww . ja va2 s. com public boolean evaluate(Object arg0) { return !((Long) arg0).equals(hostId); } }); serviceConfigEntity.setHostIds(hostIds); } } }
From source file:org.apache.atlas.repository.util.FilterUtil.java
private static Predicate getNamePredicate(final String name) { return new Predicate() { private boolean isAtlasType(Object o) { return o instanceof AtlasType; }//from w w w.j av a 2s .c o m @Override public boolean evaluate(Object o) { return o != null && isAtlasType(o) && Objects.equals(((AtlasType) o).getTypeName(), name); } }; }
From source file:org.apache.atlas.repository.util.FilterUtil.java
private static Predicate getSuperTypePredicate(final String supertype) { return new Predicate() { private boolean isClassificationType(Object o) { return o instanceof AtlasClassificationType; }//from w ww . j av a2 s . c o m private boolean isEntityType(Object o) { return o instanceof AtlasEntityType; } @Override public boolean evaluate(Object o) { return (isClassificationType(o) && ((AtlasClassificationType) o).getAllSuperTypes().contains(supertype)) || (isEntityType(o) && ((AtlasEntityType) o).getAllSuperTypes().contains(supertype)); } }; }
From source file:org.apache.atlas.repository.util.FilterUtil.java
private static Predicate getTypePredicate(final String type) { return new Predicate() { @Override//w w w . j a va 2 s . com public boolean evaluate(Object o) { if (o instanceof AtlasType) { AtlasType atlasType = (AtlasType) o; switch (type.toUpperCase()) { case "CLASS": case "ENTITY": return atlasType.getTypeCategory() == TypeCategory.ENTITY; case "TRAIT": case "CLASSIFICATION": return atlasType.getTypeCategory() == TypeCategory.CLASSIFICATION; case "STRUCT": return atlasType.getTypeCategory() == TypeCategory.STRUCT; case "ENUM": return atlasType.getTypeCategory() == TypeCategory.ENUM; default: // This shouldn't have happened return false; } } return false; } }; }
From source file:org.apache.carbondata.datamap.bloom.BloomDataMapWriter.java
BloomDataMapWriter(String tablePath, String dataMapName, List<CarbonColumn> indexColumns, Segment segment, String shardName, SegmentProperties segmentProperties, int bloomFilterSize, double bloomFilterFpp, boolean compressBloom) throws IOException { super(tablePath, dataMapName, indexColumns, segment, shardName, segmentProperties, bloomFilterSize, bloomFilterFpp, compressBloom); columnarSplitter = segmentProperties.getFixedLengthKeySplitter(); this.indexCol2MdkIdx = new HashMap<>(); int idx = 0;//from w w w .j a va 2 s.co m for (final CarbonDimension dimension : segmentProperties.getDimensions()) { if (!dimension.isGlobalDictionaryEncoding() && !dimension.isDirectDictionaryEncoding()) { continue; } boolean isExistInIndex = CollectionUtils.exists(indexColumns, new Predicate() { @Override public boolean evaluate(Object object) { return ((CarbonColumn) object).getColName().equalsIgnoreCase(dimension.getColName()); } }); if (isExistInIndex) { this.indexCol2MdkIdx.put(dimension.getColName(), idx); } idx++; } }
From source file:org.apache.cayenne.modeler.dialog.codegen.ClientModeController.java
public ClientModeController(CodeGeneratorControllerBase parent) { super(parent); this.checkPredicate = new Predicate() { public boolean evaluate(Object object) { if (object instanceof ObjEntity) { ObjEntity entity = (ObjEntity) object; return entity.isClientAllowed() && getParentController().getProblem(entity.getName()) == null; }/*w ww . j a v a 2 s. c o m*/ return false; } }; }
From source file:org.apache.cayenne.modeler.dialog.codegen.GeneratorController.java
/** * Returns a predicate for default entity selection in a given mode. *///from ww w . ja v a2 s. c om public Predicate getDefaultClassFilter() { final ObjEntity selectedEntity = Application.getInstance().getFrameController().getProjectController() .getCurrentObjEntity(); final Embeddable selectedEmbeddable = Application.getInstance().getFrameController().getProjectController() .getCurrentEmbeddable(); // select a single entity if (selectedEntity != null) { final boolean hasProblem = getParentController().getProblem(selectedEntity.getName()) != null; return new Predicate() { public boolean evaluate(Object object) { return !hasProblem && object == selectedEntity; } }; } // select a single embeddable else if (selectedEmbeddable != null) { final boolean hasProblem = getParentController().getProblem(selectedEmbeddable.getClassName()) != null; return new Predicate() { public boolean evaluate(Object object) { return !hasProblem && object == selectedEmbeddable; } }; } // select all entities else { return new Predicate() { public boolean evaluate(Object object) { if (object instanceof ObjEntity) { return getParentController().getProblem(((ObjEntity) object).getName()) == null; } if (object instanceof Embeddable) { return getParentController().getProblem(((Embeddable) object).getClassName()) == null; } return false; } }; } }
From source file:org.apache.cayenne.modeler.editor.ObjEntityTab.java
/** * Updates the view from the current model state. Invoked when a currently displayed * ObjEntity is changed.//from ww w.j a va 2 s. c om * * @param entity current entity */ private void initFromModel(final ObjEntity entity) { // TODO: this is a hack until we implement a real MVC qualifier.getComponent().setBackground(Color.WHITE); name.setText(entity.getName()); superClassName.setText(entity.getSuperClassName()); className.setText(entity.getClassName()); readOnly.setSelected(entity.isReadOnly()); isAbstract.setSelected(entity.isAbstract()); serverOnly.setSelected(entity.isServerOnly()); clientClassName.setText(entity.getClientClassName()); clientSuperClassName.setText(entity.getClientSuperClassName()); qualifier.setText(new ExpressionConvertor().valueAsString(entity.getDeclaredQualifier())); // TODO: fix inheritance - we should allow to select optimistic // lock if superclass is not already locked, // otherwise we must keep this checked in but not editable. optimisticLocking.setSelected(entity.getDeclaredLockType() == ObjEntity.LOCK_TYPE_OPTIMISTIC); excludeSuperclassListeners.setSelected(entity.isExcludingSuperclassListeners()); excludeDefaultListeners.setSelected(entity.isExcludingDefaultListeners()); // init DbEntities EntityResolver resolver = mediator.getEntityResolver(); DataMap map = mediator.getCurrentDataMap(); Object[] dbEntities = resolver.getDbEntities().toArray(); Arrays.sort(dbEntities, Comparators.getDataMapChildrenComparator()); DefaultComboBoxModel dbModel = new DefaultComboBoxModel(dbEntities); dbModel.setSelectedItem(entity.getDbEntity()); dbEntityCombo.setRenderer(CellRenderers.entityListRendererWithIcons(map)); dbEntityCombo.setModel(dbModel); boolean isUsedInheritance = entity.getSuperEntity() != null; dbEntityCombo.setEnabled(!isUsedInheritance); // toggle visibilty and editability rules toggleClientFieldsVisible(map.isClientSupported()); toggleEnabled(entity.getSuperEntityName() == null, !entity.isServerOnly()); // init ObjEntities for inheritance Predicate inheritanceFilter = new Predicate() { public boolean evaluate(Object object) { // do not show this entity or any of the subentities if (entity == object) { return false; } if (object instanceof ObjEntity) { return !((ObjEntity) object).isSubentityOf(entity); } return false; } }; Object[] objEntities = CollectionUtils.select(map.getObjEntities(), inheritanceFilter).toArray(); Arrays.sort(objEntities, Comparators.getDataMapChildrenComparator()); Object[] finalObjEntities = new Object[objEntities.length + 1]; finalObjEntities[0] = noInheritance; System.arraycopy(objEntities, 0, finalObjEntities, 1, objEntities.length); DefaultComboBoxModel superEntityModel = new DefaultComboBoxModel(finalObjEntities); superEntityModel.setSelectedItem(entity.getSuperEntity()); superEntityCombo.setRenderer(CellRenderers.entityListRendererWithIcons(map)); superEntityCombo.setModel(superEntityModel); }