/** * Invokes a test method of the subclass using reflection API. Handles the method results and sets * its status. * * @param meth the subclass' method to invoke * @param methName the name of the method */ protected void invokeTestMethod(Method meth, String methName) { if (meth == null) { setStatus(methName, Status.skipped(false)); } else { Status stat; try { meth.invoke(this, new Object[0]); return; } catch (InvocationTargetException itE) { Throwable t = itE.getTargetException(); if (t instanceof StatusException) { stat = ((StatusException) t).getStatus(); } else { t.printStackTrace(log); stat = Status.exception(t); } } catch (IllegalAccessException iaE) { iaE.printStackTrace(log); stat = Status.exception(iaE); } catch (IllegalArgumentException iaE) { iaE.printStackTrace(log); stat = Status.exception(iaE); } catch (ClassCastException ccE) { ccE.printStackTrace(log); stat = Status.exception(ccE); } setStatus(methName, stat); } }
@Test public void testCleanDirsWithSubmodule() throws Exception { SubmoduleAddCommand command = new SubmoduleAddCommand(db); String path = "sub"; command.setPath(path); String uri = db.getDirectory().toURI().toString(); command.setURI(uri); Repository repo = command.call(); repo.close(); Status beforeCleanStatus = git.status().call(); assertTrue(beforeCleanStatus.getAdded().contains(DOT_GIT_MODULES)); assertTrue(beforeCleanStatus.getAdded().contains(path)); Set<String> cleanedFiles = git.clean().setCleanDirectories(true).call(); // The submodule should not be cleaned. assertTrue(!cleanedFiles.contains(path + "/")); assertTrue(cleanedFiles.contains("File2.txt")); assertTrue(cleanedFiles.contains("File3.txt")); assertTrue(!cleanedFiles.contains("sub-noclean/File1.txt")); assertTrue(cleanedFiles.contains("sub-noclean/File2.txt")); assertTrue(cleanedFiles.contains("sub-clean/")); assertTrue(cleanedFiles.size() == 4); }
public static void main(String[] args) throws TwitterException, IOException { Twitter twitter = TwitterFactory.getSingleton(); JLanguageTool langTool = new JLanguageTool(new AmericanEnglish()); List<String> twts = new ArrayList<String>(); for (String arg : args) { Query query = new Query(arg); QueryResult result; int counter = 0; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { if (isEligible(tweet)) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); System.out.println(tweet.getLang()); twts.add(tweet.getText()); counter++; } } } while ((query = result.nextQuery()) != null && counter < 5); } for (String str : twts) { List<RuleMatch> matches = langTool.check(str); for (RuleMatch match : matches) { System.out.println( "Potential error at line " + match.getLine() + ", column " + match.getColumn() + ": " + match.getMessage()); System.out.println("Suggested correction: " + match.getSuggestedReplacements()); } } }
public boolean isError() { if (status != null && status.getCode() != null && status.getCode() >= 400) { return true; } return false; }
public static void printTweets( String keywords, String location, Integer limit, Boolean hideRetweets) throws TwitterException, URLs.ConnectionException, GeolocationSearch.SearchLocationException, MalformedURLException, GeolocationSearch.NoKeyException, URLs.HTTPQueryException { Twitter twitter = new TwitterFactory().getInstance(); Query query = new Query(keywords); query.setGeoCode(getLocation(location), RADIUS, Query.KILOMETERS); Integer needTweets; Integer numberTweets = 0; if (limit == Integer.MAX_VALUE) { needTweets = NUMBER_TWEETS; } else { needTweets = limit; } QueryResult result; List<Status> tweets; do { result = twitter.search(query); tweets = result.getTweets(); for (Status tweet : tweets) { if (!(hideRetweets && tweet.isRetweet()) && (numberTweets < needTweets)) { printTweet(tweet, false); numberTweets++; } } query = result.nextQuery(); } while ((numberTweets < needTweets) && (query != null)); if (numberTweets == 0) { System.out.println("Твитов по заданному запросу не найдено."); } else { System.out.println(SEPARATOR); } }
private List<Long> obtainReadIds(List<Status> statusList) { List<Long> idsToCheck = new ArrayList<Long>(statusList.size()); for (Status status : statusList) { idsToCheck.add(status.getId()); } return th.getReadIds(idsToCheck); }
/** * Custom deserialization routine used during deserialization of a Session/PersistenceContext for * increased performance. * * @param ois The stream from which to read the entry. * @param persistenceContext The context being deserialized. * @return The deserialized EntityEntry * @throws IOException If a stream error occurs * @throws ClassNotFoundException If any of the classes declared in the stream cannot be found */ public static EntityEntry deserialize( ObjectInputStream ois, PersistenceContext persistenceContext) throws IOException, ClassNotFoundException { String previousStatusString; return new EntityEntry( // this complexity comes from non-flushed changes, should really look at how that reattaches // entries (persistenceContext.getSession() == null ? null : persistenceContext.getSession().getFactory()), (String) ois.readObject(), (Serializable) ois.readObject(), EntityMode.parse((String) ois.readObject()), (String) ois.readObject(), Status.valueOf((String) ois.readObject()), ((previousStatusString = (String) ois.readObject()).length() == 0 ? null : Status.valueOf(previousStatusString)), (Object[]) ois.readObject(), (Object[]) ois.readObject(), ois.readObject(), LockMode.valueOf((String) ois.readObject()), ois.readBoolean(), ois.readBoolean(), ois.readBoolean(), persistenceContext); }
public static void printTweet(Status tweet, boolean isStream) { String time; if (isStream) { time = ""; try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException ie) { ie.printStackTrace(); } } else { time = getTimeForm(tweet) + " "; } System.out.println(SEPARATOR); String uName = tweet.getUser().getScreenName(); String text = tweet.getText(); Integer retweets = tweet.getRetweetCount(); if (tweet.isRetweet()) { Pattern myPattern = Pattern.compile("RT @([^ ]*): (.*)"); Matcher m = myPattern.matcher(text); m.find(); String uRTName = m.group(1); text = m.group(2); System.out.println(time + "@" + uName + ": ретвитнул @" + uRTName + ": " + text); } else { System.out.println(time + "@" + uName + ": " + text + retweetsForm(retweets)); } }
public static List<Status> filterStatusListByTimeThreshold(List<Status> rawList, long threshold) { List<Status> filteredList = new ArrayList<Status>(); for (Status s : rawList) { if (s.getDate() >= threshold) filteredList.add(s); } return filteredList; }
/** * Builds the JSON format response string. * * @return the JSON format response string * @throws JSONException if error occurs when building the JSONObject */ public String build() throws JSONException { JSONObject result = new JSONObject(); Iterator<JsonField> iterator = values.keySet().iterator(); while (iterator.hasNext()) { JsonField key = iterator.next(); Object value = values.get(key); if (value != null) { switch (key) { case STATUS: { Status status = (Status) value; result.put("status", status.toJsonString()); break; } case IDP: { result.put("idp", value); break; } case DISPLAY_NAME: { result.put("displayName", value); break; } case PHOTO_URL: { result.put("photoUrl", value); break; } } } } return result.toString(); }
@Override public void nextTuple() { // emit tweets Status status = statuses.poll(); if (status == null) Utils.sleep(1000); else { ResponseList<User> followers; ResponseList<User> friends; try { Thread.sleep(6000); followers = twitter.getFollowersList(status.getUser().getScreenName(), -1); Thread.sleep(6000); friends = twitter.getFriendsList(status.getUser().getScreenName(), -1); if (!followers.isEmpty() && !friends.isEmpty()) { spoutOutputCollector.emit(new Values(status, followers, friends)); } // followers.clear(); // friends.clear(); } catch (TwitterException ex) { ex.printStackTrace(); } catch (InterruptedException ex) { ex.printStackTrace(); } } }
/** * This is the command-line entry point for JRuby, and should ONLY be used by Java when starting * up JRuby from a command-line. Use other mechanisms when embedding JRuby into another * application. * * @param args command-line args, provided by the JVM. */ public static void main(String[] args) { doGCJCheck(); Main main; if (DripMain.DRIP_RUNTIME != null) { main = new Main(DripMain.DRIP_CONFIG, true); } else { main = new Main(true); } try { Status status = main.run(args); if (status.isExit()) { System.exit(status.getStatus()); } } catch (RaiseException rj) { System.exit(handleRaiseException(rj)); } catch (Throwable t) { // print out as a nice Ruby backtrace System.err.println(ThreadContext.createRawBacktraceStringFromThrowable(t)); while ((t = t.getCause()) != null) { System.err.println("Caused by:"); System.err.println(ThreadContext.createRawBacktraceStringFromThrowable(t)); } System.exit(1); } }
/** * Merge. * * @param other the other */ public void merge(final Activity other) { if (other.summary != null) { summary = other.summary; } if (other.description != null) { description = other.description; } if (other.agent != null) { agent = other.agent; } if (other.constraints != null) { if (constraints != null) { constraints.merge(other.constraints); } else { constraints = other.constraints.clone(); } } if (other.status != null) { if (status != null) { status.merge(other.status); } else { status = other.status.clone(); } } status.merge(other.status); }
@SuppressWarnings("unchecked") public void applyUpdateObject(Map<String, Object> updateData) { List<Map<String, Object>> updatedNodes = (List<Map<String, Object>>) updateData.get("nodes"); for (Map<String, Object> node : updatedNodes) { String jobId = (String) node.get("jobId"); Status status = Status.fromInteger((Integer) node.get("status")); long startTime = JSONUtils.getLongFromObject(node.get("startTime")); long endTime = JSONUtils.getLongFromObject(node.get("endTime")); long updateTime = JSONUtils.getLongFromObject(node.get("updateTime")); ExecutableNode exNode = executableNodes.get(jobId); exNode.setEndTime(endTime); exNode.setStartTime(startTime); exNode.setUpdateTime(updateTime); exNode.setStatus(status); int attempt = 0; if (node.containsKey("attempt")) { attempt = (Integer) node.get("attempt"); if (attempt > 0) { exNode.updatePastAttempts((List<Object>) node.get("pastAttempts")); } } exNode.setAttempt(attempt); } this.flowStatus = Status.fromInteger((Integer) updateData.get("status")); this.startTime = JSONUtils.getLongFromObject(updateData.get("startTime")); this.endTime = JSONUtils.getLongFromObject(updateData.get("endTime")); this.updateTime = JSONUtils.getLongFromObject(updateData.get("updateTime")); }
public static Status getById(int id) { for (Status l : Status.values()) { if (l.getId() == id) { return l; } } return null; }
@Test public void testToResponse() { for (final Status status : Status.REGISTERED_STATUSES.values()) { final Response response = status.toResponse(); assertTrue(response.status().equals(status)); assertTrue(response.entity().get().equals(status.message())); } }
public void changeStatus(String name, String status) { Status s = mStatus.get(name); if (s == null) { s = new Status(); mStatus.put(name, s); } s.value = status; }
private void input(String source) { Status status = powerOn(); while (!status.getInput().equals(source)) { post(XMLYamaha.input(source)); sleep(1); status = getStatus(); } }
private Status powerOn() { Status status = getStatus(); while (status == null || !status.isPowerOn()) { post(powerOnXml()); sleep(1); status = getStatus(); } return status; }
public static Status getStatusValue(final String text) { final Status[] values = values(); for (final Status value : values) { if (value.toString().equals(text)) { return value; } } throw new IllegalArgumentException(text + " is not a valid status."); }
private boolean matchPath(Template input, Status status) { Path segment; Iterator<Path> segments = input.getPath().iterator(); while (segments.hasNext() && status.hasCandidates()) { segment = segments.next(); pickMatchingChildren(segment, status); } return status.hasCandidates(); }
public int getHighestLevel(long threshold) { List<Status> filteredList = filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), threshold); int maxLevel = Status.INFO; for (Status s : filteredList) { if (s.getLevel() > maxLevel) maxLevel = s.getLevel(); } return maxLevel; }
protected static Status createStatus( final String basename, final int state, final int pid, final String msg, final Throwable t) { final Status status = new Status(basename); status.state = state; status.pid = pid; status.msg = msg; status.exception = t; return status; }
public static boolean isEligible(Status tweet) { if (!tweet.getLang().equalsIgnoreCase("en")) { return false; } else if (tweet.isRetweet()) { return false; } else { return true; } }
/* * Favorites the specified tweet, returning true in case of success. * If error, returns false. */ public boolean doFav(Status tweet) { try { twitter.createFavorite(tweet.getId()); return true; } catch (Exception ex) { System.err.println("[ERROR] Can't favorite " + tweet.getId()); ex.printStackTrace(); return false; } }
@Test public void testEquals() { new EqualsTester() .addEqualityGroup(Status.CLIENT_ERROR_BAD_REQUEST) .addEqualityGroup(Status.INFORMATIONAL_CONTINUE) .addEqualityGroup(Status.SERVER_ERROR_BAD_GATEWAY) .addEqualityGroup(Status.SUCCESS_ACCEPTED) .addEqualityGroup(Status.forCode(550), Status.forCode(550)) .testEquals(); }
public static Status parse(int id) { Status status = null; for (Status item : Status.values()) { if (item.getId() == id) { status = item; break; } } return status; }
public static Status parse(String val) { Status status = null; for (Status item : Status.values()) { if (item.getValue() == val) { status = item; break; } } return status; }
/** * Calling of the method indicates that the <code>method</code> test should be called. The method * checks this and if it is not called, calls it. If the method is failed or skipped, it throws * StatusException. */ protected void requiredMethod(String method) { log.println("starting required method: " + method); executeMethod(method); Status mtStatus = tRes.getStatusFor(method); if (mtStatus != null && (!mtStatus.isPassed() || mtStatus.isFailed())) { log.println("! Required method " + method + " failed"); throw new StatusException(mtStatus); } }
public void status() throws IOException { final Logger logger = cmdLogger; final Status status = getStatus(logger); if (status.isRespondingToPing()) { logger.info( "Apache NiFi is currently running, listening to Bootstrap on port {}, PID={}", new Object[] {status.getPort(), status.getPid() == null ? "unknkown" : status.getPid()}); return; } if (status.isProcessRunning()) { logger.info( "Apache NiFi is running at PID {} but is not responding to ping requests", status.getPid()); return; } if (status.getPort() == null) { logger.info("Apache NiFi is not running"); return; } if (status.getPid() == null) { logger.info( "Apache NiFi is not responding to Ping requests. The process may have died or may be hung"); } else { logger.info("Apache NiFi is not running"); } }