当前位置: 首页>>代码示例>>Java>>正文


Java NamespaceVersion.compareTo方法代码示例

本文整理汇总了Java中com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java NamespaceVersion.compareTo方法的具体用法?Java NamespaceVersion.compareTo怎么用?Java NamespaceVersion.compareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion的用法示例。


在下文中一共展示了NamespaceVersion.compareTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: merge

import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion; //导入方法依赖的package包/类
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @param policies collection of policies to be merged. The collection must not contain '{@code null}' elements!
 * @return merged policy containing combination of policy alternatives stored in all input policies.
 *         If provided collection of policies is {@code null} or empty, returns {@code null}. If provided
 *         collection of policies contains only single policy, the policy is returned.
 */
public Policy merge(final Collection<Policy> policies) {
    if (policies == null || policies.isEmpty()) {
        return null;
    } else if (policies.size() == 1) {
        return policies.iterator().next();
    }

    final Collection<Collection<AssertionSet>> alternativeSets = new LinkedList<Collection<AssertionSet>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:PolicyMerger.java

示例2: intersect

import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion; //导入方法依赖的package包/类
/**
 * Performs intersection on the input collection of policies and returns the resulting (intersected) policy. If input policy
 * collection contains only a single policy instance, no intersection is performed and the instance is directly returned
 * as a method call result.
 *
 * @param policies collection of policies to be intersected. Must not be {@code null} nor empty, otherwise exception is thrown.
 * @return intersected policy as a result of perfromed policy intersection. A {@code null} value is never returned.
 *
 * @throws IllegalArgumentException in case {@code policies} argument is either {@code null} or empty collection.
 */
public Policy intersect(final Policy... policies) {
    if (policies == null || policies.length == 0) {
        throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0056_NEITHER_NULL_NOR_EMPTY_POLICY_COLLECTION_EXPECTED()));
    } else if (policies.length == 1) {
        return policies[0];
    }

    // check for "null" and "empty" policy: if such policy is found return "null" policy,
    // or if all policies are "empty", return "empty" policy
    boolean found = false;
    boolean allPoliciesEmpty = true;
    NamespaceVersion latestVersion = null;
    for (Policy tested : policies) {
        if (tested.isEmpty()) {
            found = true;
        } else {
            if (tested.isNull()) {
                found = true;
            }
            allPoliciesEmpty = false;
        }
        if (latestVersion == null) {
            latestVersion = tested.getNamespaceVersion();
        } else if (latestVersion.compareTo(tested.getNamespaceVersion()) < 0) {
            latestVersion = tested.getNamespaceVersion();
        }

        if (found && !allPoliciesEmpty) {
            return Policy.createNullPolicy(latestVersion, null, null);
        }
    }
    latestVersion = (latestVersion != null) ? latestVersion : NamespaceVersion.getLatestVersion();
    if (allPoliciesEmpty) {
        return Policy.createEmptyPolicy(latestVersion, null, null);
    }

    // simple tests didn't lead to final answer => let's performe some intersecting ;)
    final List<AssertionSet> finalAlternatives = new LinkedList<AssertionSet>(policies[0].getContent());
    final Queue<AssertionSet> testedAlternatives = new LinkedList<AssertionSet>();
    final List<AssertionSet> alternativesToMerge = new ArrayList<AssertionSet>(2);
    for (int i = 1; i < policies.length; i++) {
        final Collection<AssertionSet> currentAlternatives = policies[i].getContent();

        testedAlternatives.clear();
        testedAlternatives.addAll(finalAlternatives);
        finalAlternatives.clear();

        AssertionSet testedAlternative;
        while ((testedAlternative = testedAlternatives.poll()) != null) {
            for (AssertionSet currentAlternative : currentAlternatives) {
                if (testedAlternative.isCompatibleWith(currentAlternative, this.mode)) {
                    alternativesToMerge.add(testedAlternative);
                    alternativesToMerge.add(currentAlternative);
                    finalAlternatives.add(AssertionSet.createMergedAssertionSet(alternativesToMerge));
                    alternativesToMerge.clear();
                }
            }
        }
    }

    return Policy.createPolicy(latestVersion, null, null, finalAlternatives);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:73,代码来源:PolicyIntersector.java


注:本文中的com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion.compareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。