Example #1
1
 // Makes sure QueryKeys have no problem going in and out of GGEP blocks
 public void testQueryKeysAndGGEP() throws Exception {
   MACCalculatorRepositoryManager macManager = new MACCalculatorRepositoryManager();
   Random rand = new Random();
   for (int i = 4; i < 17; i++) {
     byte[] qk = new byte[i];
     Arrays.sort(qk);
     // make sure the bytes have offensive characters....
     while ((Arrays.binarySearch(qk, (byte) 0x1c) < 0)
         || (Arrays.binarySearch(qk, (byte) 0x00) < 0)) {
       rand.nextBytes(qk);
       Arrays.sort(qk);
     }
     AddressSecurityToken addressSecurityToken = new AddressSecurityToken(qk, macManager);
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     addressSecurityToken.write(baos);
     GGEP in = new GGEP(true);
     in.put(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT, baos.toByteArray());
     baos = new ByteArrayOutputStream();
     in.write(baos);
     GGEP out = new GGEP(baos.toByteArray(), 0, null);
     AddressSecurityToken queryKey2 =
         new AddressSecurityToken(
             out.getBytes(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT), macManager);
     assertEquals("qks not equal, i = " + i, addressSecurityToken, queryKey2);
   }
 }
 public void ___testGetAllFontsNames() {
   NRC_HTMLDocumentByCobra doc = null;
   try {
     doc = new NRC_HTMLDocumentByCobra("http://localhost/tests/testfonts.html");
     String[] fontNames = doc.getAllFontsNames();
     doc.close();
     Arrays.sort(fontNames);
     String[] namesExpected =
         new String[] {
           "nunacom",
           "Verdana",
           "Arial",
           "Helvetica",
           "sans-serif",
           "Naamajut",
           "Times New Roman",
           "georgia",
           "PROSYL"
         };
     Arrays.sort(namesExpected);
     assertTrue(
         "Les noms des polices retournés pour testfonts.html ne sont pas corrects",
         Arrays.hashCode(fontNames) == Arrays.hashCode(namesExpected));
   } catch (Exception e) {
     e.printStackTrace();
     if (doc != null) doc.close();
     fail();
   }
 }
Example #3
0
 public ArrayList<String> anagrams(String[] strs) {
   // Start typing your Java solution below
   // DO NOT write main() function
   ArrayList<String> ret = new ArrayList<String>();
   int n = strs.length;
   Index[] indices = new Index[n];
   for (int i = 0; i < n; i++) {
     char[] chs = strs[i].toCharArray();
     Arrays.sort(chs);
     indices[i] = new Index(i, new String(chs));
   }
   Arrays.sort(indices);
   boolean ana = false;
   for (int i = 0; i < n - 1; i++) {
     if (indices[i].s.equals(indices[i + 1].s)) {
       if (!ana) {
         ret.add(strs[indices[i].id]);
         ana = true;
       }
       ret.add(strs[indices[i + 1].id]);
     } else {
       ana = false;
     }
   }
   return ret;
 }
Example #4
0
  public static void main(String[] args) {
    try {
      BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));

      int testCases = Integer.parseInt(consoleReader.readLine());
      for (int i = 0; i < testCases; i++) {
        int pairs = Integer.parseInt(consoleReader.readLine());
        String[] men = consoleReader.readLine().split(" ");
        String[] women = consoleReader.readLine().split(" ");

        int[] menRatings = new int[pairs];
        int[] womenRatings = new int[pairs];
        for (int j = 0; j < pairs; j++) {
          menRatings[j] = Integer.parseInt(men[j]);
          womenRatings[j] = Integer.parseInt(women[j]);
        }

        Arrays.sort(menRatings);
        Arrays.sort(womenRatings);

        int sum = 0;

        for (int k = pairs - 1; k >= 0; k--) {
          sum += womenRatings[k] * menRatings[k];
        }

        System.out.println(sum);
      }

    } catch (Exception exc) {

    }
  }
  @Test
  public void test() {
    String first = "silent";
    String second = "Listen";

    assertEquals(first.length(), second.length());

    char[] firstArray = first.toLowerCase().toCharArray();
    char[] secondArray = second.toLowerCase().toCharArray();

    sort(firstArray);
    sort(secondArray);

    boolean equals = false;

    for (int i = 0; i < firstArray.length; i++) {
      if (firstArray[i] == secondArray[i]) {
        equals = true;
      } else {
        equals = false;
      }
    }

    if (equals) {
      System.out.println("Anagram Strings");
    }
  }
