List of usage examples for java.util EnumSet copyOf
public static <E extends Enum<E>> EnumSet<E> copyOf(Collection<E> c)
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDao.java
/** * {@inheritDoc}//from w ww .j a v a 2 s .c o m */ @Override public void deleteFile(final Serializable fileId, final String versionMessage) { if (isKioskEnabled()) { throw new RuntimeException( Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED")); //$NON-NLS-1$ } Assert.notNull(fileId); jcrTemplate.execute(new JcrCallback() { @Override public Object doInJcr(final Session session) throws RepositoryException, IOException { RepositoryFile fileToBeDeleted = getFileById(fileId); // Get repository file info and acl info of parent if (fileToBeDeleted != null) { RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl(fileToBeDeleted.getId()); // Invoke accessVoterManager to see if we have access to perform this operation if (!accessVoterManager.hasAccess(fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl, PentahoSessionHolder.getSession())) { return null; } } List<RepositoryFilePermission> perms = new ArrayList<RepositoryFilePermission>(); perms.add(RepositoryFilePermission.DELETE); if (!aclDao.hasAccess(fileToBeDeleted.getPath(), EnumSet.copyOf(perms))) { throw new AccessDeniedException(Messages.getInstance() .getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED_DELETE", fileId)); } PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); Serializable parentFolderId = JcrRepositoryFileUtils.getParentId(session, fileId); JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId); deleteHelper.deleteFile(session, pentahoJcrConstants, fileId); session.save(); JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId, versionMessage); return null; } }); }
From source file:org.apache.hadoop.yarn.server.timeline.RollingLevelDBTimelineStore.java
/** * Retrieves a list of entities satisfying given parameters. * * @param base//w w w . j a v a 2 s . c o m * A byte array prefix for the lookup * @param entityType * The type of the entity * @param limit * A limit on the number of entities to return * @param starttime * The earliest entity start time to retrieve (exclusive) * @param endtime * The latest entity start time to retrieve (inclusive) * @param fromId * Retrieve entities starting with this entity * @param fromTs * Ignore entities with insert timestamp later than this ts * @param secondaryFilters * Filter pairs that the entities should match * @param fields * The set of fields to retrieve * @param usingPrimaryFilter * true if this query is using a primary filter * @return A list of entities * @throws IOException */ private TimelineEntities getEntityByTime(byte[] base, String entityType, Long limit, Long starttime, Long endtime, String fromId, Long fromTs, Collection<NameValuePair> secondaryFilters, EnumSet<Field> fields, CheckAcl checkAcl, boolean usingPrimaryFilter) throws IOException { KeyBuilder kb = KeyBuilder.newInstance().add(base).add(entityType); // only db keys matching the prefix (base + entity type) will be parsed byte[] prefix = kb.getBytesForLookup(); if (endtime == null) { // if end time is null, place no restriction on end time endtime = Long.MAX_VALUE; } // Sanitize the fields parameter if (fields == null) { fields = EnumSet.allOf(Field.class); } // construct a first key that will be seeked to using end time or fromId long firstStartTime = Long.MAX_VALUE; byte[] first = null; if (fromId != null) { Long fromIdStartTime = getStartTimeLong(fromId, entityType); if (fromIdStartTime == null) { // no start time for provided id, so return empty entities return new TimelineEntities(); } if (fromIdStartTime <= endtime) { // if provided id's start time falls before the end of the window, // use it to construct the seek key firstStartTime = fromIdStartTime; first = kb.add(writeReverseOrderedLong(fromIdStartTime)).add(fromId).getBytesForLookup(); } } // if seek key wasn't constructed using fromId, construct it using end ts if (first == null) { firstStartTime = endtime; first = kb.add(writeReverseOrderedLong(endtime)).getBytesForLookup(); } byte[] last = null; if (starttime != null) { // if start time is not null, set a last key that will not be // iterated past last = KeyBuilder.newInstance().add(base).add(entityType).add(writeReverseOrderedLong(starttime)) .getBytesForLookup(); } if (limit == null) { // if limit is not specified, use the default limit = DEFAULT_LIMIT; } TimelineEntities entities = new TimelineEntities(); RollingLevelDB rollingdb = null; if (usingPrimaryFilter) { rollingdb = indexdb; } else { rollingdb = entitydb; } DB db = rollingdb.getDBForStartTime(firstStartTime); while (entities.getEntities().size() < limit && db != null) { try (DBIterator iterator = db.iterator()) { iterator.seek(first); // iterate until one of the following conditions is met: limit is // reached, there are no more keys, the key prefix no longer matches, // or a start time has been specified and reached/exceeded while (entities.getEntities().size() < limit && iterator.hasNext()) { byte[] key = iterator.peekNext().getKey(); if (!prefixMatches(prefix, prefix.length, key) || (last != null && WritableComparator.compareBytes(key, 0, key.length, last, 0, last.length) > 0)) { break; } // read the start time and entity id from the current key KeyParser kp = new KeyParser(key, prefix.length); Long startTime = kp.getNextLong(); String entityId = kp.getNextString(); if (fromTs != null) { long insertTime = readReverseOrderedLong(iterator.peekNext().getValue(), 0); if (insertTime > fromTs) { byte[] firstKey = key; while (iterator.hasNext()) { key = iterator.peekNext().getKey(); iterator.next(); if (!prefixMatches(firstKey, kp.getOffset(), key)) { break; } } continue; } } // Even if other info and primary filter fields are not included, we // still need to load them to match secondary filters when they are // non-empty EnumSet<Field> queryFields = EnumSet.copyOf(fields); boolean addPrimaryFilters = false; boolean addOtherInfo = false; if (secondaryFilters != null && secondaryFilters.size() > 0) { if (!queryFields.contains(Field.PRIMARY_FILTERS)) { queryFields.add(Field.PRIMARY_FILTERS); addPrimaryFilters = true; } if (!queryFields.contains(Field.OTHER_INFO)) { queryFields.add(Field.OTHER_INFO); addOtherInfo = true; } } // parse the entity that owns this key, iterating over all keys for // the entity TimelineEntity entity = null; if (usingPrimaryFilter) { entity = getEntity(entityId, entityType, queryFields); iterator.next(); } else { entity = getEntity(entityId, entityType, startTime, queryFields, iterator, key, kp.getOffset()); } // determine if the retrieved entity matches the provided secondary // filters, and if so add it to the list of entities to return boolean filterPassed = true; if (secondaryFilters != null) { for (NameValuePair filter : secondaryFilters) { Object v = entity.getOtherInfo().get(filter.getName()); if (v == null) { Set<Object> vs = entity.getPrimaryFilters().get(filter.getName()); if (vs == null || !vs.contains(filter.getValue())) { filterPassed = false; break; } } else if (!v.equals(filter.getValue())) { filterPassed = false; break; } } } if (filterPassed) { if (entity.getDomainId() == null) { entity.setDomainId(DEFAULT_DOMAIN_ID); } if (checkAcl == null || checkAcl.check(entity)) { // Remove primary filter and other info if they are added for // matching secondary filters if (addPrimaryFilters) { entity.setPrimaryFilters(null); } if (addOtherInfo) { entity.setOtherInfo(null); } entities.addEntity(entity); } } } db = rollingdb.getPreviousDB(db); } } return entities; }
From source file:com.moviejukebox.model.Movie.java
/** * Copy the movie/* ww w . jav a 2 s.c o m*/ * * @param aMovie * @return */ public static Movie newInstance(Movie aMovie) { Movie newMovie = new Movie(); newMovie.baseName = aMovie.baseName; newMovie.baseFilename = aMovie.baseFilename; newMovie.title = aMovie.title; newMovie.titleSort = aMovie.titleSort; newMovie.originalTitle = aMovie.originalTitle; newMovie.year = aMovie.year; newMovie.releaseDate = aMovie.releaseDate; newMovie.plot = aMovie.plot; newMovie.outline = aMovie.outline; newMovie.quote = aMovie.quote; newMovie.tagline = aMovie.tagline; newMovie.company = aMovie.company; newMovie.runtime = aMovie.runtime; newMovie.language = aMovie.language; newMovie.videoType = aMovie.videoType; newMovie.subtitles = aMovie.subtitles; newMovie.container = aMovie.container; newMovie.resolution = aMovie.resolution; newMovie.aspect = aMovie.aspect; newMovie.videoSource = aMovie.videoSource; newMovie.videoOutput = aMovie.videoOutput; newMovie.fps = aMovie.fps; newMovie.certification = aMovie.certification; newMovie.showStatus = aMovie.showStatus; newMovie.scrapeLibrary = aMovie.scrapeLibrary; newMovie.extra = aMovie.extra; newMovie.trailerExchange = aMovie.trailerExchange; newMovie.trailerLastScan = aMovie.trailerLastScan; newMovie.libraryPath = aMovie.libraryPath; newMovie.movieType = aMovie.movieType; newMovie.formatType = aMovie.formatType; newMovie.top250 = aMovie.top250; newMovie.libraryDescription = aMovie.libraryDescription; newMovie.prebuf = aMovie.prebuf; newMovie.posterURL = aMovie.posterURL; newMovie.posterFilename = aMovie.posterFilename; newMovie.detailPosterFilename = aMovie.detailPosterFilename; newMovie.thumbnailFilename = aMovie.thumbnailFilename; newMovie.fanartURL = aMovie.fanartURL; newMovie.fanartFilename = aMovie.fanartFilename; newMovie.bannerURL = aMovie.bannerURL; newMovie.bannerFilename = aMovie.bannerFilename; newMovie.wideBannerFilename = aMovie.wideBannerFilename; newMovie.clearArtURL = aMovie.clearArtURL; newMovie.clearArtFilename = aMovie.clearArtFilename; newMovie.clearLogoURL = aMovie.clearLogoURL; newMovie.clearLogoFilename = aMovie.clearLogoFilename; newMovie.tvThumbURL = aMovie.tvThumbURL; newMovie.tvThumbFilename = aMovie.tvThumbFilename; newMovie.seasonThumbURL = aMovie.seasonThumbURL; newMovie.seasonThumbFilename = aMovie.seasonThumbFilename; newMovie.movieDiscURL = aMovie.movieDiscURL; newMovie.movieDiscFilename = aMovie.movieDiscFilename; newMovie.fileDate = aMovie.fileDate; newMovie.fileSize = aMovie.fileSize; newMovie.watchedFile = aMovie.watchedFile; newMovie.watchedNFO = aMovie.watchedNFO; newMovie.first = aMovie.first; newMovie.previous = aMovie.first; newMovie.next = aMovie.next; newMovie.last = aMovie.last; newMovie.file = aMovie.file; newMovie.containerFile = aMovie.containerFile; newMovie.setMaster = aMovie.setMaster; newMovie.setSize = aMovie.setSize; newMovie.idMap = new HashMap<>(aMovie.idMap); newMovie.countries = new LinkedHashSet<>(aMovie.countries); newMovie.ratings = new HashMap<>(aMovie.ratings); newMovie.directors = new LinkedHashSet<>(aMovie.directors); newMovie.sets = new HashMap<>(aMovie.sets); newMovie.genres = new TreeSet<>(aMovie.genres); newMovie.cast = new LinkedHashSet<>(aMovie.cast); newMovie.writers = new LinkedHashSet<>(aMovie.writers); newMovie.awards = new ArrayList<>(aMovie.awards); newMovie.people = new ArrayList<>(aMovie.people); newMovie.indexes = new HashMap<>(aMovie.indexes); newMovie.movieFiles = new TreeSet<>(aMovie.movieFiles); newMovie.extraFiles = new TreeSet<>(aMovie.extraFiles); newMovie.dirtyFlags = EnumSet.copyOf(aMovie.dirtyFlags); newMovie.codecs = new LinkedHashSet<>(aMovie.codecs); newMovie.footerFilename = new ArrayList<>(aMovie.footerFilename); newMovie.overrideSources = new EnumMap<>(aMovie.overrideSources); return newMovie; }