Example usage for java.util EnumMap put

List of usage examples for java.util EnumMap put

Introduction

In this page you can find the example usage for java.util EnumMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:de.javakaffee.kryoserializers.KryoTest.java

@Test
public void testCopyEnumMap() throws Exception {
    final EnumMap<Gender, String> map = new EnumMap<Gender, String>(Gender.class);
    final String value = "foo";
    map.put(Gender.FEMALE, value);
    final EnumMap<Gender, String> copy = _kryo.copy(map);
    assertDeepEquals(copy, map);/*from www  .  j a v  a2 s.com*/
}

From source file:de.javakaffee.kryoserializers.KryoTest.java

@Test(enabled = true)
public void testEnumMap() throws Exception {
    final EnumMap<Gender, String> map = new EnumMap<Gender, String>(Gender.class);
    final String value = "foo";
    map.put(Gender.FEMALE, value);
    // Another entry with the same value - to check reference handling
    map.put(Gender.MALE, value);//w ww. ja  va 2  s . c o m
    @SuppressWarnings("unchecked")
    final EnumMap<Gender, String> deserialized = deserialize(serialize(map), map.getClass());
    assertDeepEquals(deserialized, map);
}

From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedPost.java

public VerticalToolbar generateToolbar(final Context context, final Fragment fragmentParent,
        final SideToolbarOverlay overlay) {

    final VerticalToolbar toolbar = new VerticalToolbar(context);
    final EnumSet<Action> itemsPref = PrefsUtility.pref_menus_post_toolbar_items(context,
            PreferenceManager.getDefaultSharedPreferences(context));

    final Action[] possibleItems = { Action.ACTION_MENU,
            fragmentParent instanceof CommentListingFragment ? Action.LINK_SWITCH : Action.COMMENTS_SWITCH,
            Action.UPVOTE, Action.DOWNVOTE, Action.SAVE, Action.HIDE, Action.REPLY, Action.EXTERNAL,
            Action.SAVE_IMAGE, Action.SHARE, Action.COPY, Action.USER_PROFILE, Action.PROPERTIES };

    // TODO make static
    final EnumMap<Action, Integer> iconsDark = new EnumMap<Action, Integer>(Action.class);
    iconsDark.put(Action.ACTION_MENU, R.drawable.ic_action_overflow);
    iconsDark.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_dark);
    iconsDark.put(Action.LINK_SWITCH,
            imageUrl != null ? R.drawable.ic_action_image_dark : R.drawable.ic_action_page_dark);
    iconsDark.put(Action.UPVOTE, R.drawable.action_upvote_dark);
    iconsDark.put(Action.DOWNVOTE, R.drawable.action_downvote_dark);
    iconsDark.put(Action.SAVE, R.drawable.ic_action_star_filled_dark);
    iconsDark.put(Action.HIDE, R.drawable.ic_action_cross_dark);
    iconsDark.put(Action.REPLY, R.drawable.ic_action_reply_dark);
    iconsDark.put(Action.EXTERNAL, R.drawable.ic_action_globe_dark);
    iconsDark.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_dark);
    iconsDark.put(Action.SHARE, R.drawable.ic_action_share_dark);
    iconsDark.put(Action.COPY, R.drawable.ic_action_copy_dark);
    iconsDark.put(Action.USER_PROFILE, R.drawable.ic_action_person_dark);
    iconsDark.put(Action.PROPERTIES, R.drawable.ic_action_info_dark);

    final EnumMap<Action, Integer> iconsLight = new EnumMap<Action, Integer>(Action.class);
    iconsLight.put(Action.ACTION_MENU, R.drawable.ic_action_overflow);
    iconsLight.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_light);
    iconsLight.put(Action.LINK_SWITCH,
            imageUrl != null ? R.drawable.ic_action_image_light : R.drawable.ic_action_page_light);
    iconsLight.put(Action.UPVOTE, R.drawable.action_upvote_light);
    iconsLight.put(Action.DOWNVOTE, R.drawable.action_downvote_light);
    iconsLight.put(Action.SAVE, R.drawable.ic_action_star_filled_light);
    iconsLight.put(Action.HIDE, R.drawable.ic_action_cross_light);
    iconsLight.put(Action.REPLY, R.drawable.ic_action_reply_light);
    iconsLight.put(Action.EXTERNAL, R.drawable.ic_action_globe_light);
    iconsLight.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_light);
    iconsLight.put(Action.SHARE, R.drawable.ic_action_share_light);
    iconsLight.put(Action.COPY, R.drawable.ic_action_copy_light);
    iconsLight.put(Action.USER_PROFILE, R.drawable.ic_action_person_light);
    iconsLight.put(Action.PROPERTIES, R.drawable.ic_action_info_light);

    for (final Action action : possibleItems) {

        if (action == Action.SAVE_IMAGE && imageUrl == null)
            continue;

        if (itemsPref.contains(action)) {

            final FlatImageButton ib = new FlatImageButton(context);

            final int buttonPadding = General.dpToPixels(context, 10);
            ib.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding);

            if (action == Action.UPVOTE && isUpvoted() || action == Action.DOWNVOTE && isDownvoted()
                    || action == Action.SAVE && isSaved() || action == Action.HIDE && isHidden()) {

                ib.setBackgroundColor(Color.WHITE);
                ib.setImageResource(iconsLight.get(action));

            } else {
                ib.setImageResource(iconsDark.get(action));
                // TODO highlight on click
            }//  www  .j a v a  2  s . c o  m

            ib.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {

                    final Action actionToTake;

                    switch (action) {
                    case UPVOTE:
                        actionToTake = isUpvoted() ? Action.UNVOTE : Action.UPVOTE;
                        break;

                    case DOWNVOTE:
                        actionToTake = isDownvoted() ? Action.UNVOTE : Action.DOWNVOTE;
                        break;

                    case SAVE:
                        actionToTake = isSaved() ? Action.UNSAVE : Action.SAVE;
                        break;

                    case HIDE:
                        actionToTake = isHidden() ? Action.UNHIDE : Action.HIDE;
                        break;

                    default:
                        actionToTake = action;
                        break;
                    }

                    onActionMenuItemSelected(RedditPreparedPost.this, fragmentParent, actionToTake);
                    overlay.hide();
                }
            });

            toolbar.addItem(ib);
        }
    }

    return toolbar;
}

