Search in sources :

Example 46 with EnumSet

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;
}
Also used : EnumSet(java.util.EnumSet) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 47 with EnumSet

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());
    }
}
Also used : EnumSet(java.util.EnumSet)

Example 48 with EnumSet

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);
}
Also used : DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean) EnumSet(java.util.EnumSet) DispatcherType(javax.servlet.DispatcherType) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 49 with EnumSet

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;
}
Also used : GroupParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.GroupParam) DataParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.DataParam) ModifiedTimeParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.ModifiedTimeParam) OwnerParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.OwnerParam) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) HttpUserGroupInformation(org.apache.hadoop.security.token.delegation.web.HttpUserGroupInformation) OverwriteParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.OverwriteParam) AccessTimeParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.AccessTimeParam) XAttrNameParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.XAttrNameParam) JSONObject(org.json.simple.JSONObject) PolicyNameParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.PolicyNameParam) JSONObject(org.json.simple.JSONObject) AclPermissionParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.AclPermissionParam) PermissionParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.PermissionParam) BlockSizeParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.BlockSizeParam) XAttrValueParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.XAttrValueParam) XAttrSetFlagParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.XAttrSetFlagParam) AclPermissionParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.AclPermissionParam) EnumSet(java.util.EnumSet) IOException(java.io.IOException) Response(javax.ws.rs.core.Response) ReplicationParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.ReplicationParam) DestinationParam(org.apache.hadoop.fs.http.server.HttpFSParametersProvider.DestinationParam) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 50 with EnumSet

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);
            }
        });
    }
}
Also used : PhotoViewerOption(org.wordpress.android.ui.reader.ReaderActivityLauncher.PhotoViewerOption) EnumSet(java.util.EnumSet) ImageView(android.widget.ImageView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) View(android.view.View) TextView(android.widget.TextView) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

EnumSet (java.util.EnumSet)65 Map (java.util.Map)18 Set (java.util.Set)18 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)12 Test (org.junit.Test)10 TreeSet (java.util.TreeSet)7 Collection (java.util.Collection)6 List (java.util.List)6 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)6 LinkedHashSet (java.util.LinkedHashSet)5 TreeMap (java.util.TreeMap)5 StateStorage.toStringStringSetMap (org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap)5 PathAddress (org.jboss.as.controller.PathAddress)5 PathElement (org.jboss.as.controller.PathElement)5 ModelNode (org.jboss.dmr.ModelNode)5 IOException (java.io.IOException)4 FeatureState (org.apache.karaf.features.FeatureState)4 Collections (java.util.Collections)3