Example #6
0
  @Override
  public List<File> loadInBackground() {

    ArrayList<File> list = new ArrayList<File>();

    // Current directory File instance
    final File pathDir = new File(mPath);
    list.add(pathDir.getParentFile());

    // List file in this directory with the directory filter
    final File[] dirs = pathDir.listFiles(FileUtils.sDirFilter);
    if (dirs != null) {
      // Sort the folders alphabetically
      Arrays.sort(dirs, FileUtils.sComparator);
      // Add each folder to the File list for the list adapter
      for (File dir : dirs) list.add(dir);
    }

    // List file in this directory with the file filter
    final File[] files = pathDir.listFiles(FileUtils.sFileFilter);
    if (files != null) {
      // Sort the files alphabetically
      Arrays.sort(files, FileUtils.sComparator);
      // Add each file to the File list for the list adapter
      for (File file : files) list.add(file);
    }

    return list;
  }
  public static void sort(int m[][]) {
    String[] nums = new String[m.length]; // creating string array
    Arrays.fill(nums, ""); // filling array with "" to avoid it beeing null
    for (int i = 0; i < m.length; i++) {
      for (int j = 0; j < m[i].length; j++) {
        nums[i] += String.valueOf(m[i][j]) + " "; // converting rows of
        // our 2D array into
        // string array

      }
    }
    Arrays.sort(nums); // sorting the string array
    String[][] secondary = new String[m.length][m[0].length];
    // converting back to 2D String array so we and performing secondary
    // sorting(sorting of the rows)
    for (int i = 0; i < secondary.length; i++) {
      secondary[i] = nums[i].split(" ");
      Arrays.sort(secondary[i]);
    }
    // printing out the new sorted 2D array
    for (String[] e : secondary) {
      for (String i : e) {
        System.out.print(i + " ");
      }
      System.out.println();
    }
  }
Example #8
0
  // Write a method that determines if two strings are anagrams of each other. For example, “TEAM”
  // and “MEAT” would return true.
  public static boolean isAnagram(String a, String b) {
    // Remove whitespace using a regular expression
    a = a.replaceAll("\\s+", "");
    b = b.replaceAll("\\s+", "");

    // Change to uppercase to reduce amount of possible characters
    a = a.toUpperCase();
    b = b.toUpperCase();

    // Turn the string into char arrays
    char i[] = a.toCharArray();
    char j[] = b.toCharArray();

    // Sort the arrays
    Arrays.sort(i);
    Arrays.sort(j);

    // Now check for equality
    for (int c = 0; c < i.length; c++) {
      // Since these are sorted, the indicies should match up.
      if (i[c] != j[c]) {
        return false;
      } // if
    } // for

    // Else, return true
    return true;
  } // isAnagram
  private void assertProposedMethods(
      String finderName,
      String[] properties,
      String[] superProperties,
      String[] expectedMethodProposalNames)
      throws JavaModelException {
    String superName = null;
    if (superProperties != null) {
      superName = "SearchSuper";
      createDomainClass(
          "SearchSuper", createDomainTextWithSuper(null, null, true, superProperties));
    }
    String contents = createDomainTextWithSuper(finderName, superName, false, properties);
    // ensure this is executed in a static context
    GroovyCompilationUnit unit = createDomainClass("Search", contents);
    DynamicFinderValidator validator =
        new FinderValidatorFactory()
            .createValidator(GrailsWorkspaceCore.get().create(project).getDomainClass(unit));
    List<AnnotatedNode> proposed = validator.findProposals(finderName);
    String[] actualMethodProposalNames = getProposalNames(proposed);
    Arrays.sort(expectedMethodProposalNames);
    Arrays.sort(actualMethodProposalNames);

    assertTrue(
        "Actual and expected proposals not the same.\nExpected: "
            + Arrays.toString(expectedMethodProposalNames)
            + "\nActual: "
            + Arrays.toString(actualMethodProposalNames),
        testSameElements(expectedMethodProposalNames, actualMethodProposalNames));
  }
  public static void main(String args[]) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int t = Integer.parseInt(br.readLine());
    String[] s1 = br.readLine().split(" ");
    String[] s2 = br.readLine().split(" ");
    int[] a1 = new int[t];
    int[] a2 = new int[t];
    for (int i = 0; i < t; i++) {
      a1[i] = Integer.parseInt(s1[i]);
      a2[i] = Integer.parseInt(s2[i]);
    }
    Arrays.sort(a1);
    Arrays.sort(a2);
    int i = 0;
    int cnt = 0;
    for (int k = t - 1; k >= 1; k--) {
      if (a2[k] == a1[i]) cnt += 50;
      else {
        if (a2[k] < a1[i]) cnt += 100;
      }
      i++;
    }
    System.out.println(cnt);
  }
