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);
}
}
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)));
}
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());
}
}
}
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);
}
}
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();
}
}
Aggregations