List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:com.aurel.track.admin.customize.treeConfig.field.FieldConfigBL.java
public static FieldConfigTO createFieldConfigTO(WorkItemContext workItemContext, TFieldBean fieldBean, Locale locale) {// ww w . j av a 2s. c o m FieldConfigTO fieldConfigTO = new FieldConfigTO(); Integer fieldID = fieldBean.getObjectID(); fieldConfigTO.setFieldID(fieldID); FieldType fieldType = FieldTypeManager.getInstance().getType(fieldID); TypeRendererRT fieldTypeRendererRT = null; IFieldTypeRT fieldTypeRT = null; if (fieldType != null) { fieldType.setFieldID(fieldID); fieldTypeRendererRT = fieldType.getRendererRT(); fieldTypeRT = fieldType.getFieldTypeRT(); } TFieldConfigBean fieldConfigBean = (TFieldConfigBean) workItemContext.getFieldConfigs().get(fieldID); String tooltip = null; if (fieldConfigBean != null) { tooltip = fieldConfigBean.getTooltip(); if (fieldTypeRT != null && tooltip != null) { Map<String, Object> labelContext = fieldTypeRT.getLabelContext(fieldID, workItemContext.getWorkItemBean().getAttribute(fieldID, null), locale); if (labelContext != null && !labelContext.isEmpty()) { Template tooltipTemplate = getTooltipTemplate(tooltip); StringWriter labelWriter = new StringWriter(); try { tooltipTemplate.process(labelContext, labelWriter); tooltip = labelWriter.toString(); } catch (Exception e) { LOGGER.debug("Processing template: " + labelWriter.toString() + " failed with " + e.getMessage()); } } } fieldConfigTO.setLabel(fieldConfigBean.getLabel()); } if (tooltip == null) { tooltip = ""; } fieldConfigTO.setTooltip(tooltip); Integer accesFlag = null; if (workItemContext.getFieldRestrictions() != null) { accesFlag = workItemContext.getFieldRestrictions().get(fieldID); } boolean readonly = false; boolean invisible = false; if (accesFlag != null) { if (accesFlag.intValue() == TRoleFieldBean.ACCESSFLAG.NOACCESS) { readonly = true; invisible = true; } else { invisible = false; readonly = (accesFlag.intValue() == TRoleFieldBean.ACCESSFLAG.READ_ONLY); } } fieldConfigTO.setReadonly(readonly); Set<Integer> readOnlyFields = getReadOnlySet(); if (readOnlyFields.contains(fieldID)) { fieldConfigTO.setReadonly(true); } else { fieldConfigTO.setRequired(fieldBean.isRequiredString() || fieldConfigBean.isRequiredString()); } fieldConfigTO.setInvisible(invisible); boolean hasDependences = ItemFieldRefreshBL.hasDependences(fieldBean, workItemContext); fieldConfigTO.setHasDependences(hasDependences); if (hasDependences) { fieldConfigTO.setClientSideRefresh(ItemFieldRefreshBL.isClientSideRefresh(fieldID)); } //TODO validate JSON if (fieldTypeRendererRT != null) { fieldConfigTO.setJsonData(fieldTypeRendererRT.createJsonData(fieldBean, workItemContext)); } return fieldConfigTO; }
From source file:Set1.java
public static void test(Set s) { // Strip qualifiers from class name: System.out.println(s.getClass().getName().replaceAll("\\w+\\.", "")); fill(s);/*from w w w.jav a 2 s .co m*/ fill(s); fill(s); System.out.println(s); // No duplicates! // Add another set to this one: s.addAll(s); s.add("one"); s.add("one"); s.add("one"); System.out.println(s); // Look something up: System.out.println("s.contains(\"one\"): " + s.contains("one")); }
From source file:com.cangqu.gallery.server.base.utils.ReflectionUtils.java
/** * SET????<br/>/*www.jav a 2 s . c o m*/ * @param set1 ?SET<br/> * @param set2 ?SET<br/> * @return */ public static int compareSet(Set set1, Set set2) { int sameCount = 0; for (Object o : set1) { if (set2.contains(o)) sameCount++; } return sameCount; }
From source file:org.messic.server.facade.security.AuthenticationSessionManager.java
/** * @param token the session token/* w w w. jav a 2s. c o m*/ * @param roles the user must have ANY roles * @return true if the auth connected to the token has any of the given role */ public static boolean hasAnyRoles(String token, String[] roles) { Set<String> auth = getRoles(token); if (auth == null) { return false; } for (String role : roles) { if (auth.contains(role)) { return true; } } return false; }
From source file:org.messic.server.facade.security.AuthenticationSessionManager.java
/** * @param token the session token//from w w w .j ava2 s.c o m * @param roles the user must have ALL roles * @return true if the auth connected to the token has all the given role */ public static boolean hasRoles(String token, String[] roles) { Set<String> auth = getRoles(token); if (auth == null) { return false; } for (String role : roles) { if (!auth.contains(role)) { return false; } } return true; }
From source file:com.wrmsr.wava.basic.BasicLoopInfo.java
public static SetMultimap<Name, Name> findBasicBackEdges(Iterable<Basic> basics, Set<Name> loops, BasicDominatorInfo di) {//from ww w . jav a 2 s .c om return StreamSupport.stream(basics.spliterator(), false).flatMap(brk -> { Set<Name> bdf = di.getDominanceFrontiers().get(brk.getName()); return brk.getAllTargets().stream() .filter(loop -> loops.contains(loop) && bdf.contains(loop) && (loop.equals(brk.getName()) || di.getDominated(loop).contains(brk.getName()))) .map(loop -> ImmutablePair.of(loop, brk.getName())); }).collect(toHashMultimap()); }
From source file:gr.abiss.calipso.util.UserUtils.java
/** * used to init backing form object in wicket corresponding to ItemUser / notifyList *//*from w w w .j a v a2 s .c om*/ public static List<ItemUser> convertToItemUserList(List<UserSpaceRole> userSpaceRoles) { List<ItemUser> itemUsers = new ArrayList<ItemUser>(userSpaceRoles.size()); Set<User> users = new HashSet<User>(itemUsers.size()); for (UserSpaceRole usr : userSpaceRoles) { User user = usr.getUser(); // we need to do this check as now JTrac supports same user mapped // more than once to a space with different roles if (!users.contains(user)) { users.add(user); itemUsers.add(new ItemUser(user)); } } return itemUsers; }
From source file:com.diffplug.gradle.FileMisc.java
/** Returns true if any of the bits contain the executable permission. */ public static boolean containsExecutablePermission(Set<PosixFilePermission> permissions) { return permissions.contains(PosixFilePermission.OWNER_EXECUTE) && permissions.contains(PosixFilePermission.GROUP_EXECUTE) && permissions.contains(PosixFilePermission.OTHERS_EXECUTE); }
From source file:Main.java
public static <T> Set<? extends T> interSubtype(final Set<? extends T> a, final Set<? extends T> b) { if (a == b)/*from w w w . j ava 2 s . c om*/ return a; else if (a == null) return b; else if (b == null) return a; else if (a.size() > b.size()) { return interSubtype(b, a); } final Set<T> res = new HashSet<T>(); for (final T item : a) { if (b.contains(item)) res.add(item); } return res; }
From source file:com.facebook.buck.zip.Unzip.java
/** * Unzips a file to a destination and returns the paths of the written files. *//*from w ww . j a v a 2 s . c o m*/ public static ImmutableList<Path> extractZipFile(Path zipFile, ProjectFilesystem filesystem, Path relativePath, ExistingFileMode existingFileMode) throws IOException { // if requested, clean before extracting if (existingFileMode == ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES) { try (ZipFile zip = new ZipFile(zipFile.toFile())) { Enumeration<ZipArchiveEntry> entries = zip.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); filesystem.deleteRecursivelyIfExists(relativePath.resolve(entry.getName())); } } } ImmutableList.Builder<Path> filesWritten = ImmutableList.builder(); try (ZipFile zip = new ZipFile(zipFile.toFile())) { Enumeration<ZipArchiveEntry> entries = zip.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); String fileName = entry.getName(); Path target = relativePath.resolve(fileName); // TODO(bolinfest): Keep track of which directories have already been written to avoid // making unnecessary Files.createDirectories() calls. In practice, a single zip file will // have many entries in the same directory. if (entry.isDirectory()) { // Create the directory and all its parent directories filesystem.mkdirs(target); } else { // Create parent folder filesystem.createParentDirs(target); filesWritten.add(target); // Write file try (InputStream is = zip.getInputStream(entry)) { if (entry.isUnixSymlink()) { filesystem.createSymLink(target, filesystem.getPath(new String(ByteStreams.toByteArray(is), Charsets.UTF_8)), /* force */ true); } else { try (OutputStream out = filesystem.newFileOutputStream(target)) { ByteStreams.copy(is, out); } } } // restore mtime for the file filesystem.resolve(target).toFile().setLastModified(entry.getTime()); // TODO(shs96c): Implement what the comment below says we should do. // // Sets the file permissions of the output file given the information in {@code entry}'s // extra data field. According to the docs at // http://www.opensource.apple.com/source/zip/zip-6/unzip/unzip/proginfo/extra.fld there // are two extensions that might support file permissions: Acorn and ASi UNIX. We shall // assume that inputs are not from an Acorn SparkFS. The relevant section from the docs: // // <pre> // The following is the layout of the ASi extra block for Unix. The // local-header and central-header versions are identical. // (Last Revision 19960916) // // Value Size Description // ----- ---- ----------- // (Unix3) 0x756e Short tag for this extra block type ("nu") // TSize Short total data size for this block // CRC Long CRC-32 of the remaining data // Mode Short file permissions // SizDev Long symlink'd size OR major/minor dev num // UID Short user ID // GID Short group ID // (var.) variable symbolic link filename // // Mode is the standard Unix st_mode field from struct stat, containing // user/group/other permissions, setuid/setgid and symlink info, etc. // </pre> // // From the stat man page, we see that the following mask values are defined for the file // permissions component of the st_mode field: // // <pre> // S_ISUID 0004000 set-user-ID bit // S_ISGID 0002000 set-group-ID bit (see below) // S_ISVTX 0001000 sticky bit (see below) // // S_IRWXU 00700 mask for file owner permissions // // S_IRUSR 00400 owner has read permission // S_IWUSR 00200 owner has write permission // S_IXUSR 00100 owner has execute permission // // S_IRWXG 00070 mask for group permissions // S_IRGRP 00040 group has read permission // S_IWGRP 00020 group has write permission // S_IXGRP 00010 group has execute permission // // S_IRWXO 00007 mask for permissions for others // (not in group) // S_IROTH 00004 others have read permission // S_IWOTH 00002 others have write permission // S_IXOTH 00001 others have execute permission // </pre> // // For the sake of our own sanity, we're going to assume that no-one is using symlinks, // but we'll check and throw if they are. // // Before we do anything, we should check the header ID. Pfft! // // Having jumped through all these hoops, it turns out that InfoZIP's "unzip" store the // values in the external file attributes of a zip entry (found in the zip's central // directory) assuming that the OS creating the zip was one of an enormous list that // includes UNIX but not Windows, it first searches for the extra fields, and if not found // falls through to a code path that supports MS-DOS and which stores the UNIX file // attributes in the upper 16 bits of the external attributes field. // // We'll support neither approach fully, but we encode whether this file was executable // via storing 0100 in the fields that are typically used by zip implementations to store // POSIX permissions. If we find it was executable, use the platform independent java // interface to make this unpacked file executable. Set<PosixFilePermission> permissions = MorePosixFilePermissions .fromMode(entry.getExternalAttributes() >> 16); if (permissions.contains(PosixFilePermission.OWNER_EXECUTE)) { MoreFiles.makeExecutable(filesystem.resolve(target)); } } } } return filesWritten.build(); }