public static void main(String[] args) {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */

    try {

      Scanner sc = new Scanner(new File("/home/santosh/Desktop/testData"));

      int testCases = sc.nextInt();
      int i = 0;
      ArrayList<ArrayList<Integer>> inputArraysList = new ArrayList<ArrayList<Integer>>();
      ArrayList<Integer> list;
      while (i++ < testCases) {

        int n = sc.nextInt();
        int k = 0;
        list = new ArrayList<Integer>();
        while (k < n) {
          list.add(sc.nextInt());
          k++;
        }
        inputArraysList.add(list);
      }

      // System.out.println(inputArraysList.size());
      for (ArrayList<Integer> arr : inputArraysList) {
        countPairs(arr.toArray(new Integer[arr.size()]));
      }

    } catch (Exception e) {

    }
  }
  /**
   * Returns the <code>Format.Field</code> constants associated with the text at <code>offset</code>
   * . If <code>offset</code> is not a valid location into the current text, this will return an
   * empty array.
   *
   * @param offset offset into text to be examined
   * @return Format.Field constants associated with the text at the given position.
   */
  public Format.Field[] getFields(int offset) {
    if (getAllowsInvalid()) {
      // This will work if the currently edited value is valid.
      updateMask();
    }

    Map attrs = getAttributes(offset);

    if (attrs != null && attrs.size() > 0) {
      ArrayList al = new ArrayList();

      al.addAll(attrs.keySet());
      return (Format.Field[]) al.toArray(EMPTY_FIELD_ARRAY);
    }
    return EMPTY_FIELD_ARRAY;
  }
Exemple #3
0
 /*得到从表多列的信息*/
 public final RowMap[] getDetailRowinfos() {
   RowMap[] rows = new RowMap[d_RowInfos.size()];
   d_RowInfos.toArray(rows);
   return rows;
 }
  static ItemResult extractItemInfo(Element curItem) {
    ItemResult item = new ItemResult();

    // get the item columns
    String itemId = getAttributeText(curItem, "ItemID");

    String name = getElementTextByTagNameNR(curItem, "Name");

    String currently = getElementTextByTagNameNR(curItem, "Currently");

    // get Buy_Price, just put in the "" if it doesn't exist.
    String buyPrice = getElementTextByTagNameNR(curItem, "Buy_Price");

    // get First_Bid, just put in the "" if it doesn't exist.
    String firstBid = getElementTextByTagNameNR(curItem, "First_Bid");

    String numberOfBids = getElementTextByTagNameNR(curItem, "Number_of_Bids");

    String started = convertToSQLTime(getElementTextByTagNameNR(curItem, "Started"));

    String ends = convertToSQLTime(getElementTextByTagNameNR(curItem, "Ends"));

    Element locationElem = getElementByTagNameNR(curItem, "Location");

    String latitude = getAttributeText(locationElem, "Latitude");

    String longitude = getAttributeText(locationElem, "Longitude");

    String location = getElementText(locationElem);

    String country = getElementTextByTagNameNR(curItem, "Country");

    String description = getElementTextByTagNameNR(curItem, "Description");
    description = description.substring(0, Math.min(description.length(), 4000));

    Element sellerElem = getElementByTagNameNR(curItem, "Seller");
    String sellerId = getAttributeText(sellerElem, "UserID");

    String sellerRating = getAttributeText(sellerElem, "Rating");

    // for each itemCategory
    Element[] categoriesElem = getElementsByTagNameNR(curItem, "Category");
    ArrayList<String> categoriesArrayList = new ArrayList<String>();
    for (Element category : categoriesElem) {
      categoriesArrayList.add(getElementText(category));
    }
    String[] categories = new String[categoriesArrayList.size()];
    categories = categoriesArrayList.toArray(categories);

    // for each bid
    Element bidsElem = getElementByTagNameNR(curItem, "Bids");
    Element[] bidElemList = getElementsByTagNameNR(bidsElem, "Bid");
    ArrayList<BidResult> bidsArrayList = new ArrayList<BidResult>();
    for (Element bid : bidElemList) {
      // process the user (bidder) first
      Element bidderElem = getElementByTagNameNR(bid, "Bidder");
      String bidderId = getAttributeText(bidderElem, "UserID");
      String bidderRating = getAttributeText(bidderElem, "Rating");
      String bidderLocation = getElementTextByTagNameNR(bidderElem, "Location");
      String bidderCountry = getElementTextByTagNameNR(bidderElem, "Country");

      String bidTime = getElementTextByTagNameNR(bid, "Time");
      String amount = getElementTextByTagNameNR(bid, "Amount");

      BidResult bidResult =
          new BidResult(bidderId, bidderRating, bidderLocation, bidderCountry, amount, bidTime);

      bidsArrayList.add(bidResult);
    }
    BidResult[] bidResults = new BidResult[bidsArrayList.size()];
    bidResults = bidsArrayList.toArray(bidResults);

    return new ItemResult(
        itemId,
        name,
        categories,
        currently,
        buyPrice,
        firstBid,
        numberOfBids,
        bidResults,
        longitude,
        latitude,
        location,
        country,
        started,
        ends,
        sellerId,
        sellerRating,
        description);
  }