|
Java example source code file (RawTypeSet.java)
The RawTypeSet.java Java example source code/* * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.internal.xjc.reader; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.activation.MimeType; import com.sun.tools.internal.xjc.model.CElementPropertyInfo; import static com.sun.tools.internal.xjc.model.CElementPropertyInfo.CollectionMode.*; import com.sun.tools.internal.xjc.model.CReferencePropertyInfo; import com.sun.tools.internal.xjc.model.CTypeRef; import com.sun.tools.internal.xjc.model.Multiplicity; import com.sun.tools.internal.xjc.model.nav.NType; import com.sun.xml.internal.bind.v2.model.core.Element; import com.sun.xml.internal.bind.v2.model.core.ID; import java.math.BigInteger; /** * Set of {@link Ref}. * * @author Kohsuke Kawaguchi */ public final class RawTypeSet { public final Set<Ref> refs; /** * True if this type set can form references to types. */ public final Mode canBeTypeRefs; /** * The occurence of the whole references. */ public final Multiplicity mul; // computed inside canBeTypeRefs() private CElementPropertyInfo.CollectionMode collectionMode; /** * Should be called from one of the raw type set builders. */ public RawTypeSet( Set<Ref> refs, Multiplicity m ) { this.refs = refs; mul = m; canBeTypeRefs = canBeTypeRefs(); } public CElementPropertyInfo.CollectionMode getCollectionMode() { return collectionMode; } public boolean isRequired() { return mul.min.compareTo(BigInteger.ZERO) == 1; } /** * Represents the possible binding option for this {@link RawTypeSet}. */ public enum Mode { /** * This {@link RawTypeSet} can be either an reference property or * an element property, and XJC recommends element property. */ SHOULD_BE_TYPEREF(0), /** * This {@link RawTypeSet} can be either an reference property or * an element property, and XJC recommends reference property. */ CAN_BE_TYPEREF(1), /** * This {@link RawTypeSet} can be only bound to a reference property. */ MUST_BE_REFERENCE(2); private final int rank; Mode(int rank) { this.rank = rank; } Mode or(Mode that) { switch(Math.max(this.rank,that.rank)) { case 0: return SHOULD_BE_TYPEREF; case 1: return CAN_BE_TYPEREF; case 2: return MUST_BE_REFERENCE; } throw new AssertionError(); } } /** * Returns true if {@link #refs} can form refs of types. * * If there are multiple {@link Ref}s with the same type, * we cannot make them into type refs. Or if any of the {@link Ref} * says they cannot be in type refs, we cannot do that either. * * TODO: just checking if the refs are the same is not suffice. * If two refs derive from each other, they cannot form a list of refs * (because of a possible ambiguity). */ private Mode canBeTypeRefs() { Set<NType> types = new HashSet Other Java examples (source code examples)Here is a short list of links related to this Java RawTypeSet.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.