com.microsoft.azure.storage.SharedAccessAccountService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-storage Show documentation
Show all versions of azure-storage Show documentation
SDK for Microsoft Azure Storage Clients
/**
* Copyright Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.azure.storage;
import java.util.EnumSet;
import com.microsoft.azure.storage.core.SR;
/**
* Specifies the set of possible services for a shared access account policy.
*/
public enum SharedAccessAccountService {
/**
* Permission to access blob resources granted.
*/
BLOB('b'),
/**
* Permission to access file resources granted.
*/
FILE('f'),
/**
* Permission to access queue resources granted.
*/
QUEUE('q'),
/**
* Permission to access table resources granted.
*/
TABLE('t');
char value;
/**
* Create a SharedAccessAccountService
.
*
* @param c
* The char
which represents this service.
*/
private SharedAccessAccountService(char c) {
this.value = c;
}
/**
* Converts the given services to a String
.
*
* @param services
* The services to convert to a String
.
*
* @return A String
which represents the SharedAccessAccountServices
.
*/
static String servicesToString(EnumSet services) {
if (services == null) {
return Constants.EMPTY_STRING;
}
StringBuilder value = new StringBuilder();
for (SharedAccessAccountService service : services) {
value.append(service.value);
}
return value.toString();
}
/**
* Creates an {@link EnumSet} from the specified services string.
*
* @param servicesString
* A String
which represents the SharedAccessAccountServices
.
* @return A {@link EnumSet} generated from the given String
.
*/
static EnumSet servicesFromString(String servicesString) {
EnumSet resources = EnumSet.noneOf(SharedAccessAccountService.class);
for (final char c : servicesString.toLowerCase().toCharArray()) {
boolean invalidCharacter = true;
for (SharedAccessAccountService service : SharedAccessAccountService.values()) {
if (c == service.value) {
resources.add(service);
invalidCharacter = false;
break;
}
}
if (invalidCharacter) {
throw new IllegalArgumentException(
String.format(SR.ENUM_COULD_NOT_BE_PARSED, "Services", servicesString));
}
}
return resources;
}
}