List of usage examples for java.util HashSet size
public int size()
From source file:org.gbif.ipt.task.Eml2Rtf.java
/** * Add authors section.//from w w w . jav a2 s. com * * @param doc Document * @param eml EML * @throws DocumentException if problem occurs during add */ private void addAuthors(Document doc, Eml eml) throws DocumentException { // Creating set of authors with different names. (first names + last names). HashSet<Agent> tempAgents = new LinkedHashSet<Agent>(); if (exists(eml.getResourceCreator()) && exists(eml.getResourceCreator().getLastName())) { tempAgents.add(eml.getResourceCreator()); } if (exists(eml.getMetadataProvider()) && exists(eml.getMetadataProvider().getLastName())) { tempAgents.add(eml.getMetadataProvider()); } tempAgents.addAll(eml.getAssociatedParties()); // comparing and removing those repeated agents with same name and same address. Collection<Integer> toRemove = new ArrayList<Integer>(); int counter = 0; for (Iterator<Agent> i = tempAgents.iterator(); i.hasNext(); counter++) { if (toRemove.contains(counter)) { i.next(); i.remove(); } else { Agent agentA = i.next(); // when second iterator should be start boolean flag = false; int countTemp = 0; for (Iterator<Agent> j = tempAgents.iterator(); j.hasNext(); countTemp++) { Agent agentB = j.next(); if (flag) { if (equal(agentA.getLastName(), agentB.getLastName()) && equal(agentA.getFirstName(), agentB.getFirstName()) && equal(agentA.getAddress(), agentB.getAddress())) { toRemove.add(countTemp); } } else if (agentA.equals(agentB)) { flag = true; } } } } Agent[] agentsArray = new Agent[tempAgents.size()]; tempAgents.toArray(agentsArray); // Adding authors Paragraph p = new Paragraph(); p.setFont(font); p.setAlignment(Element.ALIGN_CENTER); java.util.List<Agent> affiliations = new ArrayList<Agent>(); int superScriptCounter = 1; for (int c = 0; c < agentsArray.length; c++) { if (exists(agentsArray[c].getLastName())) { if (c != 0) { p.add(", "); } // First Name and Last Name if (exists(agentsArray[c].getFirstName())) { p.add(agentsArray[c].getFirstName() + " "); } p.add(agentsArray[c].getLastName()); // Looking for addresses and organisations of other authors // (superscripts should not be repeated). boolean isRepeated = false; // look into the affiliations array to find any previous repeated agent info. for (int index = 0; index < affiliations.size(); index++) { if (equal(agentsArray[c].getAddress(), affiliations.get(index).getAddress()) && equal(agentsArray[c].getOrganisation(), affiliations.get(index).getOrganisation())) { p.add(createSuperScript(String.valueOf(index + 1))); isRepeated = true; break; } } // if the agent is not repeated. if (!isRepeated) { p.add(createSuperScript(String.valueOf(superScriptCounter))); affiliations.add(agentsArray[c]); superScriptCounter++; } } } doc.add(p); p.clear(); doc.add(Chunk.NEWLINE); tempAgents.clear(); // <AFFILIATIONS> p = new Paragraph(); p.setFont(font); p.setAlignment(Element.ALIGN_JUSTIFIED); for (int c = 0; c < affiliations.size(); c++) { if (c != 0) { p.add("; "); } p.add((c + 1) + " "); if (exists(affiliations.get(c).getOrganisation())) { p.add(affiliations.get(c).getOrganisation() + ", "); } if (exists(affiliations.get(c).getAddress().getAddress())) { p.add(affiliations.get(c).getAddress().getAddress() + ", "); } if (exists(affiliations.get(c).getAddress().getPostalCode())) { p.add(affiliations.get(c).getAddress().getPostalCode() + ", "); } if (exists(affiliations.get(c).getAddress().getCity())) { p.add(affiliations.get(c).getAddress().getCity()); } if (exists(affiliations.get(c).getAddress().getCountry())) { VocabularyConcept concept = vocabManager.get(Constants.VOCAB_URI_COUNTRY) .findConcept(affiliations.get(c).getAddress().getCountry()); // write country in default language as matched from vocabulary or original value if (exists(concept)) { p.add(", " + WordUtils.capitalizeFully(concept.getPreferredTerm(DEFAULT_LANGUAGE).getTitle())); } else { p.add(", " + WordUtils.capitalizeFully(affiliations.get(c).getAddress().getCountry())); } } } doc.add(p); p.clear(); doc.add(Chunk.NEWLINE); // <Corresponding Authors> p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); p.add(new Phrase(getText("rtf.authors") + ": ", fontTitle)); p.setFont(font); boolean isFirst = true; if (exists(eml.getResourceCreator())) { if (exists(eml.getResourceCreator().getFirstName())) { p.add(eml.getResourceCreator().getFirstName() + " "); } p.add(eml.getResourceCreator().getLastName()); if (exists(eml.getResourceCreator().getEmail())) { p.add(" (" + eml.getResourceCreator().getEmail() + ")"); } isFirst = false; } if (exists(eml.getMetadataProvider())) { boolean sameAsCreator = false; if (!isFirst) { sameAsCreator = equal(eml.getMetadataProvider().getAddress(), eml.getResourceCreator().getAddress()) && equal(eml.getMetadataProvider().getEmail(), eml.getResourceCreator().getEmail()); } if (!sameAsCreator) { p.add(", "); if (exists(eml.getMetadataProvider().getFirstName())) { p.add(eml.getMetadataProvider().getFirstName() + " "); } p.add(eml.getMetadataProvider().getLastName()); if (exists(eml.getMetadataProvider().getEmail())) { p.add(" (" + eml.getMetadataProvider().getEmail() + ")"); } } } p.add(Chunk.NEWLINE); doc.add(p); p.clear(); }
From source file:org.epics.archiverappliance.config.DefaultConfigService.java
@Override public Set<String> getPVsForApplianceMatchingRegex(String nameToMatch) { logger.debug("Finding matching names for " + nameToMatch); LinkedList<String> fixedStringParts = new LinkedList<String>(); String[] parts = this.pvName2KeyConverter.breakIntoParts(nameToMatch); Pattern fixedStringParttern = Pattern.compile("[a-zA-Z_0-9-]+"); for (String part : parts) { if (fixedStringParttern.matcher(part).matches()) { logger.debug("Fixed string part " + part); fixedStringParts.add(part);//from w w w. jav a 2 s .c o m } else { logger.debug("Regex string part " + part); } } if (fixedStringParts.size() > 0) { HashSet<String> ret = new HashSet<String>(); HashSet<String> namesSubset = new HashSet<String>(); // This reverse is probably specific to SLAC's namespace rules but it does make a big difference. // Perhaps we can use a more intelligent way of choosing the specific path thru the trie. Collections.reverse(fixedStringParts); for (String fixedStringPart : fixedStringParts) { ConcurrentSkipListSet<String> pvNamesForPart = parts2PVNamesForThisAppliance.get(fixedStringPart); if (pvNamesForPart != null) { if (namesSubset.isEmpty()) { namesSubset.addAll(pvNamesForPart); } else { namesSubset.retainAll(pvNamesForPart); } } } logger.debug("Using fixed string path matching against names " + namesSubset.size()); Pattern pattern = Pattern.compile(nameToMatch); for (String pvName : namesSubset) { if (pattern.matcher(pvName).matches()) { ret.add(pvName); } } return ret; } else { // The use pattern did not have any fixed elements at all. // In this case we do brute force matching; should take longer. // This is also not optimal but probably don't want yet another list of PV's Pattern pattern = Pattern.compile(nameToMatch); HashSet<String> allNames = new HashSet<String>(); HashSet<String> ret = new HashSet<String>(); logger.debug("Using brute force pattern matching against names"); for (ConcurrentSkipListSet<String> pvNamesForPart : parts2PVNamesForThisAppliance.values()) { allNames.addAll(pvNamesForPart); } for (String pvName : allNames) { if (pattern.matcher(pvName).matches()) { ret.add(pvName); } } return ret; } }
From source file:dao.UserpageDaoDb.java
/** * this method returns the second degree of friends * @param userpage - the userpage/*from w w w. ja va 2 s . co m*/ * @param friend1 - the friend1 * @param friend2 - the friend2 * @throws BaseDaoException - when error occurs */ private void getMySecondFriends(Userpage userpage, String friend1, String friend2, int accessFlag) throws BaseDaoException { if ((userpage == null) || (friend1 == null) || (friend2 == null)) { userpage.setSecondFriends(null); return; } /** * friend1 */ Hdlogin hdlogin = getLoginid(friend1); if (hdlogin == null) { return; } String friendid1 = hdlogin.getValue(DbConstants.LOGIN_ID); /** * friend2 */ hdlogin = getLoginid(friend2); if (hdlogin == null) { return; } /** * first query */ String friendid2 = hdlogin.getValue(DbConstants.LOGIN_ID); Object[] params = { (Object) friendid1, (Object) friendid1 }; List result = null; /** * hdlogin, pendingfriends - no partitioned */ /* String sourceName = null; sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null " + sourceName); } */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("friendcheckquery"); } else { queryName = scalabilityManager.getReadZeroScalability("friendcheckquery"); } friendCheckQuery = getQueryMapper().getQuery(queryName); try { result = friendCheckQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query" + friendCheckQuery.getSql(), e); } HashSet hs1 = new HashSet(); if ((result != null) && (result.size() > 0)) { for (int i = 0; i < result.size(); i++) { hs1.add(((Friend) result.get(i)).getValue(DbConstants.FID)); } } Iterator it1; it1 = hs1.iterator(); /** * second query */ params[0] = friendid2; params[1] = friendid2; List result2 = null; try { result2 = friendCheckQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query", e); } HashSet hs2 = new HashSet(); if (result2 != null) { if (result2.size() > 0) { for (int i = 0; i < result2.size(); i++) { hs2.add(((Friend) result2.get(i)).getValue(DbConstants.FID)); } } } /** return the intersection of the two sets */ boolean f = hs1.retainAll(hs2); if (hs1.size() == 0) return; /** get the friendids and get the login names */ Iterator it3; it3 = hs1.iterator(); HashSet friendSet = new HashSet(); Hdlogin friendLogin = null; while (it3.hasNext()) { //HdloginidQuery hQuery = new HdloginidQuery(ds); // friendResult = hdloginidQuery.execute(myParams); friendLogin = getLoginid((String) it3.next()); if (friendLogin != null) { friendSet.add(friendLogin); } } userpage.setSecondFriends(friendSet); }
From source file:org.ramadda.geodata.cdmdata.CdmDataOutputHandler.java
/** * Get the grid dates/*from w ww .java2s .c om*/ * * @param dataset the dataset * * @return the dates or null */ private List<Date> getGridDates(GridDataset dataset) { List<Date> gridDates = null; List<GridDatatype> grids = dataset.getGrids(); HashSet<Date> dateHash = new HashSet<Date>(); List<CoordinateAxis1DTime> timeAxes = new ArrayList<CoordinateAxis1DTime>(); for (GridDatatype grid : grids) { GridCoordSystem gcs = grid.getCoordinateSystem(); CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D(); if ((timeAxis != null) && !timeAxes.contains(timeAxis)) { timeAxes.add(timeAxis); Date[] timeDates = timeAxis.getTimeDates(); for (Date timeDate : timeDates) { dateHash.add(timeDate); } } } if (!dateHash.isEmpty()) { gridDates = Arrays.asList(dateHash.toArray(new Date[dateHash.size()])); Collections.sort(gridDates); } return gridDates; }
From source file:gov.nih.nci.evs.browser.utils.MetaTreeUtils.java
public int getSubconceptCountExt(String scheme, String version, String CUI, String sab, String asso_name, boolean direction) { List<String> par_chd_assoc_list = new ArrayList(); par_chd_assoc_list.add(asso_name);// w w w .j a v a 2s .c o m Map<String, List<BySourceTabResults>> map = null; LexBIGService lbs = RemoteServerUtil.createLexBIGService(); MetaBrowserService mbs = null; try { mbs = (MetaBrowserService) lbs.getGenericExtension("metabrowser-extension"); if (direction) { map = mbs.getBySourceTabDisplay(CUI, sab, par_chd_assoc_list, Direction.SOURCEOF); } else { map = mbs.getBySourceTabDisplay(CUI, sab, par_chd_assoc_list, Direction.TARGETOF); } } catch (Exception ex) { ex.printStackTrace(); return -1; } int knt = 0; HashSet hset = new HashSet(); Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Entry thisEntry = (Entry) it.next(); String rel = (String) thisEntry.getKey(); List<BySourceTabResults> relations = (List<BySourceTabResults>) thisEntry.getValue(); //for (String rel : map.keySet()) { //List<BySourceTabResults> relations = map.get(rel); for (BySourceTabResults result : relations) { String code = result.getCui(); if (code.compareTo(CUI) != 0 && !hset.contains(code)) { hset.add(code); } String name = result.getTerm(); // _logger.debug("(***) subconcept: " + name + " " + code); knt++; } } return hset.size(); }
From source file:com.dell.asm.asmcore.asmmanager.util.ServiceTemplateValidator.java
public void validateServerComponents(ServiceTemplate svcTemplate, final Map<String, String> repoToTaskMap) { for (ServiceTemplateComponent component : safeList(svcTemplate.getComponents())) { boolean installHyperVChecked = false, domainSettingsMissing = false, domainSettingsFilled = false, rhelImage = false, windows2008 = false, isHypervChapValidationExecuted = false; if (component.getType() == ServiceTemplateComponentType.SERVER) { final ServiceTemplateValid componentValid = component.getComponentValid(); ServiceTemplateSetting templateImageType = component .getTemplateSetting(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_TYPE_ID); if (templateImageType != null && StringUtils.isNotEmpty(templateImageType.getValue())) { if (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_REDHAT6_VALUE .equals(templateImageType.getValue()) || ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_REDHAT7_VALUE .equals(templateImageType.getValue())) { rhelImage = true;//from w w w . ja va 2s. c om } else if (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_WINDOWS2008_VALUE .equals(templateImageType.getValue())) { windows2008 = true; } } for (ServiceTemplateCategory category : safeList(component.getResources())) { for (ServiceTemplateSetting setting : safeList(category.getParameters())) { if (!rhelImage && setting.getId() .equalsIgnoreCase(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_RAID_ID)) { if (StringUtils.isNotEmpty(setting.getValue()) && setting.getValue().toLowerCase().contains( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_ADVANCED_NON_RAID_ID)) { LOGGER.error("non-RAID configuration not allowed for non-RHEL images: " + setting.getValue()); componentValid.addMessage(AsmManagerMessages.invalidNonRaidConfiguration()); } } if (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_WINDOWS2008_VALUE .equalsIgnoreCase(setting.getValue()) || ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_WINDOWS2012_VALUE .equalsIgnoreCase(setting.getValue())) { Map<String, ServiceTemplateComponent> map = svcTemplate.fetchComponentsMap(); for (String key : component.getAssociatedComponents().keySet()) { if (map.get(key) != null && map.get(key).getType() == ServiceTemplateComponentType.CLUSTER) { ServiceTemplateCategory cat = svcTemplate.getTemplateResource(map.get(key), ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SCVMM_CLUSTER_COMP_ID); if (cat == null) { componentValid .addMessage(AsmManagerMessages.windowsServerWithVMWareCluster()); } } } } if (setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_HOSTNAME_ID)) { if (StringUtils.isNotEmpty(setting.getValue()) && !HostnameUtil.isValidHostName(setting.getValue(), component)) { ServiceTemplateSetting imageType = component.getTemplateSetting( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_TYPE_ID); if (imageType != null && imageType.getValue() .equals(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_ESXI_VALUE)) { LOGGER.error("Invalid hostname for ESX: " + setting.getValue()); componentValid .addMessage(AsmManagerMessages.invalidEsxHostname(setting.getValue())); } else { LOGGER.error("Invalid hostname: " + setting.getValue()); componentValid .addMessage(AsmManagerMessages.invalidHostname(setting.getValue())); } } } else if (setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_VIRTUALIZATION_ID) && ((component.hasHyperV() || component.hasESX(repoToTaskMap)) && !(setting.getValue().equals("Enabled")))) { LOGGER.error( "BIOS VT must be set for ES or HyperV for server : " + component.getAsmGUID()); componentValid.addMessage(AsmManagerMessages.mustSetBIOSForHypervisor()); } else if (setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_EXECUTE_DISABLE_ID)) { // must be checked for ESX and HyperV if ((component.hasHyperV() || component.hasESX(repoToTaskMap)) && !(setting.getValue().equals("Enabled"))) { LOGGER.error("BIOS Execute Disable must be set for ES or HyperV for server : " + component.getAsmGUID()); componentValid.addMessage(AsmManagerMessages.execDisableCheck()); } } else if (setting.getId() .equalsIgnoreCase(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_IMAGE_ID)) { if (!svcTemplate.isDraft()) { if (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_COMPID_ALL .equals(component.getComponentID()) && component.hasDiskBoot() && (setting.getValue() == null || setting.getValue().equals( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SELECT_ID) || setting.getValue().equals(""))) { LOGGER.error("Missed OS image for server : " + component.getAsmGUID()); componentValid.addMessage(AsmManagerMessages.serverMustHaveOsImage()); } // Validate the external image is actually present if (!getOsRepositoryUtil().isOSRepositoryValid(setting.getValue())) { LOGGER.error("OS Repository in Error state : " + component.getAsmGUID()); componentValid .addMessage(AsmManagerMessages.osRepositoryInvalid(setting.getValue())); } } } else if (setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_HOSTNAME_TEMPLATE_ID)) { if (StringUtils.isNotEmpty(setting.getValue()) && !HostnameUtil.isValidHostNameTemplate(setting.getValue(), component)) { ServiceTemplateSetting imageType = component.getTemplateSetting( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_TYPE_ID); if (imageType != null && imageType.getValue() .equals(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_ESXI_VALUE)) { LOGGER.error("Invalid hostname template for ESX: " + setting.getValue()); componentValid.addMessage( AsmManagerMessages.invalidEsxHostnameTemplate(setting.getValue())); } else { LOGGER.error("Invalid hostname template: " + setting.getValue()); componentValid.addMessage( AsmManagerMessages.invalidHostnameTemplate(setting.getValue())); } } } else if (setting.getId() .equalsIgnoreCase(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_RAID_ID)) { if (StringUtils.isNotEmpty(setting.getValue()) && !validateRAID(setting.getValue())) { LOGGER.error("Invalid RAID configuration: " + setting.getValue()); componentValid.addMessage(AsmManagerMessages.invalidRaidConfiguration()); } } else if (setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_LINUX_NTP_ID)) { // NTP server is required for HyperV if (component.hasHyperV() && StringUtils.isEmpty(setting.getValue())) { LOGGER.error("NTP not set for HyperV for server : " + component.getAsmGUID()); componentValid.addMessage(AsmManagerMessages.mustSetNtpForHypervisor()); } } else if (setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_ID)) { if (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_COMPID_ALL .equals(component.getComponentID()) && (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_SD .equals(setting.getValue()) || ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_SD_RAID_VSAN .equals(setting.getValue()) || ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_SD_RAID .equals(setting.getValue())) && !component.hasESX(repoToTaskMap)) { LOGGER.error("OS Image must be ESX for SD boot types, server : " + component.getAsmGUID()); componentValid.addMessage(AsmManagerMessages.mustHaveESXForSD()); } if (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_COMPID_ALL .equals(component.getComponentID()) && (ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_SD .equals(setting.getValue()) || ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_SD_RAID .equals(setting.getValue()) || ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_SD_RAID_VSAN .equals(setting.getValue()) || ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_AHCI_VSAN .equals(setting.getValue()) || ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_HD .equals(setting.getValue()))) { List<Network> networks = getServiceTemplateUtil().getServerNetworkByType(component, NetworkType.PXE); if (networks.size() == 0) { // Then a PXE Network does NOT exist! LOGGER.error( "Server uses a SD Card or a Local Hard Drive but does not have a PXE Network configured."); componentValid .addMessage(AsmManagerMessages.serverMissingPxeNetworkForBootDevice()); } } } else if (setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_NETWORK_DEFAULT_GATEWAY_ID)) { if (StringUtils.isNotEmpty(setting.getValue()) && !ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_DHCP_NETWORK_ID .equals(setting.getValue())) { List<NetworkType> types = new ArrayList<>(); types.add(NetworkType.PUBLIC_LAN); types.add(NetworkType.PRIVATE_LAN); List<Network> networks = getServiceTemplateUtil().getServerNetworkByType(component, types); boolean found = false; for (Network network : networks) { if (setting.getValue().equals(network.getId())) { found = true; break; } } if (!found) { LOGGER.error( "Selected default gateway network is not included in the network configuration."); componentValid.addMessage(AsmManagerMessages.invalidDefaultGatewayNetwork()); } } } else if (setting.getId().equalsIgnoreCase(ServiceTemplateSettingIDs.LOCAL_STORAGE_ID) && !setting.isHideFromTemplate() && "true".equals(setting.getValue())) { List<Network> netwVSAN = serviceTemplateUtil.getServerNetworkByType(component, NetworkType.VSAN); // normally we would use HashSet<NetworkConfiguration> for duplicate check // but hashCode of NetworkConfiguration has issues (recursive inclusion in iPAddressRanges) and will yeld // different result for same object. I don't want to fix it at this point as it potentially affects large amount of code. // all we need here to ensure unique vlan ID for VSAN networks HashSet<String> duplicateNetworkCheck = new HashSet<>(); for (Network ncfg : netwVSAN) { duplicateNetworkCheck.add(String.valueOf(ncfg.getVlanId())); } if (duplicateNetworkCheck.size() != 1) { LOGGER.error("Number of VSAN networks != 1: " + duplicateNetworkCheck.size()); componentValid.addMessage(AsmManagerMessages.incorrectNumberOfVSANNetworks()); } } if (setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_ID) && (!setting.getValue().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_NONE) && !setting.getValue().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_NONE_WITH_RAID))) { List<ServiceTemplateCategory> compList = component.getResources(); for (ServiceTemplateCategory comp : compList) { if (comp.getId() .equals(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_BIOS_RESOURCE)) { List<ServiceTemplateSetting> paramList = comp.getParameters(); for (ServiceTemplateSetting param : paramList) { if ((param.getId().equals("BootMode") && !param.getValue().equalsIgnoreCase("bios"))) { LOGGER.error( "If Target boot device is not None or None with RAID, BootMode must be BIOS"); componentValid.addMessage(AsmManagerMessages.bootModeCheck()); } } } } } if ((setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_ID) && setting.getValue().equals( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_SD))) { List<ServiceTemplateCategory> compList = component.getResources(); for (ServiceTemplateCategory comp : compList) { if (comp.getId() .equals(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_BIOS_RESOURCE)) { List<ServiceTemplateSetting> paramList = comp.getParameters(); for (ServiceTemplateSetting param : paramList) { if ((param.getId().equals("IntegratedRaid") && param.getValue().equals("Enabled")) || (param.getId().equals("InternalSdCard") && !param.getValue().equals("On"))) { LOGGER.error( "If - Target boot device = SD, IntegratedRaid must not be enabled and IntegratedSd must be On"); componentValid.addMessage(AsmManagerMessages.integratedRaidCheck()); } } } } } if ((setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_ID) && setting.getValue().equals( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_TARGET_BOOTDEVICE_HD))) { List<ServiceTemplateCategory> compList = component.getResources(); for (ServiceTemplateCategory comp : compList) { if (comp.getId() .equals(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_BIOS_RESOURCE)) { List<ServiceTemplateSetting> paramList = comp.getParameters(); for (ServiceTemplateSetting param : paramList) { if ((param.getId().equals("InternalSdCard") && param.getValue().equals("On")) || (param.getId().equals("InternalSdCardRedundancy") && !param.getValue().equals("n/a")) || (param.getId().equals("InternalSdCardPrimaryCard") && !param.getValue().equals("n/a"))) { LOGGER.error( "If - Target boot device = HD, IntegratedSd must be Off, InternalSdCardRedundancy and InternalSdCardPrimaryCard must be NA"); componentValid.addMessage(AsmManagerMessages.integratedSdCheck()); } } } } } if ((setting.getId() .equalsIgnoreCase(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_HV_INSTALL) && setting.getValue().equals("true"))) { installHyperVChecked = true; } if (setting.getId() .equalsIgnoreCase(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_HV_DN_ID) || setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_HV_ADMIN_LOGIN_ID) || setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_HV_FQDN_ID) || setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_DOMAIN_PASSWORD_ID) || setting.getId().equalsIgnoreCase( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_DOMAIN_CONFIRM_PASSWORD_ID)) { if (StringUtils.isEmpty(setting.getValue())) { domainSettingsMissing = true; } else { // at least one domain field is not empty domainSettingsFilled = true; } } if (!windows2008 && ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_HV_DN_ID .equalsIgnoreCase(setting.getId()) && !StringUtils.isBlank(setting.getValue()) && !setting.isHideFromTemplate()) { String domain_login = component.getParameterValue( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_RESOURCE, ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_HV_ADMIN_LOGIN_ID); String domain_pw = component.getParameterValue( ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_RESOURCE, ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_DOMAIN_PASSWORD_ID); if (StringUtils.isBlank(domain_login) || StringUtils.isBlank(domain_pw)) { LOGGER.error( "If domain name is specified for a server component domain admin and domain admin password are required"); componentValid.addMessage(AsmManagerMessages.winDomainFieldsCheck()); } } } } if (windows2008 && domainSettingsFilled) { LOGGER.error("Windows 2008 used with Domain settings"); componentValid.addMessage(AsmManagerMessages.windows2008WithDomainSettings()); } if (installHyperVChecked && domainSettingsMissing) { LOGGER.error( "Install HyperV checked while DomainName or Username or Password or Conf Password is empty"); componentValid.addMessage(AsmManagerMessages.hyperVDomainSettingsMissing()); } if (installHyperVChecked && !isHypervChapValidationExecuted) { if (isHyperVWithChapStorage(svcTemplate, component, isHypervChapValidationExecuted)) { LOGGER.error("For Install HyperV case Equallogic volumes can not have CHAP authentication"); componentValid.addMessage(AsmManagerMessages.hypervEqlChapValidation()); } } this.validateServerWithEqualLogicStorageIsNotUsingStaticIscsiNetwork(svcTemplate, component); this.validateServerComponentsWithStorageHaveTwoPartitionsWithIsciNetworks(svcTemplate, component); if (CollectionUtils.isNotEmpty(componentValid.getMessages())) { componentValid.setValid(Boolean.FALSE); svcTemplate.getTemplateValid().setValid(Boolean.FALSE); } } } }
From source file:org.quantumbadger.redreader.reddit.api.RedditAPIIndividualSubredditListRequester.java
private void doSubredditListRequest(final RedditSubredditManager.SubredditListType type, final RequestResponseHandler<WritableHashSet, SubredditRequestFailure> handler, final String after) { URI uri;//from ww w.j a va 2 s .c o m switch (type) { case SUBSCRIBED: uri = Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_MINE_SUBSCRIBER); break; case MODERATED: uri = Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_MINE_MODERATOR); break; case MOST_POPULAR: uri = Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_POPULAR); break; default: throw new UnexpectedInternalStateException(type.name()); } if (after != null) { // TODO move this logic to General? final Uri.Builder builder = Uri.parse(uri.toString()).buildUpon(); builder.appendQueryParameter("after", after); uri = General.uriFromString(builder.toString()); } final CacheRequest aboutSubredditCacheRequest = new CacheRequest(uri, user, null, Constants.Priority.API_SUBREDDIT_INVIDIVUAL, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.SUBREDDIT_LIST, true, true, false, context) { @Override protected void onCallbackException(Throwable t) { handler.onRequestFailed( new SubredditRequestFailure(RequestFailureType.PARSE, t, null, "Internal error", url)); } @Override protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { } @Override protected void onProgress(final boolean authorizationInProgress, long bytesRead, long totalBytes) { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { handler.onRequestFailed( new SubredditRequestFailure(type, t, status, readableMessage, url.toString())); } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { } @Override public void onJsonParseStarted(JsonValue result, long timestamp, UUID session, boolean fromCache) { try { final HashSet<String> output = new HashSet<String>(); final ArrayList<RedditSubreddit> toWrite = new ArrayList<RedditSubreddit>(); final JsonBufferedObject redditListing = result.asObject().getObject("data"); final JsonBufferedArray subreddits = redditListing.getArray("children"); final JsonBuffered.Status joinStatus = subreddits.join(); if (joinStatus == JsonBuffered.Status.FAILED) { handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE, null, null, "Unknown parse error", url.toString())); return; } if (type == RedditSubredditManager.SubredditListType.SUBSCRIBED && subreddits.getCurrentItemCount() == 0 && after == null) { doSubredditListRequest(RedditSubredditManager.SubredditListType.DEFAULTS, handler, null); return; } for (final JsonValue v : subreddits) { final RedditThing thing = v.asObject(RedditThing.class); final RedditSubreddit subreddit = thing.asSubreddit(); subreddit.downloadTime = timestamp; toWrite.add(subreddit); output.add(subreddit.getCanonicalName()); } RedditSubredditManager.getInstance(context, user).offerRawSubredditData(toWrite, timestamp); final String receivedAfter = redditListing.getString("after"); if (receivedAfter != null && type != RedditSubredditManager.SubredditListType.MOST_POPULAR) { doSubredditListRequest(type, new RequestResponseHandler<WritableHashSet, SubredditRequestFailure>() { public void onRequestFailed(SubredditRequestFailure failureReason) { handler.onRequestFailed(failureReason); } public void onRequestSuccess(WritableHashSet result, long timeCached) { output.addAll(result.toHashset()); handler.onRequestSuccess( new WritableHashSet(output, timeCached, type.name()), timeCached); if (after == null) { Log.i("SubredditListRequester", "Got " + output.size() + " subreddits in multiple requests"); } } }, receivedAfter); } else { handler.onRequestSuccess(new WritableHashSet(output, timestamp, type.name()), timestamp); if (after == null) { Log.i("SubredditListRequester", "Got " + output.size() + " subreddits in 1 request"); } } } catch (Exception e) { handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE, e, null, "Parse error", url.toString())); } } }; CacheManager.getInstance(context).makeRequest(aboutSubredditCacheRequest); }
From source file:org.apache.accumulo.tserver.tablet.Tablet.java
private LookupResult lookup(SortedKeyValueIterator<Key, Value> mmfi, List<Range> ranges, HashSet<Column> columnSet, List<KVEntry> results, long maxResultsSize, long batchTimeOut) throws IOException { LookupResult lookupResult = new LookupResult(); boolean exceededMemoryUsage = false; boolean tabletClosed = false; Set<ByteSequence> cfset = null; if (columnSet.size() > 0) cfset = LocalityGroupUtil.families(columnSet); long returnTime = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(batchTimeOut); if (batchTimeOut <= 0 || batchTimeOut == Long.MAX_VALUE) { batchTimeOut = 0;//from www.j av a 2s. co m } for (Range range : ranges) { boolean timesUp = batchTimeOut > 0 && System.nanoTime() > returnTime; if (exceededMemoryUsage || tabletClosed || timesUp) { lookupResult.unfinishedRanges.add(range); continue; } int entriesAdded = 0; try { if (cfset != null) mmfi.seek(range, cfset, true); else mmfi.seek(range, LocalityGroupUtil.EMPTY_CF_SET, false); while (mmfi.hasTop()) { Key key = mmfi.getTopKey(); KVEntry kve = new KVEntry(key, mmfi.getTopValue()); results.add(kve); entriesAdded++; lookupResult.bytesAdded += kve.estimateMemoryUsed(); lookupResult.dataSize += kve.numBytes(); exceededMemoryUsage = lookupResult.bytesAdded > maxResultsSize; timesUp = batchTimeOut > 0 && System.nanoTime() > returnTime; if (exceededMemoryUsage || timesUp) { addUnfinishedRange(lookupResult, range, key, false); break; } mmfi.next(); } } catch (TooManyFilesException tmfe) { // treat this as a closed tablet, and let the client retry log.warn("Tablet " + getExtent() + " has too many files, batch lookup can not run"); handleTabletClosedDuringScan(results, lookupResult, exceededMemoryUsage, range, entriesAdded); tabletClosed = true; } catch (IOException ioe) { if (shutdownInProgress()) { // assume HDFS shutdown hook caused this exception log.debug("IOException while shutdown in progress ", ioe); handleTabletClosedDuringScan(results, lookupResult, exceededMemoryUsage, range, entriesAdded); tabletClosed = true; } else { throw ioe; } } catch (IterationInterruptedException iie) { if (isClosed()) { handleTabletClosedDuringScan(results, lookupResult, exceededMemoryUsage, range, entriesAdded); tabletClosed = true; } else { throw iie; } } catch (TabletClosedException tce) { handleTabletClosedDuringScan(results, lookupResult, exceededMemoryUsage, range, entriesAdded); tabletClosed = true; } } return lookupResult; }
From source file:evaluation.Evaluator.java
public void evaluateTLExternal(String resultsFile) { BufferedReader br = null;/* w ww . j a va2 s.c o m*/ double accuracy = 0.0; double example_based_precision = 0.0; double example_based_recall = 0.0; double example_based_f = 0.0; HashSet<Integer> labels_in_predictions = new HashSet<Integer>(); int row = 0; try { br = new BufferedReader(new FileReader(resultsFile)); String line; while ((line = br.readLine()) != null) { String predicted_values[] = line.split("\\s+"); predicted_values = removeDuplicates(predicted_values); String tpres = (String) truePredictions.get(row); String true_labels[] = tpres.split("\\s+"); double common_labels = 0; for (int k = 0; k < true_labels.length; k++) // find the common labels { Integer trueLab = Integer.parseInt(true_labels[k]); boolean foundLabel = false; for (int j = 0; j < predicted_values.length; j++) { Integer predLab = Integer.parseInt(predicted_values[j]); if (predLab.intValue() == trueLab.intValue()) { common_labels += 1.0; foundLabel = true; break; } } if (!foundLabel) // this is for label based measures increaseFN(trueLab); } // calculate label based measures for (int j = 0; j < predicted_values.length; j++) { Integer predLab = Integer.parseInt(predicted_values[j]); labels_in_predictions.add(predLab); boolean foundLabel = false; for (int k = 0; k < true_labels.length; k++) { Integer trueLab = Integer.parseInt(true_labels[k]); if (trueLab.intValue() == predLab.intValue()) { increaseTP(trueLab); foundLabel = true; break; } } if (!foundLabel) { increaseFP(predLab); } } accuracy += common_labels / (double) (allLabels(true_labels, predicted_values)); example_based_precision += common_labels / (double) predicted_values.length; example_based_recall += common_labels / (double) true_labels.length; example_based_f += (2 * common_labels / (double) (true_labels.length + predicted_values.length)); row++; } // for each test instance size_of_predicted_label = labels_in_predictions.size(); String output = ""; output += accuracy / (double) row + " "; output += example_based_precision / (double) row + " "; output += example_based_recall / (double) row + " "; output += example_based_f / (double) row + " "; output += macroPrecision() + " "; output += macroRecall() + " "; output += macroFmeasure() + " "; output += microPrecision() + " "; output += microRecall() + " "; output += microFmeasure(); System.out.print(output); if (this.verbosity) { System.out.println("\nAccuracy: " + accuracy / (double) row); System.out.println("EBP :" + example_based_precision / (double) row); System.out.println("EBR :" + example_based_recall / (double) row); System.out.println("EBF :" + example_based_f / (double) row); System.out.println("MaP :" + macroPrecision()); System.out.println("MaR :" + macroRecall()); System.out.println("MaF :" + macroFmeasure()); System.out.println("MiP :" + microPrecision()); System.out.println("MiR :" + microRecall()); System.out.println("MiF :" + microFmeasure()); } } catch (IOException ex) { System.out.println("File not found: " + resultsFile + " or unable to read file"); System.out.println(ex.getMessage()); } catch (NumberFormatException exn) { System.out.println(exn); System.out.println("Line: " + row); } finally { try { if (br != null) { br.close(); } } catch (IOException ex) { System.out.println(ex); } } }
From source file:org.lol.reddit.reddit.api.RedditAPIIndividualSubredditListRequester.java
private void doSubredditListRequest(final RedditSubredditManager.SubredditListType type, final RequestResponseHandler<WritableHashSet, SubredditRequestFailure> handler, final String after) { URI uri;/*w w w. j a va 2 s . c om*/ switch (type) { case SUBSCRIBED: uri = Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_MINE_SUBSCRIBER); break; case MODERATED: uri = Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_MINE_MODERATOR); break; case MOST_POPULAR: uri = Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_POPULAR); break; default: throw new UnexpectedInternalStateException(type.name()); } if (after != null) { // TODO move this logic to General? final Uri.Builder builder = Uri.parse(uri.toString()).buildUpon(); builder.appendQueryParameter("after", after); uri = General.uriFromString(builder.toString()); } final CacheRequest aboutSubredditCacheRequest = new CacheRequest(uri, user, null, Constants.Priority.API_SUBREDDIT_INVIDIVUAL, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.SUBREDDIT_LIST, true, true, false, context) { @Override protected void onCallbackException(Throwable t) { handler.onRequestFailed( new SubredditRequestFailure(RequestFailureType.PARSE, t, null, "Internal error", url)); } @Override protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { } @Override protected void onProgress(long bytesRead, long totalBytes) { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { handler.onRequestFailed( new SubredditRequestFailure(type, t, status, readableMessage, url.toString())); } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { } @Override public void onJsonParseStarted(JsonValue result, long timestamp, UUID session, boolean fromCache) { try { final HashSet<String> output = new HashSet<String>(); final ArrayList<RedditSubreddit> toWrite = new ArrayList<RedditSubreddit>(); final JsonBufferedObject redditListing = result.asObject().getObject("data"); final JsonBufferedArray subreddits = redditListing.getArray("children"); final JsonBuffered.Status joinStatus = subreddits.join(); if (joinStatus == JsonBuffered.Status.FAILED) { handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE, null, null, "Unknown parse error", url.toString())); return; } if (type == RedditSubredditManager.SubredditListType.SUBSCRIBED && subreddits.getCurrentItemCount() == 0 && after == null) { doSubredditListRequest(RedditSubredditManager.SubredditListType.MOST_POPULAR, handler, null); return; } for (final JsonValue v : subreddits) { final RedditThing thing = v.asObject(RedditThing.class); final RedditSubreddit subreddit = thing.asSubreddit(); subreddit.downloadTime = timestamp; toWrite.add(subreddit); output.add(subreddit.getCanonicalName()); } RedditSubredditManager.getInstance(context, user).offerRawSubredditData(toWrite, timestamp); final String receivedAfter = redditListing.getString("after"); if (receivedAfter != null && type != RedditSubredditManager.SubredditListType.MOST_POPULAR) { doSubredditListRequest(type, new RequestResponseHandler<WritableHashSet, SubredditRequestFailure>() { public void onRequestFailed(SubredditRequestFailure failureReason) { handler.onRequestFailed(failureReason); } public void onRequestSuccess(WritableHashSet result, long timeCached) { output.addAll(result.toHashset()); handler.onRequestSuccess( new WritableHashSet(output, timeCached, type.name()), timeCached); if (after == null) { Log.i("SubredditListRequester", "Got " + output.size() + " subreddits in multiple requests"); } } }, receivedAfter); } else { handler.onRequestSuccess(new WritableHashSet(output, timestamp, type.name()), timestamp); if (after == null) { Log.i("SubredditListRequester", "Got " + output.size() + " subreddits in 1 request"); } } } catch (Exception e) { handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE, e, null, "Parse error", url.toString())); } } }; CacheManager.getInstance(context).makeRequest(aboutSubredditCacheRequest); }