Search in sources :

Example 21 with Objects

use of java.util.Objects in project wildfly by wildfly.

the class HibernateSecondLevelCache method addSecondLevelCacheDependencies.

public static void addSecondLevelCacheDependencies(Properties mutableProperties, String scopedPersistenceUnitName) {
    if (mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX) == null) {
        if (scopedPersistenceUnitName != null) {
            mutableProperties.setProperty(AvailableSettings.CACHE_REGION_PREFIX, scopedPersistenceUnitName);
        }
    }
    String regionFactory = mutableProperties.getProperty(AvailableSettings.CACHE_REGION_FACTORY);
    if (regionFactory == null) {
        regionFactory = DEFAULT_REGION_FACTORY;
        mutableProperties.setProperty(AvailableSettings.CACHE_REGION_FACTORY, regionFactory);
    }
    if (regionFactory.equals(DEFAULT_REGION_FACTORY)) {
        // Set infinispan defaults
        String container = mutableProperties.getProperty(CACHE_CONTAINER);
        if (container == null) {
            container = DEFAULT_CACHE_CONTAINER;
            mutableProperties.setProperty(CACHE_CONTAINER, container);
        }
        /**
             * AS will need the ServiceBuilder<?> builder that used to be passed to PersistenceProviderAdaptor.addProviderDependencies
             */
        Properties cacheSettings = new Properties();
        cacheSettings.put(CONTAINER, container);
        cacheSettings.put(ENTITY, mutableProperties.getProperty(ENTITY_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
        cacheSettings.put(IMMUTABLE_ENTITY, mutableProperties.getProperty(IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
        cacheSettings.put(COLLECTION, mutableProperties.getProperty(COLLECTION_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
        cacheSettings.put(NATURAL_ID, mutableProperties.getProperty(NATURAL_ID_CACHE_RESOURCE_PROP, DEF_ENTITY_RESOURCE));
        if (mutableProperties.getProperty(PENDING_PUTS_CACHE_RESOURCE_PROP) != null) {
            cacheSettings.put(PENDING_PUTS, mutableProperties.getProperty(PENDING_PUTS_CACHE_RESOURCE_PROP));
        }
        if (Boolean.parseBoolean(mutableProperties.getProperty(AvailableSettings.USE_QUERY_CACHE))) {
            cacheSettings.put(QUERY, mutableProperties.getProperty(QUERY_CACHE_RESOURCE_PROP, DEF_QUERY_RESOURCE));
            cacheSettings.put(TIMESTAMPS, mutableProperties.getProperty(TIMESTAMPS_CACHE_RESOURCE_PROP, DEF_QUERY_RESOURCE));
        }
        // Collect distinct cache configurations for standard regions
        Set<String> standardRegionConfigs = Stream.of(ENTITY, IMMUTABLE_ENTITY, COLLECTION, NATURAL_ID, PENDING_PUTS, QUERY, TIMESTAMPS).map(region -> cacheSettings.getProperty(region)).filter(Objects::nonNull).collect(Collectors.toSet());
        int length = INFINISPAN_CONFIG_RESOURCE_PROP.length();
        String customRegionPrefix = INFINISPAN_CONFIG_RESOURCE_PROP.substring(0, length - 3) + mutableProperties.getProperty(AvailableSettings.CACHE_REGION_PREFIX, "");
        String customRegionSuffix = INFINISPAN_CONFIG_RESOURCE_PROP.substring(length - 4, length);
        // Collect distinct cache configurations for custom regions
        Set<String> customRegionConfigs = mutableProperties.stringPropertyNames().stream().filter(name -> name.startsWith(customRegionPrefix) && name.endsWith(customRegionSuffix)).map(name -> mutableProperties.getProperty(name)).filter(config -> !standardRegionConfigs.contains(config)).collect(Collectors.toSet());
        if (!customRegionConfigs.isEmpty()) {
            cacheSettings.setProperty(CUSTOM, String.join(" ", customRegionConfigs));
        }
        Notification.addCacheDependencies(Classification.INFINISPAN, cacheSettings);
    }
}
Also used : NATURAL_ID_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.NATURAL_ID_CACHE_RESOURCE_PROP) COLLECTION_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.COLLECTION_CACHE_RESOURCE_PROP) DEF_QUERY_RESOURCE(org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_QUERY_RESOURCE) INFINISPAN_CONFIG_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP) Properties(java.util.Properties) Notification(org.jipijapa.event.impl.internal.Notification) DEFAULT_CACHE_CONTAINER(org.jboss.as.jpa.hibernate5.infinispan.InfinispanRegionFactory.DEFAULT_CACHE_CONTAINER) DEF_ENTITY_RESOURCE(org.hibernate.cache.infinispan.InfinispanRegionFactory.DEF_ENTITY_RESOURCE) AvailableSettings(org.hibernate.cfg.AvailableSettings) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) SharedInfinispanRegionFactory(org.jboss.as.jpa.hibernate5.infinispan.SharedInfinispanRegionFactory) PENDING_PUTS_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.PENDING_PUTS_CACHE_RESOURCE_PROP) CACHE_CONTAINER(org.jboss.as.jpa.hibernate5.infinispan.InfinispanRegionFactory.CACHE_CONTAINER) IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.IMMUTABLE_ENTITY_CACHE_RESOURCE_PROP) Stream(java.util.stream.Stream) QUERY_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP) TIMESTAMPS_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.TIMESTAMPS_CACHE_RESOURCE_PROP) ENTITY_CACHE_RESOURCE_PROP(org.hibernate.cache.infinispan.InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP) Classification(org.jipijapa.cache.spi.Classification) Properties(java.util.Properties)