Example #11
0
 public static void main(String[] args) {
   Scanner input = new Scanner(System.in);
   int n = input.nextInt(), m = input.nextInt();
   int[] data = new int[m], data2 = new int[m];
   for (int i = 0; i < m; i++) {
     data[i] = input.nextInt();
     data2[i] = data[i];
   }
   Arrays.sort(data);
   Arrays.sort(data2);
   // find min
   int at = 0, min = 0, max = 0, needed = n;
   while (needed > 0) {
     min += data[at];
     data[at]--;
     needed--;
     if (data[at] == 0) at++;
   }
   needed = n;
   while (needed > 0) {
     needed--;
     max += data2[m - 1];
     data2[m - 1]--;
     Arrays.sort(data2);
   }
   System.out.println(max + " " + min);
 }
  public static void main(String[] args) {
    // TODO code application logic here
    ArrayList<String> al = new ArrayList<>();
    al.add("pied");
    al.add("pile");
    al.add("pier");
    al.add("pides");
    String s = "pide";
    ArrayList possible = new ArrayList();
    for (int i = 0; i < al.size(); i++) {

      if (minDistance((String) al.get(i), s) < 2) {
        System.out.println((String) al.get(i));
        System.out.println("yo");
        possible.add((String) al.get(i));
      }

      String x = (String) al.get(i);
      char[] charArr = x.toCharArray();
      Arrays.sort(charArr);

      char[] charArr2 = s.toCharArray();
      Arrays.sort(charArr2);

      if (charArr.toString().equals(charArr2.toString())) {
        possible.add((String) al.get(i));
      }
    }
    System.out.println(possible);
  }
Example #13
0
  public static void main(String args[]) {

    // Allocate and initialize array.
    int array[] = new int[10];
    for (int i = 0; i < 10; i++) array[i] = -3 * i;

    // Display, sort, and display the array.
    System.out.print("Original contents: ");
    display(array);
    Arrays.sort(array);
    System.out.print("Sorted: ");
    display(array);

    // Fill and display the array.
    Arrays.fill(array, 2, 6, -1);
    System.out.print("After fill(): ");
    display(array);

    // Sort and display the array.
    Arrays.sort(array);
    System.out.print("After sorting again: ");
    display(array);

    // Binary search for -9.
    System.out.print("The value -9 is at location ");
    int index = Arrays.binarySearch(array, -9);

    System.out.println(index);
  }
Example #14
0
  /**
   * getLegalMovesTestManyPossibilities: This sets a black rook at spot g4 with a random board that
   * has 11 possible moves including taking a white pawn Also checks that you can move in every
   * direction multiple spaces.
   */
  @Test
  public void getLegalMovesTestManyMoves() {
    Rook rookPiece = new Rook('b', "g4");
    List<String> legalMoves =
        rookPiece.getLegalMoves("1nbqkbnr/2Pppppp/p7/1p6/6r1/8/P1PPPPPP/RNBQKBNR w KQkq -");
    String[] legalMovesArray = new String[legalMoves.size()];
    legalMoves.toArray(legalMovesArray);
    assertNotNull(legalMoves);

    String[] expected = new String[11];
    expected[0] = "1nbqkbnr/2Pppppp/p7/1p4r1/8/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[1] = "1nbqkbnr/2Pppppp/p5r1/1p6/8/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[2] = "1nbqkbnr/2Pppppp/p7/1p6/8/6r1/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[3] = "1nbqkbnr/2Pppppp/p7/1p6/7r/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[4] = "1nbqkbnr/2Pppppp/p7/1p6/5r2/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[5] = "1nbqkbnr/2Pppppp/p7/1p6/4r3/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[6] = "1nbqkbnr/2Pppppp/p7/1p6/3r4/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[7] = "1nbqkbnr/2Pppppp/p7/1p6/2r5/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[8] = "1nbqkbnr/2Pppppp/p7/1p6/1r6/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[9] = "1nbqkbnr/2Pppppp/p7/1p6/r7/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[10] = "1nbqkbnr/2Pppppp/p7/1p6/8/8/P1PPPPrP/RNBQKBNR w KQkq -";
    Arrays.sort(legalMovesArray);
    Arrays.sort(expected);
    assertArrayEquals(expected, legalMovesArray);
  }
