use of java.util.EnumSet in project morphia by mongodb.
the class EnumSetConverter method encode.
@Override
@SuppressWarnings("unchecked")
public Object encode(final Object value, final MappedField optionalExtraInfo) {
if (value == null) {
return null;
}
final List values = new ArrayList();
final EnumSet s = (EnumSet) value;
final Object[] array = s.toArray();
for (final Object anArray : array) {
values.add(ec.encode(anArray));
}
return values;
}
use of java.util.EnumSet in project robovm by robovm.
the class ClassCastExceptionTest method testHugeEnumSetAdd.
public void testHugeEnumSetAdd() throws Exception {
EnumSet m = EnumSet.noneOf(HugeE.class);
try {
m.add(HugeF.A0);
fail();
} catch (ClassCastException ex) {
ex.printStackTrace();
assertNotNull(ex.getMessage());
}
}
use of java.util.EnumSet in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method defaultFilterDispatcherTypes.
@Test
public void defaultFilterDispatcherTypes() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
DelegatingFilterProxyRegistrationBean bean = this.context.getBean("securityFilterChainRegistration", DelegatingFilterProxyRegistrationBean.class);
@SuppressWarnings("unchecked") EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils.getField(bean, "dispatcherTypes");
assertThat(dispatcherTypes).containsOnly(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST);
}
use of java.util.EnumSet in project hadoop by apache.
the class HttpFSServer method put.
/**
* Binding to handle PUT requests.
*
* @param is the inputstream for the request payload.
* @param uriInfo the of the request.
* @param path the path for operation.
* @param op the HttpFS operation of the request.
* @param params the HttpFS parameters of the request.
*
* @return the request response.
*
* @throws IOException thrown if an IO error occurred. Thrown exceptions are
* handled by {@link HttpFSExceptionProvider}.
* @throws FileSystemAccessException thrown if a FileSystemAccess releated
* error occurred. Thrown exceptions are handled by
* {@link HttpFSExceptionProvider}.
*/
@PUT
@Path("{path:.*}")
@Consumes({ "*/*" })
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 })
public Response put(InputStream is, @Context UriInfo uriInfo, @PathParam("path") String path, @QueryParam(OperationParam.NAME) OperationParam op, @Context Parameters params, @Context HttpServletRequest request) throws IOException, FileSystemAccessException {
UserGroupInformation user = HttpUserGroupInformation.get();
Response response;
path = makeAbsolute(path);
MDC.put(HttpFSFileSystem.OP_PARAM, op.value().name());
MDC.put("hostname", request.getRemoteAddr());
switch(op.value()) {
case CREATE:
{
Boolean hasData = params.get(DataParam.NAME, DataParam.class);
if (!hasData) {
response = Response.temporaryRedirect(createUploadRedirectionURL(uriInfo, HttpFSFileSystem.Operation.CREATE)).build();
} else {
Short permission = params.get(PermissionParam.NAME, PermissionParam.class);
Boolean override = params.get(OverwriteParam.NAME, OverwriteParam.class);
Short replication = params.get(ReplicationParam.NAME, ReplicationParam.class);
Long blockSize = params.get(BlockSizeParam.NAME, BlockSizeParam.class);
FSOperations.FSCreate command = new FSOperations.FSCreate(is, path, permission, override, replication, blockSize);
fsExecute(user, command);
AUDIT_LOG.info("[{}] permission [{}] override [{}] replication [{}] blockSize [{}]", new Object[] { path, permission, override, replication, blockSize });
response = Response.status(Response.Status.CREATED).build();
}
break;
}
case SETXATTR:
{
String xattrName = params.get(XAttrNameParam.NAME, XAttrNameParam.class);
String xattrValue = params.get(XAttrValueParam.NAME, XAttrValueParam.class);
EnumSet<XAttrSetFlag> flag = params.get(XAttrSetFlagParam.NAME, XAttrSetFlagParam.class);
FSOperations.FSSetXAttr command = new FSOperations.FSSetXAttr(path, xattrName, xattrValue, flag);
fsExecute(user, command);
AUDIT_LOG.info("[{}] to xAttr [{}]", path, xattrName);
response = Response.ok().build();
break;
}
case REMOVEXATTR:
{
String xattrName = params.get(XAttrNameParam.NAME, XAttrNameParam.class);
FSOperations.FSRemoveXAttr command = new FSOperations.FSRemoveXAttr(path, xattrName);
fsExecute(user, command);
AUDIT_LOG.info("[{}] removed xAttr [{}]", path, xattrName);
response = Response.ok().build();
break;
}
case MKDIRS:
{
Short permission = params.get(PermissionParam.NAME, PermissionParam.class);
FSOperations.FSMkdirs command = new FSOperations.FSMkdirs(path, permission);
JSONObject json = fsExecute(user, command);
AUDIT_LOG.info("[{}] permission [{}]", path, permission);
response = Response.ok(json).type(MediaType.APPLICATION_JSON).build();
break;
}
case RENAME:
{
String toPath = params.get(DestinationParam.NAME, DestinationParam.class);
FSOperations.FSRename command = new FSOperations.FSRename(path, toPath);
JSONObject json = fsExecute(user, command);
AUDIT_LOG.info("[{}] to [{}]", path, toPath);
response = Response.ok(json).type(MediaType.APPLICATION_JSON).build();
break;
}
case SETOWNER:
{
String owner = params.get(OwnerParam.NAME, OwnerParam.class);
String group = params.get(GroupParam.NAME, GroupParam.class);
FSOperations.FSSetOwner command = new FSOperations.FSSetOwner(path, owner, group);
fsExecute(user, command);
AUDIT_LOG.info("[{}] to (O/G)[{}]", path, owner + ":" + group);
response = Response.ok().build();
break;
}
case SETPERMISSION:
{
Short permission = params.get(PermissionParam.NAME, PermissionParam.class);
FSOperations.FSSetPermission command = new FSOperations.FSSetPermission(path, permission);
fsExecute(user, command);
AUDIT_LOG.info("[{}] to [{}]", path, permission);
response = Response.ok().build();
break;
}
case SETREPLICATION:
{
Short replication = params.get(ReplicationParam.NAME, ReplicationParam.class);
FSOperations.FSSetReplication command = new FSOperations.FSSetReplication(path, replication);
JSONObject json = fsExecute(user, command);
AUDIT_LOG.info("[{}] to [{}]", path, replication);
response = Response.ok(json).build();
break;
}
case SETTIMES:
{
Long modifiedTime = params.get(ModifiedTimeParam.NAME, ModifiedTimeParam.class);
Long accessTime = params.get(AccessTimeParam.NAME, AccessTimeParam.class);
FSOperations.FSSetTimes command = new FSOperations.FSSetTimes(path, modifiedTime, accessTime);
fsExecute(user, command);
AUDIT_LOG.info("[{}] to (M/A)[{}]", path, modifiedTime + ":" + accessTime);
response = Response.ok().build();
break;
}
case SETACL:
{
String aclSpec = params.get(AclPermissionParam.NAME, AclPermissionParam.class);
FSOperations.FSSetAcl command = new FSOperations.FSSetAcl(path, aclSpec);
fsExecute(user, command);
AUDIT_LOG.info("[{}] to acl [{}]", path, aclSpec);
response = Response.ok().build();
break;
}
case REMOVEACL:
{
FSOperations.FSRemoveAcl command = new FSOperations.FSRemoveAcl(path);
fsExecute(user, command);
AUDIT_LOG.info("[{}] removed acl", path);
response = Response.ok().build();
break;
}
case MODIFYACLENTRIES:
{
String aclSpec = params.get(AclPermissionParam.NAME, AclPermissionParam.class);
FSOperations.FSModifyAclEntries command = new FSOperations.FSModifyAclEntries(path, aclSpec);
fsExecute(user, command);
AUDIT_LOG.info("[{}] modify acl entry with [{}]", path, aclSpec);
response = Response.ok().build();
break;
}
case REMOVEACLENTRIES:
{
String aclSpec = params.get(AclPermissionParam.NAME, AclPermissionParam.class);
FSOperations.FSRemoveAclEntries command = new FSOperations.FSRemoveAclEntries(path, aclSpec);
fsExecute(user, command);
AUDIT_LOG.info("[{}] remove acl entry [{}]", path, aclSpec);
response = Response.ok().build();
break;
}
case REMOVEDEFAULTACL:
{
FSOperations.FSRemoveDefaultAcl command = new FSOperations.FSRemoveDefaultAcl(path);
fsExecute(user, command);
AUDIT_LOG.info("[{}] remove default acl", path);
response = Response.ok().build();
break;
}
case SETSTORAGEPOLICY:
{
String policyName = params.get(PolicyNameParam.NAME, PolicyNameParam.class);
FSOperations.FSSetStoragePolicy command = new FSOperations.FSSetStoragePolicy(path, policyName);
fsExecute(user, command);
AUDIT_LOG.info("[{}] to policy [{}]", path, policyName);
response = Response.ok().build();
break;
}
default:
{
throw new IOException(MessageFormat.format("Invalid HTTP PUT operation [{0}]", op.value()));
}
}
return response;
}
use of java.util.EnumSet in project WordPress-Android by wordpress-mobile.
the class MediaItemFragment method refreshViews.
private void refreshViews(MediaModel mediaModel) {
if (!isAdded() || mediaModel == null) {
return;
}
// check whether or not to show the edit button
String state = mediaModel.getUploadState();
mIsLocal = MediaUtils.isLocalFile(state);
if (mIsLocal && getActivity() != null) {
getActivity().invalidateOptionsMenu();
}
String caption = mediaModel.getCaption();
if (TextUtils.isEmpty(caption)) {
mCaptionView.setVisibility(View.GONE);
} else {
mCaptionView.setText(caption);
mCaptionView.setVisibility(View.VISIBLE);
}
String desc = mediaModel.getDescription();
if (TextUtils.isEmpty(desc)) {
mDescriptionView.setVisibility(View.GONE);
} else {
mDescriptionView.setText(desc);
mDescriptionView.setVisibility(View.VISIBLE);
}
mDateView.setText(mediaModel.getUploadDate());
if (getView() != null) {
TextView txtDateLabel = (TextView) getView().findViewById(R.id.media_listitem_details_date_label);
txtDateLabel.setText(mIsLocal ? R.string.media_details_label_date_added : R.string.media_details_label_date_uploaded);
}
String fileURL = mediaModel.getUrl();
String fileName = mediaModel.getFileName();
mImageUri = TextUtils.isEmpty(fileURL) ? mediaModel.getFilePath() : fileURL;
boolean isValidImage = MediaUtils.isValidImage(mImageUri);
mFileNameView.setText(fileName);
float mediaWidth = mediaModel.getWidth();
float mediaHeight = mediaModel.getHeight();
// image and dimensions
if (isValidImage) {
int screenWidth = DisplayUtils.getDisplayPixelWidth(getActivity());
int screenHeight = DisplayUtils.getDisplayPixelHeight(getActivity());
// determine size for display
int imageWidth;
int imageHeight;
boolean isFullWidth;
if (mediaWidth == 0 || mediaHeight == 0) {
imageWidth = screenWidth;
imageHeight = screenHeight / 2;
isFullWidth = true;
} else if (mediaWidth > mediaHeight) {
float ratio = mediaHeight / mediaWidth;
imageWidth = Math.min(screenWidth, (int) mediaWidth);
imageHeight = (int) (imageWidth * ratio);
isFullWidth = (imageWidth == screenWidth);
} else {
float ratio = mediaWidth / mediaHeight;
imageHeight = Math.min(screenHeight / 2, (int) mediaHeight);
imageWidth = (int) (imageHeight * ratio);
isFullWidth = false;
}
// set the imageView's parent height to match the image so it takes up space while
// the image is loading
FrameLayout frameView = (FrameLayout) getView().findViewById(R.id.layout_image_frame);
frameView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, imageHeight));
// add padding to the frame if the image isn't full-width
if (!isFullWidth) {
int hpadding = getResources().getDimensionPixelSize(R.dimen.content_margin);
int vpadding = getResources().getDimensionPixelSize(R.dimen.margin_extra_large);
frameView.setPadding(hpadding, vpadding, hpadding, vpadding);
}
if (mIsLocal) {
final String filePath = mediaModel.getFilePath();
loadLocalImage(mImageView, filePath, imageWidth, imageHeight);
} else {
// Allow non-private wp.com and Jetpack blogs to use photon to get a higher res thumbnail
String thumbnailURL;
if (SiteUtils.isPhotonCapable(mSite)) {
thumbnailURL = StringUtils.getPhotonUrl(mImageUri, imageWidth);
} else {
thumbnailURL = UrlUtils.removeQuery(mImageUri) + "?w=" + imageWidth;
}
mImageView.setImageUrl(thumbnailURL, WPNetworkImageView.ImageType.PHOTO);
}
} else {
// not an image so show placeholder icon
int placeholderResId = WordPressMediaUtils.getPlaceholder(mImageUri);
mImageView.setDefaultImageResId(placeholderResId);
mImageView.showDefaultImage();
}
// show dimens & file ext together
String dimens = (mediaWidth > 0 && mediaHeight > 0) ? (int) mediaWidth + " x " + (int) mediaHeight : null;
String fileExt = TextUtils.isEmpty(fileURL) ? null : fileURL.replaceAll(".*\\.(\\w+)$", "$1").toUpperCase();
boolean hasDimens = !TextUtils.isEmpty(dimens);
boolean hasExt = !TextUtils.isEmpty(fileExt);
if (hasDimens & hasExt) {
mFileTypeView.setText(fileExt + ", " + dimens);
mFileTypeView.setVisibility(View.VISIBLE);
} else if (hasExt) {
mFileTypeView.setText(fileExt);
mFileTypeView.setVisibility(View.VISIBLE);
} else {
mFileTypeView.setVisibility(View.GONE);
}
// enable fullscreen photo for non-local
if (!mIsLocal && isValidImage) {
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EnumSet<PhotoViewerOption> imageOptions = EnumSet.noneOf(PhotoViewerOption.class);
if (mSite.isPrivate()) {
imageOptions.add(PhotoViewerOption.IS_PRIVATE_IMAGE);
}
ReaderActivityLauncher.showReaderPhotoViewer(v.getContext(), mImageUri, imageOptions);
}
});
}
}
Aggregations