From source file:org.lol.reddit.reddit.prepared.RedditPreparedPost.java

public VerticalToolbar generateToolbar(final Activity activity, boolean isComments,
        final SideToolbarOverlay overlay) {

    final VerticalToolbar toolbar = new VerticalToolbar(activity);
    final EnumSet<Action> itemsPref = PrefsUtility.pref_menus_post_toolbar_items(activity,
            PreferenceManager.getDefaultSharedPreferences(activity));

    final Action[] possibleItems = { Action.ACTION_MENU,
            isComments ? Action.LINK_SWITCH : Action.COMMENTS_SWITCH, Action.UPVOTE, Action.DOWNVOTE,
            Action.SAVE, Action.HIDE, Action.REPLY, Action.EXTERNAL, Action.SAVE_IMAGE, Action.SHARE,
            Action.COPY, Action.USER_PROFILE, Action.PROPERTIES };

    // TODO make static
    final EnumMap<Action, Integer> iconsDark = new EnumMap<Action, Integer>(Action.class);
    iconsDark.put(Action.ACTION_MENU, R.drawable.ic_action_overflow);
    iconsDark.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_dark);
    iconsDark.put(Action.LINK_SWITCH,
            imageUrl != null ? R.drawable.ic_action_image_dark : R.drawable.ic_action_page_dark);
    iconsDark.put(Action.UPVOTE, R.drawable.action_upvote_dark);
    iconsDark.put(Action.DOWNVOTE, R.drawable.action_downvote_dark);
    iconsDark.put(Action.SAVE, R.drawable.ic_action_star_filled_dark);
    iconsDark.put(Action.HIDE, R.drawable.ic_action_cross_dark);
    iconsDark.put(Action.REPLY, R.drawable.ic_action_reply_dark);
    iconsDark.put(Action.EXTERNAL, R.drawable.ic_action_globe_dark);
    iconsDark.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_dark);
    iconsDark.put(Action.SHARE, R.drawable.ic_action_share_dark);
    iconsDark.put(Action.COPY, R.drawable.ic_action_copy_dark);
    iconsDark.put(Action.USER_PROFILE, R.drawable.ic_action_person_dark);
    iconsDark.put(Action.PROPERTIES, R.drawable.ic_action_info_dark);

    final EnumMap<Action, Integer> iconsLight = new EnumMap<Action, Integer>(Action.class);
    iconsLight.put(Action.ACTION_MENU, R.drawable.ic_action_overflow);
    iconsLight.put(Action.COMMENTS_SWITCH, R.drawable.ic_action_comments_light);
    iconsLight.put(Action.LINK_SWITCH,
            imageUrl != null ? R.drawable.ic_action_image_light : R.drawable.ic_action_page_light);
    iconsLight.put(Action.UPVOTE, R.drawable.action_upvote_light);
    iconsLight.put(Action.DOWNVOTE, R.drawable.action_downvote_light);
    iconsLight.put(Action.SAVE, R.drawable.ic_action_star_filled_light);
    iconsLight.put(Action.HIDE, R.drawable.ic_action_cross_light);
    iconsLight.put(Action.REPLY, R.drawable.ic_action_reply_light);
    iconsLight.put(Action.EXTERNAL, R.drawable.ic_action_globe_light);
    iconsLight.put(Action.SAVE_IMAGE, R.drawable.ic_action_save_light);
    iconsLight.put(Action.SHARE, R.drawable.ic_action_share_light);
    iconsLight.put(Action.COPY, R.drawable.ic_action_copy_light);
    iconsLight.put(Action.USER_PROFILE, R.drawable.ic_action_person_light);
    iconsLight.put(Action.PROPERTIES, R.drawable.ic_action_info_light);

    for (final Action action : possibleItems) {

        if (action == Action.SAVE_IMAGE && imageUrl == null)
            continue;

        if (itemsPref.contains(action)) {

            final FlatImageButton ib = new FlatImageButton(activity);

            final int buttonPadding = General.dpToPixels(activity, 10);
            ib.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding);

            if (action == Action.UPVOTE && isUpvoted() || action == Action.DOWNVOTE && isDownvoted()
                    || action == Action.SAVE && isSaved() || action == Action.HIDE && isHidden()) {

                ib.setBackgroundColor(Color.WHITE);
                ib.setImageResource(iconsLight.get(action));

            } else {
                ib.setImageResource(iconsDark.get(action));
                // TODO highlight on click
            }/*from   ww  w  . j  ava  2  s . c  om*/

            ib.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {

                    final Action actionToTake;

                    switch (action) {
                    case UPVOTE:
                        actionToTake = isUpvoted() ? Action.UNVOTE : Action.UPVOTE;
                        break;

                    case DOWNVOTE:
                        actionToTake = isDownvoted() ? Action.UNVOTE : Action.DOWNVOTE;
                        break;

                    case SAVE:
                        actionToTake = isSaved() ? Action.UNSAVE : Action.SAVE;
                        break;

                    case HIDE:
                        actionToTake = isHidden() ? Action.UNHIDE : Action.HIDE;
                        break;

                    default:
                        actionToTake = action;
                        break;
                    }

                    onActionMenuItemSelected(RedditPreparedPost.this, activity, actionToTake);
                    overlay.hide();
                }
            });

            toolbar.addItem(ib);
        }
    }

    return toolbar;
}

