Example #1
0
  public boolean containsAnyCodePoint(final CharSequence text, final Range inputRange) {
    final int len = text.length();
    if (len == 0) {
      return false;
    }

    if (mostSignificantGap != null
        && mostSignificantGap.contains(inputRange.first)
        && mostSignificantGap.contains(inputRange.last)) {
      return false;
    }

    // if found, returns the index, otherwise "-insertionPoint - 1"
    final int idxEnd = Arrays.binarySearch(ranges, new Range(inputRange.last), CONTAINS_COMPARATOR);
    // search for start in "head" range only (likely small)
    final int startFromIdx = 0;
    final int startEndIdx = idxEnd >= 0 ? idxEnd + 1 : -(idxEnd + 1);
    final int idxStart =
        Arrays.binarySearch(
            ranges, startFromIdx, startEndIdx, new Range(inputRange.first), CONTAINS_COMPARATOR);

    // If whole range in text outside same non-contained range, won't be found
    // If whole range in text inside single contained range, must match
    if (idxStart == idxEnd) {
      return idxStart >= 0;
    }

    // if start or end inside contained range, match
    if (idxStart >= 0 || idxEnd >= 0) {
      return true;
    }

    // text spans across multiple ranges of set, need to search individual chars
    final int searchStart = -idxStart + 1;
    final int searchEnd = -idxEnd + 1;

    for (int i = 0; i < len; ) {
      final int cp = Character.codePointAt(text, i);
      i += Character.charCount(cp);
      final int idx =
          Arrays.binarySearch(ranges, searchStart, searchEnd, new Range(cp), CONTAINS_COMPARATOR);
      if (idx > 0) {
        return true;
      }
    }
    return false;
  }
Example #2
0
  public boolean intersects(Range intersectedRange) {

    if (contains(intersectedRange.start) || intersectedRange.contains(start)) {
      return true;
    }

    return false;
  }
Example #3
0
 private Range findIncludingRange(long mac) {
   for (Range range : ranges) {
     if (range.contains(mac)) {
       return range;
     }
   }
   return null;
 }
Example #4
0
  public boolean contains(final int i) {
    if (mostSignificantGap != null && mostSignificantGap.contains(i)) {
      return false;
    }

    final Range searchRange = new Range(i);
    int idx = Arrays.binarySearch(ranges, searchRange, CONTAINS_COMPARATOR);
    return idx >= 0;
  }
 /** Test of contains method, of class Range. */
 @Test
 public void testContains_Range() {
   System.out.println("contains");
   Range r = new Range(3, 6);
   Range instance = new Range(4, 5);
   boolean expResult = false;
   boolean result = instance.contains(r);
   assertEquals(expResult, result);
 }
 /** Test of contains method, of class Range. */
 @Test
 public void testContains_int() {
   System.out.println("contains");
   int x = 5;
   Range instance = new Range(4, 10);
   boolean expResult = true;
   boolean result = instance.contains(x);
   assertEquals(expResult, result);
 }
 public String classify(Range r) {
   if (this.equals(r)) return "SAME";
   if (this.contains(r)) return "SUPERSET";
   if (r.contains(this)) return "SUBSET";
   if (this.isDisjoint(r))
     if (this.lo > r.hi) return "MOREDISJOINT";
     else return "LESSDISJOINT";
   if (this.lessThan(r)) return "LESSOVERLAP";
   return "MOREOVERLAP";
 }
