下面列出了java.util.EnumSet#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static <E extends Enum<E> & Flags> List<String> toStringList(
Class<E> enumClass,
long rscFlags
)
{
EnumSet<E> values = EnumSet.allOf(enumClass);
List<String> strList = new ArrayList<>(values.size());
for (E en : values)
{
if ((rscFlags & en.getFlagValue()) == en.getFlagValue())
{
strList.add(en.toString());
}
}
return strList;
}
@Override
public void onSaveEvent(EnumSet selectedDays, TimeOfDay timeOfDay) {
int selectedHour = timeOfDay.getHours();
int selectedMinute = timeOfDay.getMinutes();
if(selectedDays.size() > 1 && isEditMode()) {
confirmUpdateAllDays(selectedDays, selectedHour, selectedMinute);
}
else {
saveEvent(selectedDays, selectedHour, selectedMinute, false);
}
}
/**
* Assert that the current lexeme matches one of the types in the specified
* set. If it does not match, then throw an exception.
*
* @param types An set containing a collection of types to match against
*/
public void assertTypeInSet(EnumSet<T> types) {
if (!isInTypeSet(types)) {
List<String> typeNames = new ArrayList<String>(types.size());
for (Enum<T> s : types) {
typeNames.add(s.toString());
}
errorWithMessage("Expected a token of one of these types: " + typeNames);
}
}
/**
* Constructs a request to return a listing of all shares in this storage account. Sign with no length
* specified.
*
* @param uri
* A <code>java.net.URI</code> object that specifies the absolute URI.
* @param fileOptions
* A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout
* settings for the operation. Specify <code>null</code> to use the request options specified on the
* {@link CloudFileClient}.
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. This object
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
* @param listingContext
* A set of parameters for the listing operation.
* @param detailsIncluded
* A <code>java.util.EnumSet</code> object that contains {@link ShareListingDetails} values that indicate
* whether share snapshots and/or metadata will be returned.
* @return a HttpURLConnection configured for the operation.
* @throws IOException
* @throws URISyntaxException
* @throws StorageException
* @throws IllegalArgumentException
*/
public static HttpURLConnection listShares(final URI uri, final FileRequestOptions fileOptions,
final OperationContext opContext, final ListingContext listingContext,
final EnumSet<ShareListingDetails> detailsIncluded) throws URISyntaxException, IOException, StorageException {
final UriQueryBuilder builder = BaseRequest.getListUriQueryBuilder(listingContext);
if (detailsIncluded != null && detailsIncluded.size() > 0) {
final StringBuilder sb = new StringBuilder();
boolean started = false;
if (detailsIncluded.contains(ShareListingDetails.SNAPSHOTS)) {
started = true;
sb.append(SNAPSHOTS_QUERY_ELEMENT_NAME);
}
if (detailsIncluded.contains(ShareListingDetails.METADATA)) {
if (started)
{
sb.append(",");
}
sb.append(Constants.QueryConstants.METADATA);
}
builder.add(Constants.QueryConstants.INCLUDE, sb.toString());
}
final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);
request.setRequestMethod(Constants.HTTP_GET);
return request;
}
protected void parseDiscoveryOptionProperty(XMLExtendedStreamReader reader, ModelNode discoveryOptionProperties) throws XMLStreamException {
String propertyName = null;
String propertyValue = null;
EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
propertyName = value;
break;
}
case VALUE: {
propertyValue = value;
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}
if (required.size() > 0) {
throw missingRequired(reader, required);
}
discoveryOptionProperties.add(propertyName, propertyValue);
requireNoContent(reader);
}
public static String enumSetToString(EnumSet<ArticleChangeType> enumSet) {
if(enumSet.isEmpty()) return "";
if(enumSet.size() == 1) return enumSet.iterator().next().name();
Iterator<ArticleChangeType> it = enumSet.iterator();
StringBuilder sb = new StringBuilder(it.next().name());
while(it.hasNext()) {
sb.append(STRING_DELIMITER).append(it.next().name());
}
return sb.toString();
}
@SuppressWarnings("rawtypes") // necessary to compile against Java 8
static ImmutableSet asImmutable(EnumSet set) {
switch (set.size()) {
case 0:
return ImmutableSet.of();
case 1:
return ImmutableSet.of(Iterables.getOnlyElement(set));
default:
return new ImmutableEnumSet(set);
}
}
private void parseDiscoveryOptionProperty(XMLExtendedStreamReader reader, ModelNode discoveryOptionProperties) throws XMLStreamException {
String propertyName = null;
String propertyValue = null;
EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
propertyName = value;
break;
}
case VALUE: {
propertyValue = value;
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}
if (required.size() > 0) {
throw missingRequired(reader, required);
}
discoveryOptionProperties.add(propertyName, propertyValue);
requireNoContent(reader);
}
private static <T extends Enum<T>> Map<String, T> extractStringMap(Class<T> type) {
checkType(type);
EnumSet<T> values = EnumSet.allOf(type);
Map<String, T> strings = new HashMap<String, T>(values.size());
for (T value : values) {
if (strings.put(value.toString(), value) != null) {
throw new InitializationException("Enum type "
+ type.getName()
+ " does not have unique string representations for its values");
}
}
return strings;
}
protected void parseDiscoveryOptionProperty(XMLExtendedStreamReader reader, ModelNode discoveryOptionProperties) throws XMLStreamException {
String propertyName = null;
String propertyValue = null;
EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
propertyName = value;
break;
}
case VALUE: {
propertyValue = value;
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}
if (required.size() > 0) {
throw missingRequired(reader, required);
}
discoveryOptionProperties.add(propertyName, propertyValue);
requireNoContent(reader);
}
@SuppressWarnings("rawtypes") // necessary to compile against Java 8
static ImmutableSet asImmutable(EnumSet set) {
switch (set.size()) {
case 0:
return ImmutableSet.of();
case 1:
return ImmutableSet.of(Iterables.getOnlyElement(set));
default:
return new ImmutableEnumSet(set);
}
}
protected void parseDiscoveryOptionProperty(XMLExtendedStreamReader reader, ModelNode discoveryOptionProperties) throws XMLStreamException {
String propertyName = null;
String propertyValue = null;
EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
propertyName = value;
break;
}
case VALUE: {
propertyValue = value;
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}
if (required.size() > 0) {
throw missingRequired(reader, required);
}
discoveryOptionProperties.add(propertyName, propertyValue);
requireNoContent(reader);
}
/**
* Converts a TestDoc enum set into a collection of revisions
*
* @param testDocs set of TestDoc revisions in ascending order
* @return
*/
private List<DocumentRevision> toRevisionCollection(EnumSet<TestDoc> testDocs) {
List<DocumentRevision> revisions = new ArrayList<DocumentRevision>(testDocs.size());
for (TestDoc testDoc : testDocs) {
revisions.add(testDoc.revision);
}
return revisions;
}
private void parseModuleOption(XMLExtendedStreamReader reader, ModelNode moduleOptions) throws XMLStreamException {
String name = null;
String val = null;
EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
name = value;
break;
}
case VALUE: {
val = value;
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}
if (required.size() > 0) {
throw missingRequired(reader, required);
}
moduleOptions.add(name, val);
requireNoContent(reader);
}
protected void parseDiscoveryOptionProperty(XMLExtendedStreamReader reader, ModelNode discoveryOptionProperties) throws XMLStreamException {
String propertyName = null;
String propertyValue = null;
EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
propertyName = value;
break;
}
case VALUE: {
propertyValue = value;
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}
if (required.size() > 0) {
throw missingRequired(reader, required);
}
discoveryOptionProperties.add(propertyName, propertyValue);
requireNoContent(reader);
}
protected void parseDiscoveryOptionProperty(XMLExtendedStreamReader reader, ModelNode discoveryOptionProperties) throws XMLStreamException {
String propertyName = null;
String propertyValue = null;
EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.VALUE);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME: {
propertyName = value;
break;
}
case VALUE: {
propertyValue = value;
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}
if (required.size() > 0) {
throw missingRequired(reader, required);
}
discoveryOptionProperties.add(propertyName, propertyValue);
requireNoContent(reader);
}
@Override
public String[] getRoutingTypes() {
if (AuditLogger.isEnabled()) {
AuditLogger.getRoutingTypes(this.addressInfo);
}
EnumSet<RoutingType> routingTypes = addressInfo.getRoutingTypes();
String[] result = new String[routingTypes.size()];
int i = 0;
for (RoutingType routingType : routingTypes) {
result[i++] = routingType.toString();
}
return result;
}
@JsonProperty(PROP_BGP_RANKING)
public void setBgpRanking(List<BgpDecisionVariable> r) {
EnumSet<BgpDecisionVariable> rset = EnumSet.noneOf(BgpDecisionVariable.class);
rset.addAll(r);
if (rset.size() != r.size()) {
throw new BatfishException("Duplicate BGP decision variable in question");
}
_bgpRanking = r;
}
private void before(final String enabledEvents, final EnumSet<DriverEventCode> expectedEvents)
{
System.setProperty(EventLogAgent.READER_CLASSNAME_PROP_NAME, StubEventLogReaderAgent.class.getName());
System.setProperty(EventConfiguration.ENABLED_EVENT_CODES_PROP_NAME, enabledEvents);
AgentTests.beforeAgent();
latch = new CountDownLatch(expectedEvents.size());
WAIT_LIST.addAll(expectedEvents.stream().map(DriverEventCode::id).collect(toSet()));
testDir = Paths.get(IoUtil.tmpDirName(), "driver-test").toFile();
if (testDir.exists())
{
IoUtil.delete(testDir, false);
}
}
/**
* reset the EnumSetWritable with specified
* <tt>value</value> and <tt>elementType</tt>. If the <tt>value</tt> argument
* is null or its size is zero, the <tt>elementType</tt> argument must not be
* null. If the argument <tt>value</tt>'s size is bigger than zero, the
* argument <tt>elementType</tt> is not be used.
*
* @param value
* @param elementType
*/
public void set(EnumSet<E> value, Class<E> elementType) {
if ((value == null || value.size() == 0)
&& (this.elementType == null && elementType == null)) {
throw new IllegalArgumentException(
"The EnumSet argument is null, or is an empty set but with no elementType provided.");
}
this.value = value;
if (value != null && value.size() > 0) {
Iterator<E> iterator = value.iterator();
this.elementType = iterator.next().getDeclaringClass();
} else if (elementType != null) {
this.elementType = elementType;
}
}