From source file:org.messic.server.api.dlna.MusicService.java

@Transactional
public List<PlaylistItem> getPlaylists(String containerId, long startIndex, long maxCount, VisualContainer vc) {
    List<PlaylistItem> result = new ArrayList<PlaylistItem>();
    List<MDOPlaylist> playlists = this.daoPlaylist.getAllDLNA();

    for (long i = startIndex; i < startIndex + maxCount && i < playlists.size(); i++) {
        MDOPlaylist mdop = playlists.get((int) i);

        HashMap<MDOAuthor, String> authors = new HashMap<MDOAuthor, String>();
        List<MDOSong> songs = mdop.getSongs();
        for (int j = 0; j < songs.size(); j++) {
            MDOSong song = songs.get(j);
            authors.put(song.getAlbum().getAuthor(), "");
        }//from   w ww  .java 2 s  .  co m

        PlaylistItem pli = new PlaylistItem();
        pli.setTitle(mdop.getName());
        pli.setDescription(mdop.getName());
        pli.setLongDescription(mdop.getName());
        pli.setDate("24/01/2013");
        MDOAuthor[] mdoauthors = new MDOAuthor[authors.size()];
        authors.keySet().toArray(mdoauthors);
        PersonWithRole[] persons = new PersonWithRole[mdoauthors.length];
        for (int k = 0; k < mdoauthors.length; k++) {
            MDOAuthor mdoa = mdoauthors[k];
            PersonWithRole pwr = new PersonWithRole(mdoa.getName());
            persons[k] = pwr;
        }
        pli.setArtists(persons);

        pli.setParentID(mdop.getOwner().getSid() + "");
        pli.setId(mdop.getOwner().getSid() + MessicContainer.SEPARATOR);

        for (int l = 0; l < mdop.getSongs().size(); l++) {
            MDOSong song = mdop.getSongs().get(l);

            MDOUser user = song.getOwner();
            String token = loginDLNA(user.getLogin(), user.getPassword());

            Res resource = new Res();
            EnumMap<DLNAAttribute.Type, DLNAAttribute> dlnaAttributes = new EnumMap<DLNAAttribute.Type, DLNAAttribute>(
                    DLNAAttribute.Type.class);

            URI originalUri = null;
            try {
                originalUri = new URI(
                        (isSecured() ? "https" : "http") + "://" + Util.getInternalIp() + ":" + getCurrentPort()
                                + "/messic/services/songs/" + song.getSid() + "/dlna?messic_token=" + token);
            } catch (URISyntaxException e) {
                log.error("failed!", e);
            } catch (Exception e) {
                log.error("failed!", e);
            }
            resource.setValue(originalUri.toString());
            DLNAProfiles originalProfile = DLNAProfiles.MP3;
            dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_PN, new DLNAProfileAttribute(originalProfile));
            dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_OP,
                    new DLNAOperationsAttribute(DLNAOperations.RANGE));
            dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_CI,
                    new DLNAConversionIndicatorAttribute(DLNAConversionIndicator.NONE));
            dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_FLAGS,
                    new DLNAFlagsAttribute(DLNAFlags.STREAMING_TRANSFER_MODE,
                            DLNAFlags.BACKGROUND_TRANSFERT_MODE, DLNAFlags.DLNA_V15));

            resource.setProtocolInfo(new DLNAProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, "audio/mp3",
                    dlnaAttributes));

            pli.addResource(resource);

        }

        result.add(pli);
    }
    return result;
}

