List of usage examples for java.util EnumSet noneOf
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
From source file:com.couchbase.touchdb.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { TDBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); TDStatus status = new TDStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); TDRevision rev1 = database.putRevision(new TDRevision(rev1Properties), null, false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); TDAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); TDRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(TDDatabase.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Check the attachment dict, with attachments included: innerDict.remove("stub"); innerDict.put("data", Base64.encodeBytes(attach1)); attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(TDDatabase.TDContentOptions.TDIncludeAttachments)); gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Add a second revision that doesn't update the attachment: Map<String, Object> rev2Properties = new HashMap<String, Object>(); rev2Properties.put("_id", rev1.getDocId()); rev2Properties.put("foo", 2); rev2Properties.put("bazz", false); TDRevision rev2 = database.putRevision(new TDRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());/*from w w w . ja v a2 s. c o m*/ Assert.assertEquals(TDStatus.OK, status.getCode()); // Add a third revision of the same document: Map<String, Object> rev3Properties = new HashMap<String, Object>(); rev3Properties.put("_id", rev2.getDocId()); rev3Properties.put("foo", 2); rev3Properties.put("bazz", false); TDRevision rev3 = database.putRevision(new TDRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: TDAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: TDAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<TDBlobKey> expected = new HashSet<TDBlobKey>(); expected.add(TDBlobStore.keyForBlob(attach1)); expected.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<TDBlobKey> expected2 = new HashSet<TDBlobKey>(); expected2.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:com.couchbase.cblite.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { CBLBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); CBLStatus status = new CBLStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); CBLRevision rev1 = database.putRevision(new CBLRevision(rev1Properties), null, false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); CBLAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); CBLRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(CBLDatabase.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Check the attachment dict, with attachments included: innerDict.remove("stub"); innerDict.put("data", Base64.encodeBytes(attach1)); attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(CBLDatabase.TDContentOptions.TDIncludeAttachments)); gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Add a second revision that doesn't update the attachment: Map<String, Object> rev2Properties = new HashMap<String, Object>(); rev2Properties.put("_id", rev1.getDocId()); rev2Properties.put("foo", 2); rev2Properties.put("bazz", false); CBLRevision rev2 = database.putRevision(new CBLRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());/* w w w. j av a 2s.c om*/ Assert.assertEquals(CBLStatus.OK, status.getCode()); // Add a third revision of the same document: Map<String, Object> rev3Properties = new HashMap<String, Object>(); rev3Properties.put("_id", rev2.getDocId()); rev3Properties.put("foo", 2); rev3Properties.put("bazz", false); CBLRevision rev3 = database.putRevision(new CBLRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: CBLAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: CBLAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<CBLBlobKey> expected = new HashSet<CBLBlobKey>(); expected.add(CBLBlobStore.keyForBlob(attach1)); expected.add(CBLBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<CBLBlobKey> expected2 = new HashSet<CBLBlobKey>(); expected2.add(CBLBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:com.pongasoft.kiwidoc.builder.KiwidocBuilder.java
/** * Builds the kiwidoc for the given library * * @param library (optional, <code>null</code> ok) dependencies * @return the model builder/*from w w w .j ava2 s. c o m*/ * @throws BuilderException when there is a problem indexing */ public LibraryModelBuilder buildKiwidoc(Library library) throws IOException, BuilderException { Set<BuiltFrom> builtFrom = EnumSet.noneOf(BuiltFrom.class); Manifest manifest = null; LibraryModelBuilder libFromByteCode = null; // if we have the library itself (jar file) if (library.classes != null) { builtFrom.add(BuiltFrom.BYTECODE); // manifest FileObject manifestResource = library.classes.resolveFile("META-INF/MANIFEST.MF"); if (manifestResource.exists()) { manifest = new Manifest(); InputStream is = manifestResource.getContent().getInputStream(); try { manifest.read(new BufferedInputStream(is)); } finally { is.close(); } } // byte code libFromByteCode = new LibraryModelBuilder(library.libraryVersionResource); new ByteCodeParser().parseClasses(libFromByteCode, library.classes); } LibraryModelBuilder libFromSource = null; // if we have the source code if (library.sources != null) { try { libFromSource = new LibraryModelBuilder(library.libraryVersionResource); if (libFromByteCode != null) libFromSource.setJdkVersion(libFromByteCode.getJdkVersion()); else libFromSource.setJdkVersion(library.jdkVersion); int sourceCount = new SourceCodeParser().parseSources(libFromSource, library.sources, library.overviewFilename, library.publicOnly ? library.javadoc : null, library.classpath); if (sourceCount == 0) { libFromSource = null; log.warn("No sources found in " + library.sources); } else { builtFrom.add(BuiltFrom.SOURCE); } } catch (IOException e) { throw e; } catch (Throwable th) { throw new BuilderException(th); } } // compute which version to use (source code wins if available) LibraryModelBuilder lib = new LibraryModelBuilder(library.libraryVersionResource); if (libFromByteCode != null) { lib = libFromByteCode; } if (libFromSource != null) { lib = libFromSource; } log.info("Processed source|bytecode: " + (libFromSource == null ? "N/A" : libFromSource.getClassCount()) + " | " + (libFromByteCode == null ? "N/A" : libFromByteCode.getClassCount())); // TODO MED YP: use byte code for resolving unresolved types during javadoc processing // if we have the original javadoc (used for determining exported classes) if (library.javadoc != null) { builtFrom.add(BuiltFrom.JAVADOC); for (PackageModelBuilder packageModelBuilder : lib.getAllPackages()) { for (ClassModelBuilder classModelBuilder : packageModelBuilder.getAllClasses()) { String javadocFile = classModelBuilder.getFqcn(); javadocFile = javadocFile.replace('.', '/'); javadocFile = javadocFile.replace('$', '.'); // for inner classes javadocFile += ".html"; try { classModelBuilder.setExportedClass( library.javadoc.resolveFile(javadocFile, NameScope.DESCENDENT).exists()); } catch (FileSystemException e) { log.warn("Error while setting exported class on " + javadocFile + " [" + classModelBuilder.getFqcn() + "]", e); } } } } // dependencies lib.setDependencies(library.dependencies); // manifest lib.setManifest(manifest); // built from lib.addBuiltFrom(builtFrom); return lib; }
From source file:cc.wulian.smarthomev5.fragment.singin.handler.DecodeThread.java
public DecodeThread(IQRScanHandlerResult scanHandlerResult, Collection<BarcodeFormat> decodeFormats, Hashtable<DecodeHintType, ?> baseHints, String characterSet, ResultPointCallback resultPointCallback) { this.scanHandlerResult = scanHandlerResult; handlerInitLatch = new CountDownLatch(1); hints = new Hashtable<>(); if (baseHints != null) { hints.putAll(baseHints);/*from w w w.j a va2 s . c o m*/ } // The prefs can't change while the thread is running, so pick them up once here. if (decodeFormats == null || decodeFormats.isEmpty()) { // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); decodeFormats = EnumSet.noneOf(BarcodeFormat.class); // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_1D_PRODUCT, true)) { // decodeFormats.addAll(DecodeFormatManager.PRODUCT_FORMATS); // } // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_1D_INDUSTRIAL, true)) { // decodeFormats.addAll(DecodeFormatManager.INDUSTRIAL_FORMATS); // } // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_QR, true)) { // decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); // } // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_DATA_MATRIX, true)) { // decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS); // } // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_AZTEC, false)) { // decodeFormats.addAll(DecodeFormatManager.AZTEC_FORMATS); // } // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_PDF417, false)) { // decodeFormats.addAll(DecodeFormatManager.PDF417_FORMATS); // } decodeFormats.addAll(DecodeFormatManager.PRODUCT_FORMATS); decodeFormats.addAll(DecodeFormatManager.INDUSTRIAL_FORMATS); decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS); decodeFormats.addAll(DecodeFormatManager.AZTEC_FORMATS); decodeFormats.addAll(DecodeFormatManager.PDF417_FORMATS); } hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); if (characterSet != null) { hints.put(DecodeHintType.CHARACTER_SET, characterSet); } hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback); Log.i("DecodeThread", "Hints: " + hints); }
From source file:com.github.anba.es6draft.util.TestGlobals.java
protected EnumSet<Parser.Option> getParserOptions() { return EnumSet.noneOf(Parser.Option.class); }
From source file:io.lavagna.service.PermissionService.java
public ProjectRoleAndPermissionFullHolder findPermissionsGroupedByProjectForUserId(int userId) { List<ProjectRoleAndPermission> found = queries.findPermissionsGroupedByProjectForUserId(userId); Map<String, Set<Permission>> res = new HashMap<>(); Map<Integer, Set<Permission>> resById = new HashMap<>(); for (ProjectRoleAndPermission p : found) { if (p.getPermission() == null) { continue; }//from w w w .java 2s .c om if (!res.containsKey(p.getProjectShortName())) { res.put(p.getProjectShortName(), EnumSet.noneOf(Permission.class)); } res.get(p.getProjectShortName()).add(p.getPermission()); if (!resById.containsKey(p.getProjectId())) { resById.put(p.getProjectId(), EnumSet.noneOf(Permission.class)); } resById.get(p.getProjectId()).add(p.getPermission()); } return new ProjectRoleAndPermissionFullHolder(res, resById); }
From source file:com.github.anba.es6draft.util.TestGlobals.java
protected EnumSet<Compiler.Option> getCompilerOptions() { return EnumSet.noneOf(Compiler.Option.class); }
From source file:ezbake.security.permissions.PermissionUtils.java
/** * Get permissions for user (based their authorizations) against the data's visibility. * * @param auths Authorizations of the user * @param visibility Visibility of the data * @param validateFormalAuths true to validate formal authorizations, false to skip * @param subsetToCheck The subset of permissions to check (to avoid more bitvector operations than needed) * @return The set of permissions the user has for the data (a subset of the subsetToCheck) */// ww w. jav a2 s.com public static Set<Permission> getPermissions(Authorizations auths, Visibility visibility, boolean validateFormalAuths, Set<Permission> subsetToCheck) { if (visibility == null) { return ALL_PERMS; // No visibility to check } if (auths == null) { return NO_PERMS; // Has visibility but no auths } if (validateFormalAuths && !validateVisibilityExpression(auths.getFormalAuthorizations(), visibility.getFormalVisibility())) { return NO_PERMS; // Formals auths check failed } final AdvancedMarkings markings = visibility.getAdvancedMarkings(); if (markings == null) { return ALL_PERMS; // No further visibility to check } if (!validateVisibilityExpression(auths.getExternalCommunityAuthorizations(), markings.getExternalCommunityVisibility())) { return NO_PERMS; // External community auths check failed } final PlatformObjectVisibilities pov = markings.getPlatformObjectVisibility(); if (pov == null) { return ALL_PERMS; // No further visibility to check } final Set<Long> authCheck = auths.getPlatformObjectAuthorizations(); final Set<Permission> perms = EnumSet.noneOf(Permission.class); for (final Permission permToCheck : subsetToCheck) { Set<Long> permVisibility = null; switch (permToCheck) { case READ: permVisibility = pov.getPlatformObjectReadVisibility(); break; case WRITE: permVisibility = pov.getPlatformObjectWriteVisibility(); break; case MANAGE_VISIBILITY: permVisibility = pov.getPlatformObjectManageVisibility(); break; case DISCOVER: permVisibility = pov.getPlatformObjectDiscoverVisibility(); break; default: throw new IllegalArgumentException("Unknown Permission enum value" + permToCheck); } // Null/Empty visibility means world-accessible, else check intersection if (permVisibility == null || permVisibility.isEmpty() || authCheck != null && !Sets.intersection(authCheck, permVisibility).isEmpty()) { perms.add(permToCheck); } } return perms; }
From source file:com.inmobi.conduit.distcp.tools.util.TestDistCpUtils.java
@Test public void testPreserve() { try {//from w w w . j av a 2 s.c o m FileSystem fs = FileSystem.get(config); EnumSet<FileAttribute> attributes = EnumSet.noneOf(FileAttribute.class); Path path = new Path("/tmp/abc"); Path src = new Path("/tmp/src"); fs.mkdirs(path); fs.mkdirs(src); FileStatus srcStatus = fs.getFileStatus(src); FsPermission noPerm = new FsPermission((short) 0); fs.setPermission(path, noPerm); fs.setOwner(path, "nobody", "nobody"); DistCpUtils.preserve(fs, path, srcStatus, attributes); FileStatus target = fs.getFileStatus(path); Assert.assertEquals(target.getPermission(), noPerm); Assert.assertEquals(target.getOwner(), "nobody"); Assert.assertEquals(target.getGroup(), "nobody"); attributes.add(FileAttribute.PERMISSION); DistCpUtils.preserve(fs, path, srcStatus, attributes); target = fs.getFileStatus(path); Assert.assertEquals(target.getPermission(), srcStatus.getPermission()); Assert.assertEquals(target.getOwner(), "nobody"); Assert.assertEquals(target.getGroup(), "nobody"); attributes.add(FileAttribute.GROUP); attributes.add(FileAttribute.USER); DistCpUtils.preserve(fs, path, srcStatus, attributes); target = fs.getFileStatus(path); Assert.assertEquals(target.getPermission(), srcStatus.getPermission()); Assert.assertEquals(target.getOwner(), srcStatus.getOwner()); Assert.assertEquals(target.getGroup(), srcStatus.getGroup()); fs.delete(path, true); fs.delete(src, true); } catch (IOException e) { LOG.error("Exception encountered ", e); Assert.fail("Preserve test failure"); } }
From source file:ru.savvy.jpafilterbuilder.FilterCriteriaBuilder.java
/** * Creates new instance from existing query * * @param em/* w w w . j a v a 2 s . c o m*/ * @param query */ public FilterCriteriaBuilder(EntityManager em, CriteriaQuery<T> query) { this.cb = em.getCriteriaBuilder(); this.clazz = query.getResultType(); //this.query = query; this.options = EnumSet.noneOf(Option.class); this.pb = new PredicateBuilder(cb, options); this.metamodel = em.getMetamodel(); // Set<Root<?>> roots = query.getRoots(); // for (Root<?> r : roots) { // if (r.getJavaType().equals(this.clazz)) { // this.root = (Root<T>) r; // break; // } // } // if (this.root == null) { // this.root = query.from(this.clazz); // } }