Search in sources :

Example 21 with EnumSet

use of java.util.EnumSet in project hibernate-orm by hibernate.

the class SchemaUpdateTableBackedSequenceTest method testCreateTableOnUpdate.

@Test
public void testCreateTableOnUpdate() throws SQLException {
    Metadata metadata = new MetadataSources(ssr).buildMetadata();
    Database database = metadata.getDatabase();
    TableStructure tableStructure = new TableStructure(database.getJdbcEnvironment(), new QualifiedTableName(null, null, Identifier.toIdentifier("test_seq")), Identifier.toIdentifier("nextval"), 20, 30, Long.class);
    tableStructure.registerExportables(database);
    // lets make sure the InitCommand is there
    assertEquals(1, database.getDefaultNamespace().getTables().size());
    Table table = database.getDefaultNamespace().getTables().iterator().next();
    assertEquals(1, table.getInitCommands().size());
    final TargetImpl target = new TargetImpl();
    ssr.getService(SchemaManagementTool.class).getSchemaMigrator(Collections.emptyMap()).doMigration(metadata, new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return ssr.getService(ConfigurationService.class).getSettings();
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }
    }, new TargetDescriptor() {

        @Override
        public EnumSet<TargetType> getTargetTypes() {
            return EnumSet.of(TargetType.SCRIPT, TargetType.DATABASE);
        }

        @Override
        public ScriptTargetOutput getScriptTargetOutput() {
            return target;
        }
    });
    assertTrue(target.found);
    new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
Also used : QualifiedTableName(org.hibernate.boot.model.relational.QualifiedTableName) Table(org.hibernate.mapping.Table) EnumSet(java.util.EnumSet) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) TargetDescriptor(org.hibernate.tool.schema.spi.TargetDescriptor) ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) TableStructure(org.hibernate.id.enhanced.TableStructure) Database(org.hibernate.boot.model.relational.Database) ScriptTargetOutput(org.hibernate.tool.schema.spi.ScriptTargetOutput) Map(java.util.Map) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 22 with EnumSet

use of java.util.EnumSet in project Railcraft by Railcraft.

the class GridTools method getMutuallyConnectedObjects.

public static Set<IElectricGrid> getMutuallyConnectedObjects(IElectricGrid gridObject) {
    Set<IElectricGrid> connectedObjects = new HashSet<IElectricGrid>();
    WorldCoordinate myPos = new WorldCoordinate(gridObject.getTile());
    for (Map.Entry<BlockPos, EnumSet<ConnectType>> position : gridObject.getChargeHandler().getPossibleConnectionLocations().entrySet()) {
        Optional<IElectricGrid> otherObj = getGridObjectAt(gridObject.getTile().getWorld(), position.getKey());
        if (otherObj.isPresent() && position.getValue().contains(otherObj.get().getChargeHandler().getType())) {
            EnumSet<ConnectType> otherType = otherObj.get().getChargeHandler().getPossibleConnectionLocations().get(myPos);
            if (otherType != null && otherType.contains(gridObject.getChargeHandler().getType()))
                connectedObjects.add(otherObj.get());
        }
    }
    return connectedObjects;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) EnumSet(java.util.EnumSet) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashSet(java.util.HashSet) ConnectType(mods.railcraft.api.charge.IElectricGrid.ChargeHandler.ConnectType)

Example 23 with EnumSet

use of java.util.EnumSet in project voltdb by VoltDB.

the class MeshProber method considerMeshPlea.