From source file:tasly.greathealth.oms.web.inventory.rest.resources.ItemInfoResource.java

@SuppressWarnings("null")
@PUT//from   w ww.  j av  a  2  s  .c  o  m
@Path("/flag0skus")
public Response updateFlagSku(final SkuList skuList) throws Exception {
    int flag;
    EnumMap<HandleReturn, Object> handleReturn = new EnumMap<HandleReturn, Object>(HandleReturn.class);
    boolean updateStatus = false;
    final List<String> skus = skuList.getSkus();
    if (skus.size() > 0 || skus != null) {
        for (final String sku : skus) {
            final ItemInfo itemInfo = itemInfoFacade.getBySku(sku);
            flag = itemInfo.getStockManageFlag();
            if (flag == 0) {
                final List<TaslyItemLocationData> checkTaslyItemLocationDatas = taslyItemLocationService
                        .getByItemID(sku);
                if (checkTaslyItemLocationDatas == null || checkTaslyItemLocationDatas.size() == 0) {
                    omsLOG.error("sku:" + sku + ",no ItemLocation data!");
                    continue;
                } else {
                    try {

                        handleReturn = itemQuantityService.handleUpdateMethod(checkTaslyItemLocationDatas, sku,
                                flag, 0);
                    } catch (final Exception e) {
                        omsLOG.error("handle sku:" + sku + " failed and error is " + e);
                        handleReturn.put(HandleReturn.handleStatus, false);
                    }
                    if ((boolean) handleReturn.get(HandleReturn.handleStatus)) {
                        try {
                            updateStatus = itemQuantityService.updateMethod(sku, flag, 0);
                            if (updateStatus) {
                                omsLOG.debug("sku:" + sku + ",flag=0 allocated ok!");
                            }
                        } catch (final Exception e) {
                            omsLOG.error("update sku:" + sku + " failed and error is " + e);
                        }
                    }
                }
            }
        }
        omsLOG.info("Update quantity where flag=0 finished.");
    }
    return Response.status(Response.Status.OK).build();
}