Example #15
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String a = in.nextLine();
    String[] suba = a.split(" ");
    int N = suba.length;
    Arrays.sort(suba);
    //		for (int i = 0; i < suba.length; i++) {
    //			System.out.print(suba[i]+" ");
    //		}

    Record[] records = new Record[N];
    String word = suba[0];
    int freq = 1;
    int M = 0;
    for (int i = 0; i < N; i++) {
      if (!suba[i].equals(word)) {
        records[M++] = new Record(word, freq);
        word = suba[i];
        freq = 0;
      }
      freq++;
      // suba中的元素如果等于给定的word则freq增加,并且下一轮的时候加入到records数组中
    }
    // 这条语句是在变化元素之后执行的,所以需要再执行一遍
    records[M++] = new Record(word, freq);
    // 将records数组进行排序,所以将忽略重复元素
    Arrays.sort(records, 0, M);
    for (int i = M - 1; i >= 0; i--) {
      // 这里要加上toString方法才能直接调用records[i]
      System.out.println(records[i].getWord() + " " + records[i].getFreq());
    }
  }
Example #16
0
  /** Unit tests the transaction data type. */
  public static void main(String[] args) {
    Transaction[] a = new Transaction[4];
    a[0] = new Transaction("Turing   6/17/1990  644.08");
    a[1] = new Transaction("Tarjan   3/26/2002 4121.85");
    a[2] = new Transaction("Knuth    6/14/1999  288.34");
    a[3] = new Transaction("Dijkstra 8/22/2007 2678.40");

    StdOut.println("Unsorted");
    for (int i = 0; i < a.length; i++) StdOut.println(a[i]);
    StdOut.println();

    StdOut.println("Sort by date");
    Arrays.sort(a, new Transaction.WhenOrder());
    for (int i = 0; i < a.length; i++) StdOut.println(a[i]);
    StdOut.println();

    StdOut.println("Sort by customer");
    Arrays.sort(a, new Transaction.WhoOrder());
    for (int i = 0; i < a.length; i++) StdOut.println(a[i]);
    StdOut.println();

    StdOut.println("Sort by amount");
    Arrays.sort(a, new Transaction.HowMuchOrder());
    for (int i = 0; i < a.length; i++) StdOut.println(a[i]);
    StdOut.println();
  }
Example #17
0
  /** Find smallest difference between two elements of two arrays */
  public static final int findSmallest(int[] x, int[] y) {
    Arrays.sort(x);
    Arrays.sort(y);

    int i = 0;
    int j = 0;
    int smallest = -1;

    while (true) {

      final int dif = Math.abs((x[i] - y[j]));

      if (smallest == -1) {
        smallest = dif;
      } else if (dif < smallest) {
        smallest = dif;
      } else if (dif == 0) {
        return 0;
      }

      if (x[i] < y[j]) {
        i++;
        if (i == x.length) return smallest;
      } else if (x[i] > y[j]) {
        j++;
        if (j == y.length) return smallest;
      }
    }
  }
Example #18
0
  public static void main(String[] args) {
    String[] newString = new String[args.length];
    int counter = 0;

    if (args[(args.length) - 1].equals("down")) {
      counter = 1;
    }

    for (int i = 0; i < args.length; i++) {
      if (System.getProperty(args[i]) == null) {
        newString[i] = "Error";
        continue;
      }

      newString[i] = System.getProperty(args[i]);
    }

    System.out.println("");
    if (counter == 1) {

      Arrays.sort(newString, Collections.reverseOrder()); // ,java.text.Collator.getInstance()
    } else {
      Arrays.sort(newString);
    }

    for (int i = 0; i < newString.length; i++) {
      if (newString[i].equals("Error")) {
        continue;
      }
      System.out.println(newString[i]);
    }
  }