@Override
public JoinAcceptor.PleaDecision considerMeshPlea(ZooKeeper zk, int hostId, JSONObject jo) {
    checkArgument(zk != null, "zookeeper is null");
    checkArgument(jo != null, "json object is null");
    if (!HostCriteria.hasCriteria(jo)) {
        return new JoinAcceptor.PleaDecision(String.format("Joining node version %s is incompatible with this node verion %s", jo.optString(SocketJoiner.VERSION_STRING, "(unknown)"), m_versionChecker.getVersionString()), false, false);
    }
    HostCriteria hc = new HostCriteria(jo);
    Map<Integer, HostCriteria> hostCriteria = m_hostCriteria.get();
    // when the cluster is forming anew)
    if (!getNodeState().operational() && !hostCriteria.values().stream().anyMatch(c -> c.getNodeState().operational())) {
        List<String> incompatibilities = asHostCriteria().listIncompatibilities(hc);
        if (!incompatibilities.isEmpty()) {
            Joiner joiner = Joiner.on("\n    ").skipNulls();
            String error = "Incompatible joining criteria:\n    " + joiner.join(incompatibilities);
            return new JoinAcceptor.PleaDecision(error, false, false);
        }
        return new JoinAcceptor.PleaDecision(null, true, false);
    } else {
        StartAction operationalStartAction = hostCriteria.values().stream().filter(c -> c.getNodeState().operational()).map(c -> c.getStartAction()).findFirst().orElse(getStartAction());
        if (operationalStartAction == StartAction.PROBE && hc.getStartAction() != StartAction.PROBE) {
            String msg = "Invalid VoltDB command. Please use init and start to join this cluster";
            return new JoinAcceptor.PleaDecision(msg, false, false);
        }
    }
    // how many hosts are already in the mesh?
    Stat stat = new Stat();
    try {
        zk.getChildren(CoreZK.hosts, false, stat);
    } catch (InterruptedException e) {
        String msg = "Interrupted while considering mesh plea";
        m_networkLog.error(msg, e);
        return new JoinAcceptor.PleaDecision(msg, false, false);
    } catch (KeeperException e) {
        EnumSet<KeeperException.Code> closing = EnumSet.of(KeeperException.Code.SESSIONEXPIRED, KeeperException.Code.CONNECTIONLOSS);
        if (closing.contains(e.code())) {
            return new JoinAcceptor.PleaDecision("Shutting down", false, false);
        } else {
            String msg = "Failed to list hosts while considering a mesh plea";
            m_networkLog.error(msg, e);
            return new JoinAcceptor.PleaDecision(msg, false, false);
        }
    }
    // connecting to already wholly formed cluster
    if (stat.getNumChildren() >= getHostCount()) {
        return new JoinAcceptor.PleaDecision(hc.isAddAllowed() ? null : "Cluster is already complete", hc.isAddAllowed(), false);
    } else if (stat.getNumChildren() < getHostCount()) {
        // check for concurrent rejoins
        final int rejoiningHost = CoreZK.createRejoinNodeIndicator(zk, hostId);
        if (rejoiningHost == -1) {
            return new JoinAcceptor.PleaDecision(null, true, false);
        } else {
            String msg = "Only one host can rejoin at a time. Host " + rejoiningHost + " is still rejoining.";
            return new JoinAcceptor.PleaDecision(msg, false, true);
        }
    }
    return new JoinAcceptor.PleaDecision(null, true, false);
}
Also used : ImmutableSortedSet(com.google_voltpatches.common.collect.ImmutableSortedSet) Arrays(java.util.Arrays) Supplier(com.google_voltpatches.common.base.Supplier) Preconditions.checkArgument(com.google_voltpatches.common.base.Preconditions.checkArgument) CoreZK(org.voltcore.zk.CoreZK) NodeState(org.voltdb.common.NodeState) SettableFuture(com.google_voltpatches.common.util.concurrent.SettableFuture) VersionChecker(org.voltcore.utils.VersionChecker) Predicates.not(com.google_voltpatches.common.base.Predicates.not) JoinAcceptor(org.voltcore.messaging.JoinAcceptor) InetAddresses(com.google_voltpatches.common.net.InetAddresses) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeSet(java.util.TreeSet) InetAddress(java.net.InetAddress) Generated(javax.annotation.Generated) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) Predicate(com.google_voltpatches.common.base.Predicate) HostAndPort(com.google_voltpatches.common.net.HostAndPort) Map(java.util.Map) JSONObject(org.json_voltpatches.JSONObject) Predicates.equalTo(com.google_voltpatches.common.base.Predicates.equalTo) Constants(org.voltcore.common.Constants) Joiner(com.google_voltpatches.common.base.Joiner) JSONWriter(org.json_voltpatches.JSONWriter) StartAction(org.voltdb.StartAction) EnumSet(java.util.EnumSet) VoltLogger(org.voltcore.logging.VoltLogger) Maps(com.google_voltpatches.common.collect.Maps) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Set(java.util.Set) NavigableSet(java.util.NavigableSet) UUID(java.util.UUID) MiscUtils(org.voltdb.utils.MiscUtils) Suppliers(com.google_voltpatches.common.base.Suppliers) JSONException(org.json_voltpatches.JSONException) SocketJoiner(org.voltcore.messaging.SocketJoiner) Throwables(com.google_voltpatches.common.base.Throwables) ExecutionException(java.util.concurrent.ExecutionException) JSONStringer(org.json_voltpatches.JSONStringer) List(java.util.List) HostMessenger(org.voltcore.messaging.HostMessenger) Stat(org.apache.zookeeper_voltpatches.data.Stat) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap) InternetDomainName(com.google_voltpatches.common.net.InternetDomainName) Preconditions.checkNotNull(com.google_voltpatches.common.base.Preconditions.checkNotNull) Digester(org.voltdb.utils.Digester) Optional(java.util.Optional) Splitter(com.google_voltpatches.common.base.Splitter) Joiner(com.google_voltpatches.common.base.Joiner) SocketJoiner(org.voltcore.messaging.SocketJoiner) JoinAcceptor(org.voltcore.messaging.JoinAcceptor) EnumSet(java.util.EnumSet) StartAction(org.voltdb.StartAction) Stat(org.apache.zookeeper_voltpatches.data.Stat) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 24 with EnumSet

