List of usage examples for java.util ArrayList isEmpty
public boolean isEmpty()
From source file:com.microfocus.application.automation.tools.pc.PcClient.java
public void waitForRunToPublishOnTrendReport(int runId, String trendReportId) throws PcException, IOException, InterruptedException { ArrayList<PcTrendedRun> trendReportMetaDataResultsList; boolean publishEnded = false; int counterPublishStarted = 0; int counterPublishNotStarted = 0; boolean resultNotFound = true; do {/*from w w w. j a va 2s . c o m*/ trendReportMetaDataResultsList = restProxy.getTrendReportMetaData(trendReportId); if (trendReportMetaDataResultsList.isEmpty()) break; for (PcTrendedRun result : trendReportMetaDataResultsList) { resultNotFound = result.getRunID() != runId; if (resultNotFound) continue; if (result.getState().equals(PcBuilder.TRENDED) || result.getState().equals(PcBuilder.ERROR)) { publishEnded = true; logger.println(String.format("%s - Run: %s %s: %s", dateFormatter.getDate(), runId, Messages.PublishingStatus(), result.getState())); break; } else { Thread.sleep(5000); counterPublishStarted++; if (counterPublishStarted >= 120) { String msg = String.format("%s: %s", Messages.Error(), Messages.PublishingEndTimeout()); throw new PcException(msg); } } } if (!publishEnded && resultNotFound) { Thread.sleep(5000); counterPublishNotStarted++; if (counterPublishNotStarted >= 120) { //waiting 10 minutes for timeout String msg = String.format("%s", Messages.PublishingStartTimeout()); throw new PcException(msg); } else if (counterPublishNotStarted % 12 == 0) { //warning every minute until timeout logger.println(String.format("%s - %s. %s: %s ... ", dateFormatter.getDate(), Messages.WaitingForTrendReportToStart(), Messages.MinutesUntilTimeout(), 10 - (counterPublishNotStarted / 12))); } } } while (!publishEnded && counterPublishStarted < 120 && counterPublishNotStarted < 120); }
From source file:com.app.util.browser.BrowserSniffer.java
private void sniffOS() throws Exception { // look for Windows Box // eg: Windows NT 5.0 // [0] = Windows NT 5.0 // [1] = Windows // [2] = NT/*from w ww.j av a 2 s.com*/ // [3] = 5.0 ArrayList matches = getMatches(WindowsPat, ua, 4); if (!matches.isEmpty()) { String[] versionParticulars = (String[]) matches.get(0); String v1 = versionParticulars[2]; String v2 = versionParticulars[3]; // Establish NT 6.0 as Windows Vista if (StringUtils.contains(v1, "nt") && StringUtils.equals(v2, "6.0")) v1 = "vista"; // Establish NT 5.2 as Windows Server 2003 or XP 64 else if (StringUtils.contains(v1, "nt") && StringUtils.equals(v2, "5.2")) v1 = "2003"; // Establish NT 5.1 as Windows XP else if (StringUtils.contains(v1, "nt") && StringUtils.equals(v2, "5.1")) v1 = "xp"; // Establish NT 5.0 and Windows 2000 as win2k else if (StringUtils.equals(v1, "2000")) v1 = "2000"; else if (StringUtils.contains(v1, "nt") && StringUtils.contains(v2, "5.0")) v1 = "2000"; // Establish NT 4.0 as winnt else if (StringUtils.contains(v1, "nt") && (StringUtils.contains(v2, "4.0") || StringUtils.contains(v2, "3.51") || StringUtils.contains(v2, "3.5") || StringUtils.contains(v2, "3.1"))) v1 = "nt"; // Establish 9x 4.90 as Windows 98 else if (StringUtils.contains(v1, "9x") && StringUtils.equals(v2, "98")) v1 = "98"; // See if we're running windows 3.1 else if (StringUtils.equals(StringUtils.join(new String[] { v1, v2 }), "16bit")) v1 = "31"; // otherwise display as is (31,95,98,NT,ME,XP) else v1 = StringUtils.join(new String[] { v1, v2 }); if (StringUtils.isEmpty(v1)) { final Matcher matcher = NumberRetrievePat.matcher(versionParticulars[0]); if (matcher.matches()) { v1 = matcher.group(matcher.groupCount()); if (StringUtils.contains(versionParticulars[0], "nt")) v1 = "nt"; } else { v1 = PLATFORM_WIN; } } os = v1; platform = PLATFORM_WIN; return; } // look for amiga OS // eg: Amiga-AWeb/3.5.07 beta // [0] = Amiga matches = getMatches(AmigaPat, ua, 1); if (!matches.isEmpty()) { platform = PLATFORM_AMIGA; if (StringUtils.contains(ua, "morphos")) os = "morphos"; else if (StringUtils.contains(ua, "mc680x0")) os = "mc680x0"; else if (StringUtils.contains(ua, "ppc")) os = "ppc"; else { matches = getMatches(AmigaVerPat, ua, 2); if (!matches.isEmpty()) { int count = matches.size() - 1; String[] versionParticulars = (String[]) matches.get(count); os = versionParticulars[1]; } } return; } // look for OS2 matches = getMatches(Os2Pat, ua, 1); if (!matches.isEmpty()) { platform = PLATFORM_OS2; os = PLATFORM_OS2; return; } // look for mac // sets: platform = mac ; os = 68k or ppc matches = getMatches(MacPat, ua, 5); if (!matches.isEmpty()) { platform = PLATFORM_MAC; int count = matches.size() - 1; String[] versionParticulars = (String[]) matches.get(count); os = (StringUtils.isNotEmpty(versionParticulars[1])) ? "68k" : StringUtils.EMPTY; os = (StringUtils.isNotEmpty(versionParticulars[2])) ? "osx" : os; os = (StringUtils.isNotEmpty(versionParticulars[3])) ? "osx" : os; os = (StringUtils.isNotEmpty(versionParticulars[4])) ? "ppc" : os; return; } // look for *nix boxes // sunos sets: platform = *nix ; os = sun|sun4|sun5|suni86 matches = getMatches(SunosPat, ua, 3); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; int count = matches.size() - 1; String[] versionParticulars = (String[]) matches.get(count); if (!StringUtils.contains("sun", versionParticulars[1])) versionParticulars[1] = StringUtils.join(new String[] { "sun", versionParticulars[1] }); os = StringUtils.join(new String[] { versionParticulars[1], versionParticulars[2] }); return; } // irix sets: platform = *nix ; os = irix|irix5|irix6|... matches = getMatches(IrixPat, ua, 3); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; int count = matches.size() - 1; String[] versionParticulars = (String[]) matches.get(count); os = StringUtils.join(new String[] { versionParticulars[1], versionParticulars[2] }); return; } // hp-ux sets: platform = *nix ; os = hpux9|hpux10|... matches = getMatches(HpuxPat, ua, 3); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; int count = matches.size() - 1; String[] versionParticulars = (String[]) matches.get(count); versionParticulars[1] = StringUtils.replace(versionParticulars[1], "-", StringUtils.EMPTY); os = StringUtils.join(new String[] { versionParticulars[1], StringUtils.trim(versionParticulars[2]) }); return; } // aix sets: platform = *nix ; os = aix|aix1|aix2|aix3|... matches = getMatches(AixPat, ua, 2); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; int count = matches.size() - 1; String[] versionParticulars = (String[]) matches.get(count); os = StringUtils.join(new String[] { "aix", versionParticulars[1] }); return; } // dec sets: platform = *nix ; os = dec matches = getMatches(DecPat, ua, 1); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; os = "dec"; return; } // vms sets: platform = *nix ; os = vms matches = getMatches(VmsPat, ua, 1); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; os = "vms"; return; } // sco sets: platform = *nix ; os = sco matches = getMatches(ScoPat, ua, 1); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; os = "sco"; return; } // unixware sets: platform = *nix ; os = unixware if (StringUtils.contains(ua, "'unix_system_v'")) { platform = PLATFORM_UNIX; os = "unixware"; return; } // mpras sets: platform = *nix ; os = mpras if (StringUtils.contains(ua, "'ncr'")) { platform = PLATFORM_UNIX; os = "mpras"; return; } // reliant sets: platform = *nix ; os = reliant if (StringUtils.contains(ua, "'reliantunix'")) { platform = PLATFORM_UNIX; os = "reliant"; return; } // sinix sets: platform = *nix ; os = sinix if (StringUtils.contains(ua, "'sinix'")) { platform = PLATFORM_UNIX; os = "sinix"; return; } // bsd sets: platform = *nix ; os = bsd|freebsd matches = getMatches(BsdPat, ua, 3); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; int count = matches.size() - 1; String[] versionParticulars = (String[]) matches.get(count); os = StringUtils.join(new String[] { versionParticulars[1], versionParticulars[2] }); return; } // linux sets: platform = *nix ; os = linux matches = getMatches(LinuxPat, ua, 1); if (!matches.isEmpty()) { platform = PLATFORM_UNIX; os = "linux"; return; } platform = PLATFORM_OTHER; os = "unknown"; }
From source file:com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedTaskExtensionHandler_V1.java
@Override public ExecutionResult toExecutionResult(String responseBody) { ExecutionResult executionResult = new ExecutionResult(); ArrayList<String> exceptions = new ArrayList<>(); try {/*from ww w . j a va 2 s .co m*/ Map result = (Map) new GsonBuilder().create().fromJson(responseBody, Object.class); if (!(result.containsKey("success") && result.get("success") instanceof Boolean)) { exceptions.add( "The Json for Execution Result must contain a not-null 'success' field of type Boolean"); } if (result.containsKey("message") && (!(result.get("message") instanceof String))) { exceptions.add( "If the 'message' key is present in the Json for Execution Result, it must contain a not-null message of type String"); } if (!exceptions.isEmpty()) { throw new RuntimeException(StringUtils.join(exceptions, ", ")); } if ((Boolean) result.get("success")) { executionResult.withSuccessMessages((String) result.get("message")); } else { executionResult.withErrorMessages((String) result.get("message")); } return executionResult; } catch (Exception e) { LOGGER.error( "Error occurred while converting the Json to Execution Result. Error: {}. The Json received was '{}'.", e.getMessage(), responseBody); throw new RuntimeException(String.format( "Error occurred while converting the Json to Execution Result. Error: %s.", e.getMessage())); } }
From source file:me.code4fun.roboq.Request.java
private String makeUrl(String url, Options opts) { String url1 = url;/*from www.j av a 2 s .c om*/ // expand path vars for (Map.Entry<String, Object> entry : opts.getPathVars().entrySet()) { String k = entry.getKey(); url1 = url1.replace("${" + k + "}", o2s(entry.getValue(), "")); } // params ArrayList<NameValuePair> nvl = new ArrayList<NameValuePair>(); for (Map.Entry<String, Object> entry : opts.getParams().entrySet()) { nvl.add(new BasicNameValuePair(entry.getKey(), o2s(entry.getValue(), ""))); } if (nvl.isEmpty()) { return url1; } else { return url1 + "?" + URLEncodedUtils.format(nvl, selectValue(paramsEncoding, prepared != null ? prepared.paramsEncoding : null, "UTF-8")); } }
From source file:hudson.plugins.jobConfigHistory.FileHistoryDao.java
boolean hasDuplicateHistory(Node node) { final String content = Jenkins.XSTREAM2.toXML(node); boolean isDuplicated = false; final ArrayList<String> timeStamps = new ArrayList<String>(getRevisions(node).keySet()); if (!timeStamps.isEmpty()) { Collections.sort(timeStamps, Collections.reverseOrder()); final XmlFile lastRevision = getOldRevision(node, timeStamps.get(0)); try {//from w ww.ja v a 2s. co m if (content.equals(lastRevision.asString())) { isDuplicated = true; } } catch (IOException e) { LOG.log(Level.WARNING, "unable to check for duplicate previous history file: {0}\n{1}", new Object[] { lastRevision, e }); } } return isDuplicated; }
From source file:com.ottogroup.bi.streaming.sink.elasticsearch.ElasticsearchSink.java
/** * Initializes the {@link ElasticsearchSink} using the provided input * @param clusterName//from w ww . ja v a2 s . c om * @param index * @param type * @param transportAddresses * @param statsdHost * @param statsdPort * @param statsPrefix */ public ElasticsearchSink(final String clusterName, final String index, final String type, final ArrayList<ElasticsearchNodeAddress> transportAddresses, final String statsdHost, final int statsdPort, final String statsdPrefix) { //////////////////////////////////////////////////////////////////////////////////////////////// // validate provided input if (StringUtils.isBlank(clusterName)) throw new IllegalArgumentException("Missing required cluster name"); if (StringUtils.isBlank(index)) throw new IllegalArgumentException("Missing required index to write documents into"); if (StringUtils.isBlank(type)) throw new IllegalArgumentException("Missing required document type to use when indexing"); if (transportAddresses == null || transportAddresses.isEmpty()) throw new IllegalArgumentException( "Missing required transport addresses to establish a connection with the elasticsearch cluster"); boolean nonEmptyAddressFound = false; for (final ElasticsearchNodeAddress ta : transportAddresses) { if (StringUtils.isNotBlank(ta.getHost()) && ta.getPort() > 0) { nonEmptyAddressFound = true; break; } } if (!nonEmptyAddressFound) throw new IllegalArgumentException( "No valid address found in configuration to establish a connection with the elasticsearch cluster"); //////////////////////////////////////////////////////////////////////////////////////////////// this.transportAddresses.addAll(transportAddresses); this.clusterName = clusterName; this.index = index; this.type = type; this.statsdHost = statsdHost; this.statsdPort = statsdPort; this.statsdPrefix = statsdPrefix; }
From source file:edu.isi.misd.scanner.network.registry.web.controller.AnalysisToolController.java
@RequestMapping(value = BASE_PATH, method = { RequestMethod.GET, RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE) public @ResponseBody List<AnalysisTool> getAnalysisTools(@RequestParam Map<String, String> paramMap) { Map<String, String> params = validateParameterMap(paramMap, REQUEST_PARAM_USER_NAME, REQUEST_PARAM_STUDY_ID, REQUEST_PARAM_DATASET_ID, REQUEST_PARAM_LIBRARY_ID); if (!params.isEmpty()) { ArrayList<String> missingParams = new ArrayList<String>(); String userName = params.get(REQUEST_PARAM_USER_NAME); if (userName == null) { missingParams.add(REQUEST_PARAM_USER_NAME); }//from w w w . j a v a2 s . co m String studyId = params.get(REQUEST_PARAM_STUDY_ID); if (studyId == null) { missingParams.add(REQUEST_PARAM_STUDY_ID); } String dataSetId = params.get(REQUEST_PARAM_DATASET_ID); if (dataSetId == null) { missingParams.add(REQUEST_PARAM_DATASET_ID); } String libraryId = params.get(REQUEST_PARAM_LIBRARY_ID); if (libraryId == null) { missingParams.add(REQUEST_PARAM_LIBRARY_ID); } if (!missingParams.isEmpty()) { throw new BadRequestException("Required parameter(s) missing: " + missingParams); } return analysisToolRepository.findAnalysisToolByStudyPolicyStatement(userName, validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId), validateIntegerParameter(REQUEST_PARAM_DATASET_ID, dataSetId), validateIntegerParameter(REQUEST_PARAM_LIBRARY_ID, libraryId)); } List<AnalysisTool> toolLibraries = new ArrayList<AnalysisTool>(); Iterator iter = analysisToolRepository.findAll().iterator(); CollectionUtils.addAll(toolLibraries, iter); return toolLibraries; }
From source file:hudson.plugins.jobConfigHistory.FileHistoryDao.java
/** * Determines if the {@link XmlFile} contains a duplicate of * the last saved information, if there is previous history. * * @param xmlFile/*from w w w.j a v a 2 s.c om*/ * The {@link XmlFile} configuration file under consideration. * @return true if previous history is accessible, and the file duplicates the previously saved information. */ boolean hasDuplicateHistory(XmlFile xmlFile) { boolean isDuplicated = false; final ArrayList<String> timeStamps = new ArrayList<String>(getRevisions(xmlFile).keySet()); if (!timeStamps.isEmpty()) { Collections.sort(timeStamps, Collections.reverseOrder()); final XmlFile lastRevision = getOldRevision(xmlFile, timeStamps.get(0)); try { if (xmlFile.asString().equals(lastRevision.asString())) { isDuplicated = true; } } catch (IOException e) { LOG.log(Level.WARNING, "unable to check for duplicate previous history file: {0}\n{1}", new Object[] { lastRevision, e }); } } return isDuplicated; }
From source file:org.getlantern.firetweet.util.net.FiretweetHostAddressResolver.java
private InetAddress[] resolveInternal(String originalHost, String host) throws IOException { if (isValidIpAddress(host)) return fromAddressString(originalHost, host); // First, I'll try to load address cached. if (mHostCache.containsKey(host)) { final InetAddress[] hostAddr = mHostCache.get(host); if (Utils.isDebugBuild()) { Log.d(RESOLVER_LOGTAG, "Got cached " + Arrays.toString(hostAddr)); }/*from w w w.ja v a2 s . c o m*/ return hostAddr; } // Then I'll try to load from custom host mapping. // Stupid way to find top domain, but really fast. if (mHostMapping.contains(host)) { final String mappedAddr = mHostMapping.getString(host, null); if (mappedAddr != null) { final InetAddress[] hostAddr = fromAddressString(originalHost, mappedAddr); mHostCache.put(originalHost, hostAddr); if (Utils.isDebugBuild()) { Log.d(RESOLVER_LOGTAG, "Got mapped " + Arrays.toString(hostAddr)); } return hostAddr; } } mSystemHosts.reloadIfNeeded(); if (mSystemHosts.contains(host)) { final InetAddress[] hostAddr = fromAddressString(originalHost, mSystemHosts.getAddress(host)); mHostCache.put(originalHost, hostAddr); if (Utils.isDebugBuild()) { Log.d(RESOLVER_LOGTAG, "Got hosts " + Arrays.toString(hostAddr)); } return hostAddr; } final String customMappedHost = findHost(host); if (customMappedHost != null) { final InetAddress[] hostAddr = fromAddressString(originalHost, customMappedHost); mHostCache.put(originalHost, hostAddr); if (Utils.isDebugBuild()) { Log.d(RESOLVER_LOGTAG, "Got mapped address " + customMappedHost + " for host " + host); } return hostAddr; } // Use TCP DNS Query if enabled. final Resolver dns = getResolver(); if (dns != null && mPreferences.getBoolean(KEY_TCP_DNS_QUERY, false)) { final Lookup lookup = new Lookup(new Name(host), Type.A, DClass.IN); final Record[] records; lookup.setResolver(dns); lookup.run(); final int result = lookup.getResult(); if (result != Lookup.SUCCESSFUL) { throw new UnknownHostException("Unable to resolve " + host + ", " + lookup.getErrorString()); } records = lookup.getAnswers(); final ArrayList<InetAddress> resolvedAddresses = new ArrayList<>(); // Test each IP address resolved. for (final Record record : records) { if (record instanceof ARecord) { final InetAddress ipv4Addr = ((ARecord) record).getAddress(); resolvedAddresses.add(InetAddress.getByAddress(originalHost, ipv4Addr.getAddress())); } else if (record instanceof AAAARecord) { final InetAddress ipv6Addr = ((AAAARecord) record).getAddress(); resolvedAddresses.add(InetAddress.getByAddress(originalHost, ipv6Addr.getAddress())); } } if (!resolvedAddresses.isEmpty()) { final InetAddress[] hostAddr = resolvedAddresses.toArray(new InetAddress[resolvedAddresses.size()]); mHostCache.put(originalHost, hostAddr); if (Utils.isDebugBuild()) { Log.d(RESOLVER_LOGTAG, "Resolved " + Arrays.toString(hostAddr)); } return hostAddr; } // No address is reachable, but I believe the IP is correct. for (final Record record : records) { if (record instanceof CNAMERecord) return resolveInternal(originalHost, ((CNAMERecord) record).getTarget().toString()); } } if (Utils.isDebugBuild()) { Log.w(RESOLVER_LOGTAG, "Resolve address " + host + " failed, using original host"); } final InetAddress[] defaultAddresses = InetAddress.getAllByName(host); mHostCache.put(host, defaultAddresses); return defaultAddresses; }
From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java
/** * Checks to make sure that the current page has no duplicate dots *//* w w w .java 2 s .c o m*/ private boolean checkNoDuplicates() { ArrayList<String> names = new ArrayList<>(); ArrayList<String> badNames = new ArrayList<>(); PointConcurrentHashMap<Point, String> dots = Main.getCurrentPage().getDots(); for (String s : dots.values()) { if (!names.contains(s)) names.add(s); else badNames.add(s); } if (!badNames.isEmpty()) { String str = "The following players have more than one dot on the page:\n"; for (String s : badNames) str += s + "\n"; str += "\nTo data from the first page to the second page, navigate to the second page and click \"Play\"."; JOptionPane.showMessageDialog(this, str.trim(), "Conflicts!", JOptionPane.ERROR_MESSAGE); return false; } return checkNoDuplicates(Main.getState().getCurrentPage() - 1); }