Example #19
0
  private void displayMetModels() {
    Class<?>[] modelClasses = Metadata.class.getInterfaces();
    Arrays.sort(
        modelClasses,
        new Comparator<Class<?>>() {
          public int compare(Class<?> o1, Class<?> o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });

    for (Class<?> modelClass : modelClasses) {
      // we don't care about internal Tika met classes
      // if we do, then we can take this conditional out
      if (!modelClass.getSimpleName().contains("Tika")) {
        System.out.println(modelClass.getSimpleName());
        Field[] keyFields = modelClass.getFields();
        Arrays.sort(
            keyFields,
            new Comparator<Field>() {
              public int compare(Field o1, Field o2) {
                return o1.getName().compareTo(o2.getName());
              }
            });
        for (Field keyField : keyFields) {
          System.out.println(" " + keyField.getName());
        }
      }
    }
  }
Example #20
0
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int[] arr1 = new int[size];
    int[] arr2 = new int[size];
    for (int i = 0; i < arr1.length; i++) {
      System.out.println("Enter the elements in arr1");
      arr1[i] = sc.nextInt();
    }

    for (int i = 0; i < arr1.length; i++) {
      System.out.println("Enter the elements in arr2");
      arr2[i] = sc.nextInt();
    }

    Arrays.sort(arr1);
    Arrays.sort(arr2);
    System.out.println(Arrays.toString(arr1));
    System.out.println(Arrays.toString(arr2));

    int sum = 0;
    for (int i = 0; i < arr1.length; i++) {
      for (int j = 0; j < arr2.length; j++) {
        sum = arr1[i] * arr2[j];
      }
    }
    System.out.println(sum);
  }
Example #21
0
 // set sequences to null or empty to get all sequences
 // set positions to null or empty to get all posistions
 public Msa createSubAlignment(final int[] sequences, final int[] positions) {
   final Msa msa = new BasicMsa();
   boolean return_all_seqs = false;
   boolean return_all_pos = false;
   if ((sequences == null) || (sequences.length < 1)) {
     return_all_seqs = true;
   } else {
     Arrays.sort(sequences);
   }
   if ((positions == null) || (positions.length < 1)) {
     return_all_pos = true;
   } else {
     Arrays.sort(positions);
   }
   for (int s = 0; s < getNumberOfSequences(); ++s) {
     if (return_all_seqs || (Arrays.binarySearch(sequences, s) >= 0)) {
       for (int p = 0; p < getLength(); ++p) {
         if (return_all_pos || (Arrays.binarySearch(positions, p) >= 0)) {
           // FIXME finish me
         }
       }
     }
   }
   return msa;
 }
  /**
   * Helper method to determine whether two arrays of path names contain the same elements, even if
   * those elements aren't in the same order in both arrays. Also, remove a prefix from each path in
   * arr1 before comparing.
   *
   * @param arr1prefix The String prefix to remove
   * @param arr1 The first array of Strings
   * @param arr2 The second array of Strings
   */
  public static void assertSortedPathArraysEqual(String arr1prefix, String[] arr1, String[] arr2) {

    /* if one is null, then both must be null */
    if (arr1 == null) {
      if (arr2 != null) {
        fail("One array is null, but the other isn't.");
      } else {
        /* everything is good */
        return;
      }
    }

    /* lengths must be the same */
    if (arr1.length != arr2.length) {
      fail("Arrays have different length: " + arr1.length + " versus " + arr2.length);
    }

    /* now sort the elements and compare them */
    Arrays.sort(arr1);
    Arrays.sort(arr2);

    for (int i = 0; i < arr1.length; i++) {
      String str1 = arr1[i];
      if (!str1.startsWith(arr1prefix)) {
        fail("Array element " + str1 + " doesn't start with " + arr1prefix);
      }
      str1 = str1.substring(arr1prefix.length());
      String str2 = arr2[i];
      // System.out.println("Comparing " + str1 + " and " + str2);
      if (!str1.equals(str2)) {
        fail("Mismatched array elements: " + str1 + " and " + str2);
      }
    }
  }