use of java.util.EnumSet in project jackson-databind by FasterXML.

the class EnumAltIdTest method testIgnoreCaseInEnumSet.

public void testIgnoreCaseInEnumSet() throws IOException {
    ObjectReader r = READER_IGNORE_CASE.forType(new TypeReference<EnumSet<TestEnum>>() {
    });
    EnumSet<TestEnum> set = r.readValue("[\"jackson\"]");
    assertEquals(1, set.size());
    assertTrue(set.contains(TestEnum.JACKSON));
}
Also used : EnumSet(java.util.EnumSet) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 25 with EnumSet

use of java.util.EnumSet in project kotlin by JetBrains.

the class ResourceEvaluator method getResourceTypes.

/**
     * Evaluates the given node and returns the resource types applicable to the
     * node, if any.
     *
     * @param element the element to compute the types for
     * @return the corresponding resource types
     */
@Nullable
public EnumSet<ResourceType> getResourceTypes(@Nullable PsiElement element) {
    if (element == null) {
        return null;
    }
    if (element instanceof PsiConditionalExpression) {
        PsiConditionalExpression expression = (PsiConditionalExpression) element;
        Object known = ConstantEvaluator.evaluate(null, expression.getCondition());
        if (known == Boolean.TRUE && expression.getThenExpression() != null) {
            return getResourceTypes(expression.getThenExpression());
        } else if (known == Boolean.FALSE && expression.getElseExpression() != null) {
            return getResourceTypes(expression.getElseExpression());
        } else {
            EnumSet<ResourceType> left = getResourceTypes(expression.getThenExpression());
            EnumSet<ResourceType> right = getResourceTypes(expression.getElseExpression());
            if (left == null) {
                return right;
            } else if (right == null) {
                return left;
            } else {
                EnumSet<ResourceType> copy = EnumSet.copyOf(left);
                copy.addAll(right);
                return copy;
            }
        }
    } else if (element instanceof PsiParenthesizedExpression) {
        PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression) element;
        return getResourceTypes(parenthesizedExpression.getExpression());
    } else if (element instanceof PsiMethodCallExpression && mAllowDereference) {
        PsiMethodCallExpression call = (PsiMethodCallExpression) element;
        PsiReferenceExpression expression = call.getMethodExpression();
        PsiMethod method = call.resolveMethod();
        if (method != null && method.getContainingClass() != null) {
            EnumSet<ResourceType> types = getTypesFromAnnotations(method);
            if (types != null) {
                return types;
            }
            String qualifiedName = method.getContainingClass().getQualifiedName();
            String name = expression.getReferenceName();
            if ((CLASS_RESOURCES.equals(qualifiedName) || CLASS_CONTEXT.equals(qualifiedName) || CLASS_FRAGMENT.equals(qualifiedName) || CLASS_V4_FRAGMENT.equals(qualifiedName) || CLS_TYPED_ARRAY.equals(qualifiedName)) && name != null && name.startsWith("get")) {
                PsiExpression[] args = call.getArgumentList().getExpressions();
                if (args.length > 0) {
                    types = getResourceTypes(args[0]);
                    if (types != null) {
                        return types;
                    }
                }
            }
        }
    } else if (element instanceof PsiReference) {
        ResourceUrl url = getResourceConstant(element);
        if (url != null) {
            return EnumSet.of(url.type);
        }
        PsiElement resolved = ((PsiReference) element).resolve();
        if (resolved instanceof PsiField) {
            url = getResourceConstant(resolved);
            if (url != null) {
                return EnumSet.of(url.type);
            }
            PsiField field = (PsiField) resolved;
            if (field.getInitializer() != null) {
                return getResourceTypes(field.getInitializer());
            }
            return null;
        } else if (resolved instanceof PsiParameter) {
            return getTypesFromAnnotations((PsiParameter) resolved);
        } else if (resolved instanceof PsiLocalVariable) {
            PsiLocalVariable variable = (PsiLocalVariable) resolved;
            PsiStatement statement = PsiTreeUtil.getParentOfType(element, PsiStatement.class, false);
            if (statement != null) {
                PsiStatement prev = PsiTreeUtil.getPrevSiblingOfType(statement, PsiStatement.class);
                String targetName = variable.getName();
                if (targetName == null) {
                    return null;
                }
                while (prev != null) {
                    if (prev instanceof PsiDeclarationStatement) {
                        PsiDeclarationStatement prevStatement = (PsiDeclarationStatement) prev;
                        for (PsiElement e : prevStatement.getDeclaredElements()) {
                            if (variable.equals(e)) {
                                return getResourceTypes(variable.getInitializer());
                            }
                        }
                    } else if (prev instanceof PsiExpressionStatement) {
                        PsiExpression expression = ((PsiExpressionStatement) prev).getExpression();
                        if (expression instanceof PsiAssignmentExpression) {
                            PsiAssignmentExpression assign = (PsiAssignmentExpression) expression;
                            PsiExpression lhs = assign.getLExpression();
                            if (lhs instanceof PsiReferenceExpression) {
                                PsiReferenceExpression reference = (PsiReferenceExpression) lhs;
                                if (targetName.equals(reference.getReferenceName()) && reference.getQualifier() == null) {
                                    return getResourceTypes(assign.getRExpression());
                                }
                            }
                        }
                    }
                    prev = PsiTreeUtil.getPrevSiblingOfType(prev, PsiStatement.class);
                }
            }
        }
    }
    return null;
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiDeclarationStatement(com.intellij.psi.PsiDeclarationStatement) PsiExpression(com.intellij.psi.PsiExpression) PsiMethod(com.intellij.psi.PsiMethod) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) EnumSet(java.util.EnumSet) PsiReference(com.intellij.psi.PsiReference) ResourceType(com.android.resources.ResourceType) PsiAssignmentExpression(com.intellij.psi.PsiAssignmentExpression) PsiLocalVariable(com.intellij.psi.PsiLocalVariable) PsiConditionalExpression(com.intellij.psi.PsiConditionalExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression) PsiParameter(com.intellij.psi.PsiParameter) PsiExpressionStatement(com.intellij.psi.PsiExpressionStatement) PsiField(com.intellij.psi.PsiField) PsiParenthesizedExpression(com.intellij.psi.PsiParenthesizedExpression) ResourceUrl(com.android.ide.common.resources.ResourceUrl) PsiElement(com.intellij.psi.PsiElement) Nullable(com.android.annotations.Nullable)

Aggregations

EnumSet (java.util.EnumSet)58 Set (java.util.Set)18 Map (java.util.Map)16 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 TreeSet (java.util.TreeSet)7 Test (org.junit.Test)7 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 List (java.util.List)5 TreeMap (java.util.TreeMap)5 StateStorage.toStringStringSetMap (org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap)5 PathAddress (org.jboss.as.controller.PathAddress)5 PathElement (org.jboss.as.controller.PathElement)5 ModelNode (org.jboss.dmr.ModelNode)5 FeatureState (org.apache.karaf.features.FeatureState)4 Nullable (com.android.annotations.Nullable)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2