From source file:gov.nih.nci.caarray.web.action.project.ProjectFilesAction.java

/**
 * Computes a file status count for each type of file status.
 *
 * @return Map, map contains key value pair (status, count)
 *//* w  w w . j a  va 2s.c om*/
public EnumMap<FileStatus, Integer> computeFileStatusCounts() {
    final EnumMap<FileStatus, Integer> countMap = new EnumMap<FileStatus, Integer>(FileStatus.class);

    for (final FileStatus f : FileStatus.values()) {
        countMap.put(f, 0);
    }

    for (final CaArrayFile f : getFiles()) {
        countMap.put(FileStatus.valueOf(f.getStatus()), countMap.get(FileStatus.valueOf(f.getStatus())) + 1);
    }
    return countMap;
}

From source file:tasly.greathealth.oms.web.inventory.rest.resources.ItemInfoResource.java

@SuppressWarnings("null")
@GET//  w  w  w. j  av a2 s.co m
@Path("/flag0update")
public Response updateQuantity() {
    omsLOG.info("Begin to update quantity where flag=0.");
    final Collection<ItemInfo> itemInfos = itemInfoFacade.getAll();
    int flag;
    String sku;
    EnumMap<HandleReturn, Object> handleReturn = new EnumMap<HandleReturn, Object>(HandleReturn.class);
    boolean updateStatus = false;
    if (itemInfos.size() == 0 || itemInfos == null) {
        omsLOG.error("Get all itemInfos failed!");
    } else {
        for (final ItemInfo itemInfo : itemInfos) {
            flag = itemInfo.getStockManageFlag();
            sku = itemInfo.getSku();
            if (flag == 0) {
                final List<TaslyItemLocationData> checkTaslyItemLocationDatas = taslyItemLocationService
                        .getByItemID(sku);
                if (checkTaslyItemLocationDatas == null || checkTaslyItemLocationDatas.size() == 0) {
                    omsLOG.error("sku:" + sku + ",no ItemLocation data!");
                    continue;
                } else {
                    try {
                        handleReturn = itemQuantityService.handleUpdateMethod(checkTaslyItemLocationDatas, sku,
                                flag, 0);
                    } catch (final Exception e) {
                        omsLOG.error("handle sku:" + sku + " failed and error is " + e);
                        handleReturn.put(HandleReturn.handleStatus, false);
                    }
                    if ((boolean) handleReturn.get(HandleReturn.handleStatus)) {
                        try {
                            updateStatus = itemQuantityService.updateMethod(sku, flag, 0);
                            if (updateStatus) {
                                omsLOG.debug("sku:" + sku + ",flag=0 allocated ok!");
                            }
                        } catch (final Exception e) {
                            omsLOG.error("update sku:" + sku + " failed and error is " + e);
                        }
                    }
                }
            }
        }
    }
    omsLOG.info("Update quantity where flag=0 finished.");
    return Response.status(Response.Status.OK).build();
}

From source file:com.gemstone.gemfire.cache.hdfs.internal.hoplog.HdfsSortedOplogOrganizer.java

