List of usage examples for java.util EnumMap put
public V put(K key, V value)
From source file:org.messic.server.api.dlna.MusicService.java
@Transactional public List<MusicTrack> getSongs(String containerId, long startIndex, long maxCount, VisualContainer vc) { String[] parts = containerId.split(MessicContainer.SEPARATOR); List<MusicTrack> result = new ArrayList<MusicTrack>(); List<MDOSong> songs = null; if (parts.length == 3) { Long sid = Long.valueOf(parts[2]); songs = new ArrayList<MDOSong>(); songs = this.daoalbum.get(sid).getSongs(); } else {/* ww w . j av a 2s .co m*/ songs = this.daosong.getAllDLNA(); } int iadded = 0; for (long i = startIndex; i < startIndex + maxCount && i < songs.size(); i++) { MDOSong song = songs.get((int) i); MDOUser user = song.getOwner(); String token = loginDLNA(user.getLogin(), user.getPassword()); MusicTrack ai = new MusicTrack(); ai.setAlbum(song.getAlbum().getName()); ai.setArtists(new PersonWithRole[] { new PersonWithRole(song.getAlbum().getAuthor().getName()) }); // ai.setCreator( "CreatorRefree" ); ai.setDate("" + song.getAlbum().getYear()); List<DescMeta> listdm = new ArrayList<DescMeta>(); ai.setDescMetadata(listdm); // ai.setDescription( "description" ); // ai.setLanguage( "es_ES" ); // ai.setLongDescription( "long description" ); // ai.setPublishers( new Person[]{new Person( "namepublisher" )} ); ai.setRefID("" + song.getSid()); ai.setRights(new String[] {}); ai.setCreator(song.getAlbum().getAuthor().getName()); ai.setGenres(new String[] { song.getAlbum().getGenre().getName() }); ai.setParentID(song.getOwner().getSid() + MessicContainer.SEPARATOR + song.getAlbum().getAuthor().getSid() + MessicContainer.SEPARATOR + song.getAlbum().getSid()); ai.setId(song.getOwner().getSid() + MessicContainer.SEPARATOR + song.getAlbum().getAuthor().getSid() + MessicContainer.SEPARATOR + song.getAlbum().getSid() + MessicContainer.SEPARATOR + song.getSid()); ai.setTitle(song.getName()); ai.setOriginalTrackNumber(song.getTrack()); 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); } Res resource = new Res(); EnumMap<DLNAAttribute.Type, DLNAAttribute> dlnaAttributes = new EnumMap<DLNAAttribute.Type, DLNAAttribute>( DLNAAttribute.Type.class); 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)); ai.addResource(resource); result.add(ai); if (vc != null) { vc.addItem(ai); } iadded++; } if (vc != null) { vc.setChildCount(iadded); vc.setTotalChildCount(songs.size()); } return result; }
From source file:org.omnaest.utils.structure.map.MapUtils.java
/** * Returns an {@link EnumMap} filled with all available values of the given {@link Enum} type as keys and the result of the * {@link Factory} as value for each {@link Enum} key. * //from w w w . j a v a 2s . co m * @param enumType * @param factory * @return {@link EnumMap} */ public static <K extends Enum<K>, V> EnumMap<K, V> initializedEnumMap(Class<K> enumType, Factory<V> factory) { // final EnumMap<K, V> retmap = enumType != null ? new EnumMap<K, V>(enumType) : null; // if (retmap != null) { for (K key : EnumUtils.getEnumList(enumType)) { V value = factory != null ? factory.newInstance() : null; retmap.put(key, value); } } // return retmap; }
From source file:org.helios.netty.jmx.MetricCollector.java
/** * Collects the number of threads in each thread state * @return an EnumMap with Thread states as the key and the number of threads in that state as the value *//* ww w . j a va 2 s .co m*/ public EnumMap<Thread.State, AtomicInteger> getThreadStates() { EnumMap<Thread.State, AtomicInteger> map = new EnumMap<State, AtomicInteger>(Thread.State.class); for (ThreadInfo ti : threadMxBean.getThreadInfo(threadMxBean.getAllThreadIds())) { State st = ti.getThreadState(); AtomicInteger ai = map.get(st); if (ai == null) { ai = new AtomicInteger(0); map.put(st, ai); } ai.incrementAndGet(); } return map; }
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);// ww w . j av a 2 s . c o m }
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);// www . jav a2 s .c o m @SuppressWarnings("unchecked") final EnumMap<Gender, String> deserialized = deserialize(serialize(map), map.getClass()); assertDeepEquals(deserialized, map); }
From source file:org.openecomp.sdc.be.servlets.AbstractValidationsServlet.java
protected void validateResourceDoesNotExist(Wrapper<Response> responseWrapper, User user, String resourceName) { if (resourceImportManager.isResourceExist(resourceName)) { ResponseFormat responseFormat = getComponentsUtils() .getResponseFormat(ActionStatus.RESOURCE_ALREADY_EXISTS); Response errorResponse = buildErrorResponse(responseFormat); EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>( AuditingFieldsKeysEnum.class); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceName); getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam); responseWrapper.setInnerElement(errorResponse); }/*from w ww . j a v a 2 s . co m*/ }
From source file:org.openecomp.sdc.be.servlets.AbstractValidationsServlet.java
private void validateResourceType(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user) {/* ww w.ja va2s. co m*/ String resourceType = uploadResourceInfo.getResourceType(); if (resourceType == null || !ResourceTypeEnum.contains(resourceType)) { ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT); Response errorResponse = buildErrorResponse(responseFormat); EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>( AuditingFieldsKeysEnum.class); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName()); getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam); responseWrapper.setInnerElement(errorResponse); } }
From source file:org.openecomp.sdc.be.servlets.AbstractValidationsServlet.java
protected void validatePayloadIsYml(Wrapper<Response> responseWrapper, User user, UploadResourceInfo uploadResourceInfo, String toscaTamplatePayload) { log.debug("checking tosca template is valid yml"); YamlToObjectConverter yamlConvertor = new YamlToObjectConverter(); boolean isYamlValid = yamlConvertor.isValidYaml(toscaTamplatePayload.getBytes()); if (!isYamlValid) { ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_YAML_FILE); Response errorResponse = buildErrorResponse(responseFormat); EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>( AuditingFieldsKeysEnum.class); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, uploadResourceInfo.getName()); getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam); responseWrapper.setInnerElement(errorResponse); }/*w w w . j a v a 2 s .c o m*/ }
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 }/*from w ww . ja va2 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.openecomp.sdc.be.servlets.AbstractValidationsServlet.java
protected void fillToscaTemplateFromJson(Wrapper<Response> responseWrapper, Wrapper<String> yamlStringWrapper, User user, UploadResourceInfo resourceInfo) { if (resourceInfo.getPayloadData() == null || resourceInfo.getPayloadData().isEmpty()) { ResponseFormat responseFormat = getComponentsUtils() .getResponseFormat(ActionStatus.INVALID_RESOURCE_PAYLOAD); Response errorResponse = buildErrorResponse(responseFormat); EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>( AuditingFieldsKeysEnum.class); additionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInfo.getName()); getComponentsUtils().auditResource(responseFormat, user, null, "", "", AuditingActionEnum.IMPORT_RESOURCE, additionalParam); responseWrapper.setInnerElement(errorResponse); } else {//from w ww . j a va 2 s .co m String toscaPayload = resourceInfo.getPayloadData(); String decodedPayload = (GeneralUtility.isBase64Encoded(toscaPayload)) ? new String(Base64.decodeBase64(toscaPayload)) : toscaPayload; yamlStringWrapper.setInnerElement(decodedPayload); } }