Example #8
0
 public Relation classify(Range r) {
   if (this.equals(r)) return Relation.SAME;
   if (this.contains(r)) return Relation.SUPERSET;
   if (r.contains(this)) return Relation.SUBSET;
   if (this.isDisjoint(r))
     if (this.lo > r.hi) return Relation.MOREDISJOINT;
     else return Relation.LESSDISJOINT;
   if (this.lessThan(r)) return Relation.LESSOVERLAP;
   return Relation.MOREOVERLAP;
 }
  /** Checks whether given peak list row conforms to this search condition. */
  public boolean conforms(PeakListRow row) {
    switch (type) {
      case NAME:
        PeakIdentity identity = row.getPreferredPeakIdentity();
        if (identity == null) return false;
        String name = identity.getName();

        if (isEmpty(nameRegex.toString()) || isEmpty(name)) {
          return false;
        }

        Matcher matcher = nameRegex.matcher(name);
        return matcher.find();

      case MASS:
        return range.contains(row.getAverageMZ());

      case RT:
        return range.contains(row.getAverageRT());
    }
    return false;
  }
  public CommandResponse doREMOVEJOB(CommandRequest request) throws ImproperUsageException {

    if (!request.hasArgument()) {
      throw new ImproperUsageException();
    }
    class Range {
      long _low, _high;

      Range(long low, long high) {
        if (0 >= low || low > high) {
          throw new IllegalArgumentException("0 < low <= high");
        }
        _low = low;
        _high = high;
      }

      public boolean contains(long val) {
        return _low <= val && val <= _high;
      }
    }

    ArrayList<Range> rangeList = new ArrayList<Range>();
    String rangeString = request.getArgument();
    String[] ranges = rangeString.split(" ");
    for (String range : ranges) {
      if (range.indexOf("-") == -1) {
        long val = Long.parseLong(range);
        rangeList.add(new Range(val, val));
      } else {
        String[] vals = range.split("-");
        rangeList.add(new Range(Long.parseLong(vals[0]), Long.parseLong(vals[1])));
      }
    }
    TreeSet<Job> treeSet = new TreeSet<Job>(new JobIndexComparator());
    treeSet.addAll(getJobManager().getAllJobsFromQueue());
    ReplacerEnvironment env = new ReplacerEnvironment();

    CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK");
    for (Job job : treeSet) {
      for (Range range : rangeList) {
        if (range.contains(job.getIndex())) {
          env.add("job", job);
          getJobManager().stopJob(job);
          response.addComment(
              request.getSession().jprintf(_bundle, env, _keyPrefix + "removejob.success"));
        }
      }
    }
    return response;
  }