/**
 * store cardinality information in metadata
 * @param localHLL the hll estimate for this hoplog only
 *///from  w  w  w. ja v a 2 s. c om
private EnumMap<Meta, byte[]> buildMetaData(ICardinality localHLL) throws IOException {
    EnumMap<Meta, byte[]> map = new EnumMap<Hoplog.Meta, byte[]>(Meta.class);
    map.put(Meta.LOCAL_CARDINALITY_ESTIMATE_V2, localHLL.getBytes());
    return map;
}

From source file:tasly.greathealth.oms.inventory.facades.DefaultItemQuantityFacade.java

@Override
public boolean updateItemQuantity() {
    EnumMap<HandleReturn, Object> handleReturn = new EnumMap<HandleReturn, Object>(HandleReturn.class);
    boolean updateStatus = true;
    final List<String> errorSkus = new ArrayList<>();
    final List<ItemInfoData> itemInfoDatas = itemInfoService.getAll();
    if (itemInfoDatas != null && itemInfoDatas.size() > 0) {
        for (int i = 0; i < itemInfoDatas.size(); i++) {
            final String sku = itemInfoDatas.get(i).getSku();
            final int totalNumber = itemInfoDatas.get(i).getQuantity();
            final int flag = itemInfoDatas.get(i).getStockManageFlag();

            final Date nowDay = new Date();
            final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssZ");
            final String nowDate = sdf.format(nowDay);
            final String nowDateString = nowDate.substring(0, 8);
            final String modifyDay = itemInfoDatas.get(i).getExt1();
            String modifyDayString = null;
            if (StringUtils.isEmpty(modifyDay)) {
                modifyDayString = "";
            } else {
                modifyDayString = modifyDay.substring(0, 8);
            }//from  w  ww  .  ja va2s  . c  o m
            if ("".equals(modifyDayString) || nowDateString.equals(modifyDayString) || flag == 0) {
                final List<TaslyItemLocationData> checkTaslyItemLocationDatas = taslyItemLocationService
                        .getByItemID(sku);
                if (checkTaslyItemLocationDatas == null || checkTaslyItemLocationDatas.size() == 0) {
                    omsLOG.error("sku:" + sku + ",no ItemLocation data!");
                    continue;
                } else {
                    try {
                        handleReturn = itemQuantityService.handleUpdateMethod(checkTaslyItemLocationDatas, sku,
                                flag, totalNumber);
                    } catch (final Exception e) {
                        omsLOG.error("handle sku:" + sku + " failed and error is " + e);
                        handleReturn.put(HandleReturn.handleStatus, false);
                    }
                    if ((boolean) handleReturn.get(HandleReturn.handleStatus)) {
                        if ((boolean) handleReturn.get(HandleReturn.errorStatus)) {
                            errorSkus.add(sku);
                        }
                        try {
                            updateStatus = itemQuantityService.updateMethod(sku, flag,
                                    (int) handleReturn.get(HandleReturn.availableNumber));
                            if (flag == 0 && updateStatus) {
                                omsLOG.debug("sku:" + sku + ",flag=0 allocated ok!");
                            } else if (flag == 1 && updateStatus) {
                                omsLOG.debug("sku:" + sku + ",flag=1 allocated ok!");
                            }
                        } catch (final Exception e) {
                            omsLOG.error("update sku:" + sku + " failed and error is " + e);
                        }
                    } else {
                        continue;
                    }
                }
            } else if (!nowDateString.equals(modifyDayString) && flag == 1) {
                omsLOG.error("sku:" + sku + ",modifyTime:" + modifyDayString + ",nowday:" + nowDateString
                        + ".The modifyTime not equal currentdate,current sku skip allocated");
                continue;
            }
        }
        if (errorSkus.size() > 0) {
            final StringBuffer skulist = new StringBuffer();
            for (final String errorSku : errorSkus) {
                skulist.append(errorSku + ",");
            }
            omsSkuLog.error("???SKU" + skulist.toString());
        }
        return true;
    } else {
        omsLOG.error("get iteminfos failed!");
        return false;
    }
}