Example #23
0
    public static void main(String args[]) throws Exception {
        Scanner keyb = new Scanner(new File("jorge.dat"));

        while (keyb.hasNextLine()) {
            String dat[] = keyb.nextLine().split(" ");
            int ints[] = new int[dat.length];
            for (int i = 0; i < dat.length; i++) {
                ints[i] = Integer.parseInt(dat[i]);
            }
            int mods[] = new int[dat.length];
            for (int i = 0; i < dat.length; i++) {
                mods[i] = Integer.parseInt(dat[i]) % 13;
            }
            Arrays.sort(ints);
            Arrays.sort(mods);
            System.out.println(Arrays.toString(ints));
            if (asd(mods)) {
                System.out.println("FOUR OF A KIND");
            } else if (dannyTanner(mods)) {
                System.out.println("FULL HOUSE");
            } else if (toilet(ints)) {
                System.out.println("FLUSH");
            } else if (yag(ints, mods)  {
                System.out.println("STRAIGHT");
            } else if (tres()) {

            }
        }
Example #24
0
  public static void main(String[] args) {
    String[] names;

    // Sort using
    // "an Instance Method of an Arbitrary Object of a Particular Type"
    names = unsortedNames.clone();
    Arrays.sort(names, String::compareToIgnoreCase); // <1>
    dump(names);

    // Equivalent Lambda:
    names = unsortedNames.clone();
    Arrays.sort(names, (str1, str2) -> str1.compareToIgnoreCase(str2)); // <2>
    dump(names);

    // Equivalent old way:
    names = unsortedNames.clone();
    Arrays.sort(
        names,
        new Comparator<String>() { // <3>
          @Override
          public int compare(String str1, String str2) {
            return str1.compareToIgnoreCase(str2);
          }
        });
    dump(names);

    // Simpest way, using existing comparator
    names = unsortedNames.clone();
    Arrays.sort(names, String.CASE_INSENSITIVE_ORDER); // <4>
    dump(names);
  }
Example #25
0
  public static double CA(Instances odata, int[] clusters) {
    double result = 0;
    double[] tmpdclass = odata.attributeToDoubleArray(odata.numAttributes() - 1);
    int[] oclass = new int[odata.numInstances()];
    for (int i = 0; i < tmpdclass.length; ++i) {
      oclass[i] = (int) tmpdclass[i];
    }
    int[] tmpclass = oclass.clone();
    int[] tmpclusters = clusters.clone();

    Arrays.sort(tmpclusters);
    Arrays.sort(tmpclass);
    int[][] M = new int[tmpclass[tmpclass.length - 1] + 1][tmpclusters[tmpclusters.length - 1] + 1];

    for (int i = 0; i < clusters.length; ++i) {
      M[oclass[i]][clusters[i]]++;
    }
    for (int i = 0; i < M.length; ++i) {
      System.out.println(Arrays.toString(M[i]));
    }
    for (int i = 0; i < M.length; ++i) {
      int maxindex = -1;
      for (int j = 0; j < M[0].length - 1; ++j) {
        if (M[i][j] < M[i][j + 1]) maxindex = j + 1;
      }
      M[i][0] = maxindex;
    }

    for (int i = 0; i < oclass.length; ++i) {
      if (M[oclass[i]][0] == clusters[i]) result++;
    }

    return (double) result / (double) odata.numInstances();
  }
  @Override
  public RaptorAliasResult apply(ChatConsoleController controller, String command) {
    if (command.equalsIgnoreCase("=tag")) {
      StringBuilder builder = new StringBuilder(1000);

      String[] tags = UserTagService.getInstance().getTags();
      Arrays.sort(tags);

      builder.append("Available Tags: ");
      for (String tag : tags) {
        builder.append(tag).append(" ");
      }

      builder.append("\n\nTagged users:\n");
      for (String tag : tags) {
        String[] users = UserTagService.getInstance().getUsersInTag(tag);
        if (users.length > 0) {
          builder.append(tag).append(":\n");
          Arrays.sort(users);
          int counter = 0;
          for (int i = 0; i < users.length; i++) {
            builder.append(StringUtils.rightPad(users[i], 20));
            counter++;
            if (counter == 3) {
              counter = 0;
              builder.append("\n");
            }
          }
          builder.append("\n\n");
        }
      }
      return new RaptorAliasResult(null, builder.toString().trim());
    }
    return null;
  }
 /** Checks that the authorization headers are equal, modulo ordering of the parameters */
 private void assertEqualAuthorizationHeaders(String h1, String h2) {
   String[] a1 = h1.split(",?\\s*");
   Arrays.sort(a1);
   String[] a2 = h2.split(",?\\s*");
   Arrays.sort(a2);
   assertEquals(Arrays.asList(a1), Arrays.asList(a2));
 }
  /** @tests java.util.Arrays#sort(float[]) */
  public void test_sort$F() {
    // Test a basic sort
    float[] reversedArray = new float[100];
    for (int counter = 0; counter < reversedArray.length; counter++) {
      reversedArray[counter] = (reversedArray.length - counter - 1);
    }
    Arrays.sort(reversedArray);
    for (int counter = 0; counter < reversedArray.length; counter++) {
      assertTrue("Assert 0: Resulting array not sorted", reversedArray[counter] == counter);
    }

    float[] specials1 =
        new float[] {
          Float.NaN,
          Float.MAX_VALUE,
          Float.MIN_VALUE,
          0f,
          -0f,
          Float.POSITIVE_INFINITY,
          Float.NEGATIVE_INFINITY
        };
    float[] specials2 =
        new float[] {
          0f,
          Float.POSITIVE_INFINITY,
          -0f,
          Float.NEGATIVE_INFINITY,
          Float.MIN_VALUE,
          Float.NaN,
          Float.MAX_VALUE
        };
    float[] answer =
        new float[] {
          Float.NEGATIVE_INFINITY,
          -0f,
          0f,
          Float.MIN_VALUE,
          Float.MAX_VALUE,
          Float.POSITIVE_INFINITY,
          Float.NaN
        };

    Arrays.sort(specials1);
    Object[] print1 = new Object[specials1.length];
    for (int i = 0; i < specials1.length; i++) {
      print1[i] = new Float(specials1[i]);
    }
    assertTrue(
        "Assert 1: specials sort incorrectly" + Arrays.asList(print1),
        Arrays.equals(specials1, answer));

    Arrays.sort(specials2);
    Object[] print2 = new Object[specials2.length];
    for (int i = 0; i < specials2.length; i++) {
      print2[i] = new Float(specials2[i]);
    }
    assertTrue(
        "Assert 2: specials sort incorrectly" + Arrays.asList(print2),
        Arrays.equals(specials2, answer));
  }
Example #29
0
 // check if they are permutations
 public boolean compare(String a, String b) {
   char[] c1 = a.toCharArray();
   char[] c2 = b.toCharArray();
   Arrays.sort(c1);
   Arrays.sort(c2);
   return (Arrays.toString(c1).equals(Arrays.toString(c2)));
 }
  @Test
  public void getListOfKeys() throws Exception {
    // We need a fresh instance of the store for this test.
    CredentialStorage credStore1 =
        new PersistentCredentialStorage(TemporaryFileFactory.createTemporaryFile());
    CredentialManagerImpl credMng1 = new CredentialManagerImpl(credStore1);
    Map<URI, SecretKey> keys = new HashMap<URI, SecretKey>();
    for (int i = 0; i != 10; ++i) {
      SecretKey inspectorSecretKey = new SecretKey();
      CryptoParams cryptoParams = new CryptoParams();
      cryptoParams.getContent().add("TestString1");
      inspectorSecretKey.setCryptoParams(cryptoParams);
      keys.put(URI.create(UUID.randomUUID().toString()), inspectorSecretKey);
    }

    for (Map.Entry<URI, SecretKey> k : keys.entrySet()) {
      credMng1.storeInspectorSecretKey(k.getKey(), k.getValue());
    }

    Object[] keysInStore = credMng1.listInspectorSecretKeys().toArray();
    Object[] keysCreated = keys.keySet().toArray();
    // We need to ensure same order.
    Arrays.sort(keysInStore);
    Arrays.sort(keysCreated);
    assertArrayEquals(keysInStore, keysCreated);
  }