Example #11
0
  @Test
  public void containsRev() {
    Range<Integer> range = new IntRange(5, 1).incrementBy(-1);
    assertThat(range.contains(6), is(false));
    assertThat(range.contains(5), is(true));
    assertThat(range.contains(4), is(true));
    assertThat(range.contains(3), is(true));
    assertThat(range.contains(2), is(true));
    assertThat(range.contains(1), is(false));
    assertThat(range.contains(42), is(false));

    range.incrementBy(-2);
    assertThat(range.contains(5), is(true));
    assertThat(range.contains(4), is(false));
    assertThat(range.contains(3), is(true));
    assertThat(range.contains(2), is(false));
    assertThat(range.contains(1), is(false));
  }
  static FacebookRequestError checkResponseAndCreateError(
      JSONObject singleResult, Object batchResult, HttpURLConnection connection) {
    try {
      if (singleResult.has(CODE_KEY)) {
        int responseCode = singleResult.getInt(CODE_KEY);
        Object body =
            Utility.getStringPropertyAsJSON(
                singleResult, BODY_KEY, Response.NON_JSON_RESPONSE_PROPERTY);

        if (body != null && body instanceof JSONObject) {
          JSONObject jsonBody = (JSONObject) body;
          // Does this response represent an error from the service? We might get either an "error"
          // with several sub-properties, or else one or more top-level fields containing error
          // info.
          String errorType = null;
          String errorMessage = null;
          int errorCode = INVALID_ERROR_CODE;
          int errorSubCode = INVALID_ERROR_CODE;

          boolean hasError = false;
          if (jsonBody.has(ERROR_KEY)) {
            // We assume the error object is correctly formatted.
            JSONObject error =
                (JSONObject) Utility.getStringPropertyAsJSON(jsonBody, ERROR_KEY, null);

            errorType = error.optString(ERROR_TYPE_FIELD_KEY, null);
            errorMessage = error.optString(ERROR_MESSAGE_FIELD_KEY, null);
            errorCode = error.optInt(ERROR_CODE_FIELD_KEY, INVALID_ERROR_CODE);
            errorSubCode = error.optInt(ERROR_SUB_CODE_KEY, INVALID_ERROR_CODE);
            hasError = true;
          } else if (jsonBody.has(ERROR_CODE_KEY)
              || jsonBody.has(ERROR_MSG_KEY)
              || jsonBody.has(ERROR_REASON_KEY)) {
            errorType = jsonBody.optString(ERROR_REASON_KEY, null);
            errorMessage = jsonBody.optString(ERROR_MSG_KEY, null);
            errorCode = jsonBody.optInt(ERROR_CODE_KEY, INVALID_ERROR_CODE);
            errorSubCode = jsonBody.optInt(ERROR_SUB_CODE_KEY, INVALID_ERROR_CODE);
            hasError = true;
          }

          if (hasError) {
            return new FacebookRequestError(
                responseCode,
                errorCode,
                errorSubCode,
                errorType,
                errorMessage,
                jsonBody,
                singleResult,
                batchResult,
                connection);
          }
        }

        // If we didn't get error details, but we did get a failure response code, report it.
        if (!HTTP_RANGE_SUCCESS.contains(responseCode)) {
          return new FacebookRequestError(
              responseCode,
              INVALID_ERROR_CODE,
              INVALID_ERROR_CODE,
              null,
              null,
              singleResult.has(BODY_KEY)
                  ? (JSONObject)
                      Utility.getStringPropertyAsJSON(
                          singleResult, BODY_KEY, Response.NON_JSON_RESPONSE_PROPERTY)
                  : null,
              singleResult,
              batchResult,
              connection);
        }
      }
    } catch (JSONException e) {
      // defer the throwing of a JSONException to the graph object proxy
    }
    return null;
  }
  private FacebookRequestError(
      int requestStatusCode,
      int errorCode,
      int subErrorCode,
      String errorType,
      String errorMessage,
      JSONObject requestResultBody,
      JSONObject requestResult,
      Object batchRequestResult,
      HttpURLConnection connection,
      FacebookException exception) {
    this.requestStatusCode = requestStatusCode;
    this.errorCode = errorCode;
    this.subErrorCode = subErrorCode;
    this.errorType = errorType;
    this.errorMessage = errorMessage;
    this.requestResultBody = requestResultBody;
    this.requestResult = requestResult;
    this.batchRequestResult = batchRequestResult;
    this.connection = connection;

    boolean isLocalException = false;
    if (exception != null) {
      this.exception = exception;
      isLocalException = true;
    } else {
      this.exception = new FacebookServiceException(this, errorMessage);
    }

    // Initializes the error categories based on the documented error codes as outlined here
    // https://developers.facebook.com/docs/reference/api/errors/
    Category errorCategory = null;
    int messageId = INVALID_MESSAGE_ID;
    boolean shouldNotify = false;
    if (isLocalException) {
      errorCategory = Category.CLIENT;
      messageId = INVALID_MESSAGE_ID;
    } else {
      if (errorCode == EC_UNKNOWN_ERROR || errorCode == EC_SERVICE_UNAVAILABLE) {
        errorCategory = Category.SERVER;
      } else if (errorCode == EC_APP_TOO_MANY_CALLS || errorCode == EC_USER_TOO_MANY_CALLS) {
        errorCategory = Category.THROTTLING;
      } else if (errorCode == EC_PERMISSION_DENIED || EC_RANGE_PERMISSION.contains(errorCode)) {
        errorCategory = Category.PERMISSION;
        // *************** APPCELERATOR TITANIUM CUSTOMIZATION ***************************
        // messageId = R.string.com_facebook_requesterror_permissions;
        messageId = Utility.resId_requestErrorPermissions;
      } else if (errorCode == EC_INVALID_SESSION || errorCode == EC_INVALID_TOKEN) {
        if (subErrorCode == EC_USER_CHECKPOINTED || subErrorCode == EC_UNCONFIRMED_USER) {
          errorCategory = Category.AUTHENTICATION_RETRY;
          // messageId = R.string.com_facebook_requesterror_web_login;
          messageId = Utility.resId_requestErrorWebLogin;
          shouldNotify = true;
        } else {
          errorCategory = Category.AUTHENTICATION_REOPEN_SESSION;

          if (subErrorCode == EC_APP_NOT_INSTALLED) {
            // messageId = R.string.com_facebook_requesterror_relogin;
            messageId = Utility.resId_requestErrorRelogin;
          } else if (subErrorCode == EC_PASSWORD_CHANGED) {
            // messageId = R.string.com_facebook_requesterror_password_changed;
            messageId = Utility.resId_requestErrorPasswordChanged;
          } else {
            // messageId = R.string.com_facebook_requesterror_reconnect;
            messageId = Utility.resId_requestErrorReconnect;
          }
        }
      }

      if (errorCategory == null) {
        if (HTTP_RANGE_CLIENT_ERROR.contains(requestStatusCode)) {
          errorCategory = Category.BAD_REQUEST;
        } else if (HTTP_RANGE_SERVER_ERROR.contains(requestStatusCode)) {
          errorCategory = Category.SERVER;
        } else {
          errorCategory = Category.OTHER;
        }
      }
    }

    this.category = errorCategory;
    this.userActionMessageId = messageId;
    this.shouldNotifyUser = shouldNotify;
  }
Example #14
0
 @Test
 public void testMacIsNotContainedInRange() throws Exception {
   assertThat(rangeOf10Macs.contains(MAC_OUTSIDE_OF_RANGE), is(false));
 }
Example #15
0
 @Test
 public void testMacIsContainedInRange() throws Exception {
   assertThat(rangeOf10Macs.contains(MAC_FROM_RANGE), is(true));
 }