List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:nu.yona.server.subscriptions.service.migration.AddFirstDevice.java
@Override public void upgrade(User user) { Set<UserDevice> devices = user.getDevices(); if (devices.isEmpty()) { createInitialDevice(user);//w w w.jav a 2 s .co m } else { addDevicesAnonymizedToUserAnonymizedIfNotDoneYet(user); } }
From source file:ai.grakn.graql.internal.gremlin.GraqlTraversal.java
/** * Create a semi-optimal plan using a greedy approach to execute a single conjunction * @param query the conjunction query to find a traversal plan * @return a semi-optimal traversal plan to execute the given conjunction *//* w ww . j ava2s .c o m*/ private static List<Fragment> semiOptimalConjunction(ConjunctionQuery query) { Set<EquivalentFragmentSet> fragmentSets = Sets.newHashSet(query.getEquivalentFragmentSets()); Set<String> names = new HashSet<>(); // This list is constructed over the course of the algorithm List<Fragment> fragments = new ArrayList<>(); long numFragments = fragments(fragmentSets).count(); long depth = 1; long numTraversalAttempts = numFragments; // Calculate the depth to descend in the tree, based on how many plans we want to evaluate while (numFragments > 0 && numTraversalAttempts < MAX_TRAVERSAL_ATTEMPTS) { depth += 1; numTraversalAttempts *= numFragments; numFragments -= 1; } double cost = 1; while (!fragmentSets.isEmpty()) { Pair<Double, List<Fragment>> pair = findPlan(fragmentSets, names, cost, depth); cost = pair.getValue0(); List<Fragment> newFragments = Lists.reverse(pair.getValue1()); if (newFragments.isEmpty()) { throw new RuntimeException(ErrorMessage.FAILED_TO_BUILD_TRAVERSAL.getMessage()); } newFragments.forEach(fragment -> { fragmentSets.remove(fragment.getEquivalentFragmentSet()); fragment.getVariableNames().forEach(names::add); }); fragments.addAll(newFragments); } return fragments; }
From source file:RequestUtil.java
/** * Delete a cookie except the designated variable name from CookieString * /* w ww .jav a2s. c o m*/ * @param cookieString * @param paramName * @return */ public static String removeCookieParam(String cookieString, Set<String> paramNames) { StringTokenizer tok = new StringTokenizer(cookieString, ";", false); String resultCookieString = ""; while (tok.hasMoreTokens()) { String token = tok.nextToken(); int i = token.indexOf("="); if (i > -1) { for (String paramName : paramNames) { String name = token.substring(0, i).trim(); if (paramName.equalsIgnoreCase(name)) { if (resultCookieString.length() > 0) resultCookieString += ";"; resultCookieString += token; } } } else { // we have a bad cookie.... just let it go } if (paramNames.isEmpty()) { if (resultCookieString.length() > 0) resultCookieString += ";"; resultCookieString += token; } } return resultCookieString.trim(); }
From source file:edu.stanford.epad.epadws.service.UserProjectService.java
/** * Create subject/study records from uploaded dicom file and add to project * @param dicomFile/*from w ww . j a v a2s . com*/ * @param projectID * @param sessionID * @param username * @throws Exception */ public static boolean createProjectEntitiesFromDICOMFile(File dicomFile, String projectID, String sessionID, String username) throws Exception { DicomObject dicomObject = null; try { dicomObject = DicomReader.getDicomObject(dicomFile); } catch (Exception e) { log.warning("Dicom object couldn't be retrieved!"); return false; } //corrupt and/or wrong dicom file control ml if (dicomObject == null) { log.warning("Dicom object couldn't be retrieved!"); return false; } String sopInstanceUID = dicomObject.getString(Tag.SOPInstanceUID); String dicomPatientName = dicomObject.getString(Tag.PatientName); String dicomPatientID = dicomObject.getString(Tag.PatientID); String studyUID = dicomObject.getString(Tag.StudyInstanceUID); String studyDate = dicomObject.getString(Tag.StudyDate); String seriesUID = dicomObject.getString(Tag.SeriesInstanceUID); String modality = dicomObject.getString(Tag.Modality); log.info("Uploading dicom, username:" + username + " projectID:" + projectID + " patientName:" + dicomPatientName + " patientID:" + dicomPatientID + " studyUID:" + studyUID + " studyDate:" + studyDate + " seriesUID:" + seriesUID + " modality:" + modality); if (dicomPatientID == null || dicomPatientID.trim().length() == 0 || dicomPatientID.equalsIgnoreCase("ANON") || dicomPatientID.equalsIgnoreCase("Unknown") || dicomPatientID.contains("%") || dicomPatientID.equalsIgnoreCase("Anonymous")) { String message = "Invalid patientID:'" + dicomPatientID + "' file:" + dicomFile.getName() + ", Rejecting file"; log.warning(message); if (dicomPatientID != null) message = "Invalid non-unique patient ID " + dicomPatientID + " in DICOM file"; if (dicomPatientID != null && dicomPatientID.contains("%")) { message = "An invalid character in patient ID " + dicomPatientID; } databaseOperations.insertEpadEvent(username, message, seriesUID, "", "Invalid PatientID:" + dicomPatientID, dicomPatientName, studyUID, projectID, "Error in Upload"); dicomFile.delete(); projectOperations.createEventLog(username, projectID, dicomPatientID, studyUID, seriesUID, null, null, dicomFile.getName(), "UPLOAD SERIES", message, true); return false; } if (pendingUploads.size() < 300) pendingUploads.put(studyUID, username + ":" + projectID); if (pendingPNGs.size() < 300) pendingPNGs.put(seriesUID, username + ":" + projectID); //check if the patient id already exist in the system. If so put a log or something, specifying the patient name that is used and the project Subject subject = projectOperations.getSubject(dicomPatientID); //TODO for some reason this(dicomPatientName.trim().toLowerCase().equalsIgnoreCase(subject.getName().trim().toLowerCase()) does not work for Anonymous if (subject != null && dicomPatientName != null && subject.getName() != null && !dicomPatientName.trim() .toLowerCase().equalsIgnoreCase(subject.getName().trim().toLowerCase())) { if (!duplicatePatientIds.contains(dicomPatientID)) { duplicatePatientIds.add(dicomPatientID); List<Project> projects = projectOperations.getProjectsForSubject(subject.getSubjectUID()); StringBuilder projectsStr = new StringBuilder(); for (Project p : projects) { projectsStr.append(p.getName()); projectsStr.append(","); } String message = "The patient " + dicomPatientName + " is already uploaded as " + subject.getName() + " in project(s): " + projectsStr.toString().substring(0, projectsStr.length() - 1); projectOperations.createEventLog(username, projectID, dicomPatientID, studyUID, seriesUID, null, null, dicomFile.getName(), "DUPLICATE DEIDENTIFICATION", message, true); } //for keeping the same name in cache dicomPatientName = subject.getName(); } if (dicomPatientID != null && studyUID != null) { //databaseOperations.deleteSeriesOnly(seriesUID); // This will recreate all images if (dicomPatientName == null) dicomPatientName = ""; dicomPatientName = dicomPatientName.toUpperCase(); // DCM4CHEE stores the patient name as upper case addSubjectAndStudyToProject(dicomPatientID, dicomPatientName, studyUID, studyDate, projectID, sessionID, username); if ("SEG".equals(modality)) { try { // List<EPADAIM> aims = databaseOperations.getAIMsByDSOSeries(projectID, dicomPatientID, seriesUID); // List<ImageAnnotation> ias = AIMQueries.getAIMImageAnnotations(AIMSearchType.SERIES_UID, seriesUID, username, 1, 50); // if (ias.size() == 0 || aims.size() == 0) // AIMUtil.generateAIMFileForDSO(dicomFile, username, projectID); List<EPADAIM> aims = databaseOperations.getAIMsByDSOSeries(null, dicomPatientID, seriesUID); log.info("getting annotations for dso w/uid " + sopInstanceUID); List<ImageAnnotation> ias = AIMQueries.getAIMImageAnnotations(AIMSearchType.SEG_INSTANCE_UID, sopInstanceUID, username, 1, 50); log.info("Found aims:" + ias.size()); boolean generateAim = false; if (aims.size() == 1 && aims.get(0).projectID.equals(EPADConfig.xnatUploadProjectID) && !projectID.equals(EPADConfig.xnatUploadProjectID)) generateAim = true; if (generateAim || ias.size() == 0 || aims.size() == 0) { AIMUtil.generateAIMFileForDSO(dicomFile, username, projectID); } else { boolean projectAIMExists = false; for (EPADAIM aim : aims) { if (aim.projectID.equals(projectID)) { projectAIMExists = true; break; } } if (!projectAIMExists) databaseOperations.addProjectToAIM(projectID, aims.get(0).aimID); } Set<String> imageUIDs = Dcm4CheeDatabase.getInstance().getDcm4CheeDatabaseOperations() .getImageUIDsForSeries(seriesUID); if (false && !imageUIDs.isEmpty()) { String message = "DSO for patientID:" + dicomPatientID + " Series:" + seriesUID + " file:" + dicomFile.getName() + " already exists. Please delete DSO before reuploading"; log.warning(message); databaseOperations.insertEpadEvent(username, message, seriesUID, "", dicomPatientID, dicomPatientName, studyUID, projectID, "Error in Upload"); dicomFile.delete(); projectOperations.createEventLog(username, projectID, dicomPatientID, studyUID, seriesUID, null, null, dicomFile.getName(), "UPLOAD DSO", message, true); return false; } String imageUID = dicomObject.getString(Tag.SOPInstanceUID); String pngMaskDirectoryPath = EPADConfig.getEPADWebServerPNGDir() + "/studies/" + studyUID + "/series/" + seriesUID + "/images/" + imageUID + "/masks/"; File pngDirectory = new File(pngMaskDirectoryPath); if (pngDirectory.exists()) { // File[] files = pngDirectory.listFiles(); // for (File file: files) // { // //file.delete(); // } } } catch (Exception x) { log.warning("Error generating DSO Annotation:", x); databaseOperations.insertEpadEvent(username, "Error generating DSO Annotation", seriesUID, "", dicomPatientID, dicomPatientName, studyUID, projectID, "Upload " + dicomFile.getName()); projectOperations.createEventLog(username, projectID, dicomPatientID, studyUID, seriesUID, null, null, dicomFile.getName(), "UPLOAD DSO", "Error generating DSO Annotation", true); } } } else { log.warning("Missing patient ID or studyUID in DICOM file " + dicomFile.getAbsolutePath()); databaseOperations.insertEpadEvent(username, "Missing patient ID or studyUID in DICOM file", seriesUID, "", dicomPatientID, dicomPatientName, studyUID, projectID, "Process Upload"); projectOperations.createEventLog(username, projectID, dicomPatientID, studyUID, seriesUID, null, null, null, "UPLOAD DSO", "Missing patient ID or studyUID in DICOM file " + dicomFile.getName(), true); } return true; }
From source file:org.owasp.proxy.Main.java
private static HttpRequestHandler configureAJP(HttpRequestHandler rh, Configuration config) { if (config.ajpServer != null) { final DefaultAJPRequestHandler arh = new DefaultAJPRequestHandler(); arh.setTarget(config.ajpServer); AJPProperties ajpProperties = new AJPProperties(); ajpProperties.setRemoteAddress(config.ajpClientAddress); if (config.ajpClientCert != null && config.ajpClientCert.endsWith(".pem")) { try { BufferedReader in = new BufferedReader(new FileReader(config.ajpClientCert)); StringBuffer buff = new StringBuffer(); String line;// w w w. j ava 2 s . c o m while ((line = in.readLine()) != null) { buff.append(line); } in.close(); ajpProperties.setSslCert(buff.toString()); ajpProperties.setSslCipher("ECDHE-RSA-AES256-SHA"); ajpProperties.setSslSession("RANDOMID"); ajpProperties.setSslKeySize("256"); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(1); } } ajpProperties.setRemoteUser(config.ajpUser); ajpProperties.setAuthType("BASIC"); ajpProperties.setContext("/manager"); arh.setProperties(ajpProperties); final Set<String> ajpHosts = new HashSet<String>(); if (config.ajpHosts != null) ajpHosts.addAll(Arrays.asList(config.ajpHosts)); final HttpRequestHandler hrh = rh; return new HttpRequestHandler() { @Override public StreamingResponse handleRequest(InetAddress source, StreamingRequest request, boolean isContinue) throws IOException, MessageFormatException { InetSocketAddress target = request.getTarget(); if (ajpHosts.isEmpty() || ajpHosts.contains(target.getHostName()) || ajpHosts.contains(target.getAddress().getHostAddress())) { return arh.handleRequest(source, request, isContinue); } else { return hrh.handleRequest(source, request, isContinue); } } @Override public void dispose() throws IOException { arh.dispose(); hrh.dispose(); } }; } else { return rh; } }
From source file:com.blogzhou.web.sys.group.service.GroupRelationService.java
public Set<Long> findGroupIds(Long userId, Set<Long> organizationIds) { if (organizationIds.isEmpty()) { return Sets.newHashSet(getGroupRelationRepository().findGroupIds(userId)); }/*from w ww .java 2 s . c o m*/ return Sets.newHashSet(getGroupRelationRepository().findGroupIds(userId, organizationIds)); }
From source file:com.codelanx.voxelregen.command.ListCommand.java
@Override public CommandStatus execute(CommandSender sender, String... args) { Set<String> names = this.plugin.getRegionNames(); if (names.isEmpty()) { Lang.sendMessage(sender, VoxelLang.COMMAND_LIST_NONE); } else {/*w w w . j a v a 2 s . c o m*/ Lang.sendMessage(sender, VoxelLang.COMMAND_LIST_FORMAT, StringUtils.join(names, VoxelLang.COMMAND_LIST_SEPARATOR.get())); } return CommandStatus.SUCCESS; }
From source file:ws.salient.aws.dynamodb.DynamoDBProfilesIT.java
@Test public void getRemoteRepositories() { Set<RemoteRepository> repositories = profiles.getRemoteRepositories(); assertFalse(repositories.isEmpty()); }
From source file:de.cismet.cids.custom.objectrenderer.utils.alkis.AlkisUtils.java
/** * Check if in list of Buchungsstellen, all Buchungsstellen have the same Buchungsart. Return true if all have the * same Buchungsart, false otherwise. The check is realized with adding the buchungsart to a set. As soon the set * contains a second buchungsart, false can be returned. * * @param buchungsstellen DOCUMENT ME! * * @return DOCUMENT ME!//w ww .j av a 2 s.c o m */ public static boolean isListOfSameBuchungsart(final List<Buchungsstelle> buchungsstellen) { final Set<String> set = new HashSet<String>(); for (final Buchungsstelle o : buchungsstellen) { if (set.isEmpty()) { set.add(o.getBuchungsart()); } else { if (set.add(o.getBuchungsart())) { return false; } } } return true; }
From source file:org.mifos.user.domain.UserDetailsValidator.java
private void validateRoles(Set<String> roles, Errors errors) { if (null == roles || roles.isEmpty()) { errors.rejectValue("roles", "user.roles.[not.empty]", "User must be assigned at least one security role"); }//from w w w . jav a2s .c o m }