Example 22 with Objects

use of java.util.Objects in project wildfly by wildfly.

the class AddStepHandler method recordCapabilitiesAndRequirements.

@Override
protected void recordCapabilitiesAndRequirements(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    ModelNode model = resource.getModel();
    // The super implementation assumes that the capability name is a simple extension of the base name - we do not.
    // Only register capabilities when allowed by the associated predicate
    this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.registerCapability(capability.resolve(address)));
    ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
    registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name)).filter(Objects::nonNull).map(AttributeAccess::getAttributeDefinition).filter(Objects::nonNull).filter(AttributeDefinition::hasCapabilityRequirements).forEach(attribute -> attribute.addCapabilityRequirements(context, model.get(attribute.getName())));
    this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.addCapabilityRequirements(context, (String) null, resolver.apply(address)));
}
Also used : OperationEntry(org.jboss.as.controller.registry.OperationEntry) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) PathAddress(org.jboss.as.controller.PathAddress) Collection(java.util.Collection) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) PathElement(org.jboss.as.controller.PathElement) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) Objects(java.util.Objects) BiPredicate(java.util.function.BiPredicate) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) OperationContext(org.jboss.as.controller.OperationContext) Stream(java.util.stream.Stream) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) Util(org.jboss.as.controller.operations.common.Util) Map(java.util.Map) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelType(org.jboss.dmr.ModelType) PathAddress(org.jboss.as.controller.PathAddress) Objects(java.util.Objects) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 23 with Objects

use of java.util.Objects in project wildfly by wildfly.

the class RemoveStepHandler method performRemove.

@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    // Determine whether super impl will actually remove the resource
    boolean remove = !resource.getChildTypes().stream().anyMatch(type -> resource.getChildren(type).stream().filter(entry -> !entry.isRuntime()).map(entry -> entry.getPathElement()).anyMatch(path -> resource.hasChild(path)));
    if (remove) {
        // We need to remove capabilities *before* removing the resource, since the capability reference resolution might involve reading the resource
        PathAddress address = context.getCurrentAddress();
        this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.deregisterCapability(capability.resolve(address).getName()));
        ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
        registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name)).filter(Objects::nonNull).map(AttributeAccess::getAttributeDefinition).filter(Objects::nonNull).filter(AttributeDefinition::hasCapabilityRequirements).forEach(attribute -> attribute.removeCapabilityRequirements(context, model.get(attribute.getName())));
        this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.removeCapabilityRequirements(context, (String) null, resolver.apply(address)));
        // Remove any runtime child resources
        removeRuntimeChildren(context, PathAddress.EMPTY_ADDRESS);
    }
    super.performRemove(context, operation, model);
    if (remove) {
        PathAddress address = context.getResourceRegistration().getPathAddress();
        PathElement path = address.getLastElement();
        // If override model was registered, unregister it
        if (!path.isWildcard() && (context.getResourceRegistration().getParent().getSubModel(PathAddress.pathAddress(path.getKey(), PathElement.WILDCARD_VALUE)) != null)) {
            context.getResourceRegistrationForUpdate().unregisterOverrideModel(context.getCurrentAddressValue());
        }
    }
}
Also used : OperationEntry(org.jboss.as.controller.registry.OperationEntry) Resource(org.jboss.as.controller.registry.Resource) PathAddress(org.jboss.as.controller.PathAddress) PathElement(org.jboss.as.controller.PathElement) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) Objects(java.util.Objects) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) Map(java.util.Map) AbstractRemoveStepHandler(org.jboss.as.controller.AbstractRemoveStepHandler) ModelNode(org.jboss.dmr.ModelNode) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) Objects(java.util.Objects) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) Map(java.util.Map)

Example 24 with Objects

use of java.util.Objects in project gerrit by GerritCodeReview.

the class Schema_147 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    try (Repository repo = repoManager.openRepository(allUsersName)) {
        Set<Account.Id> accountIdsFromReviewDb = db.accounts().all().toList().stream().map(a -> a.getId()).collect(toSet());
        Set<Account.Id> accountIdsFromUserBranches = repo.getRefDatabase().getRefs(RefNames.REFS_USERS).values().stream().map(r -> Account.Id.fromRef(r.getName())).filter(Objects::nonNull).collect(toSet());
        accountIdsFromUserBranches.removeAll(accountIdsFromReviewDb);
        for (Account.Id accountId : accountIdsFromUserBranches) {
            AccountsUpdate.deleteUserBranch(repo, serverIdent, accountId);
        }
    } catch (IOException e) {
        throw new OrmException("Failed to delete user branches for non-existing accounts.", e);
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) OrmException(com.google.gwtorm.server.OrmException) Inject(com.google.inject.Inject) Set(java.util.Set) IOException(java.io.IOException) Objects(java.util.Objects) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Provider(com.google.inject.Provider) SQLException(java.sql.SQLException) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) RefNames(com.google.gerrit.reviewdb.client.RefNames) Account(com.google.gerrit.reviewdb.client.Account) Collectors.toSet(java.util.stream.Collectors.toSet) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) Repository(org.eclipse.jgit.lib.Repository) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) Account(com.google.gerrit.reviewdb.client.Account) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) IOException(java.io.IOException)

Example 25 with Objects

use of java.util.Objects in project fx2048 by brunoborges.

the class GameManager method moveTiles.

/**
     * Moves the tiles according to given direction
     * At any move, takes care of merge tiles, add a new one and perform the
     * required animations
     * It updates the score and checks if the user won the game or if the game is over 
     * 
     * @param direction is the selected direction to move the tiles
     */
private void moveTiles(Direction direction) {
    synchronized (gameGrid) {
        if (movingTiles) {
            return;
        }
    }
    board.setPoints(0);
    mergedToBeRemoved.clear();
    ParallelTransition parallelTransition = new ParallelTransition();
    gridOperator.sortGrid(direction);
    final int tilesWereMoved = gridOperator.traverseGrid((x, y) -> {
        Location thisloc = new Location(x, y);
        // farthest available location
        Location farthestLocation = findFarthestLocation(thisloc, direction);
        Optional<Tile> opTile = optionalTile(thisloc);
        AtomicInteger result = new AtomicInteger();
        // calculates to a possible merge
        Location nextLocation = farthestLocation.offset(direction);
        optionalTile(nextLocation).filter(t -> t.isMergeable(opTile) && !t.isMerged()).ifPresent(t -> {
            Tile tile = opTile.get();
            t.merge(tile);
            t.toFront();
            gameGrid.put(nextLocation, t);
            gameGrid.replace(thisloc, null);
            parallelTransition.getChildren().add(animateExistingTile(tile, t.getLocation()));
            parallelTransition.getChildren().add(animateMergedTile(t));
            mergedToBeRemoved.add(tile);
            board.addPoints(t.getValue());
            if (t.getValue() == FINAL_VALUE_TO_WIN) {
                board.setGameWin(true);
            }
            result.set(1);
        });
        if (result.get() == 0 && opTile.isPresent() && !farthestLocation.equals(thisloc)) {
            Tile tile = opTile.get();
            parallelTransition.getChildren().add(animateExistingTile(tile, farthestLocation));
            gameGrid.put(farthestLocation, tile);
            gameGrid.replace(thisloc, null);
            tile.setLocation(farthestLocation);
            result.set(1);
        }
        return result.get();
    });
    board.animateScore();
    if (parallelTransition.getChildren().size() > 0) {
        parallelTransition.setOnFinished(e -> {
            board.getGridGroup().getChildren().removeAll(mergedToBeRemoved);
            gameGrid.values().stream().filter(Objects::nonNull).forEach(Tile::clearMerge);
            Location randomAvailableLocation = findRandomAvailableLocation();
            if (randomAvailableLocation == null && mergeMovementsAvailable() == 0) {
                board.setGameOver(true);
            } else if (randomAvailableLocation != null && tilesWereMoved > 0) {
                synchronized (gameGrid) {
                    movingTiles = false;
                }
                addAndAnimateRandomTile(randomAvailableLocation);
            }
        });
        synchronized (gameGrid) {
            movingTiles = true;
        }
        parallelTransition.play();
    }
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) Random(java.util.Random) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) HostServices(javafx.application.HostServices) KeyValue(javafx.animation.KeyValue) HBox(javafx.scene.layout.HBox) KeyFrame(javafx.animation.KeyFrame) Iterator(java.util.Iterator) Set(java.util.Set) Timeline(javafx.animation.Timeline) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ParallelTransition(javafx.animation.ParallelTransition) List(java.util.List) ScaleTransition(javafx.animation.ScaleTransition) BooleanProperty(javafx.beans.property.BooleanProperty) Duration(javafx.util.Duration) Stream(java.util.stream.Stream) Interpolator(javafx.animation.Interpolator) SequentialTransition(javafx.animation.SequentialTransition) Optional(java.util.Optional) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelTransition(javafx.animation.ParallelTransition)

Aggregations

Objects (java.util.Objects)55 List (java.util.List)29 Map (java.util.Map)24 Collectors (java.util.stream.Collectors)22 ArrayList (java.util.ArrayList)20 Set (java.util.Set)19 Optional (java.util.Optional)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)14 Collections (java.util.Collections)13 HashSet (java.util.HashSet)10 ImmutableSet (com.google.common.collect.ImmutableSet)9 Result (ddf.catalog.data.Result)9 Stream (java.util.stream.Stream)9 Metacard (ddf.catalog.data.Metacard)8 TimeUnit (java.util.concurrent.TimeUnit)8 LoggerFactory (org.slf4j.LoggerFactory)8 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 Path (java.nio.file.Path)7 Logger (org.slf4j.Logger)7