Java Examples for java.util.Arrays

The following java examples will help you to understand the usage of java.util.Arrays. These source code samples are taken from different open source projects.

Example 1
Project: sosies-generator-master  File: Base32OutputStreamTest.java View source code
/** 
     * Test method does three tests on the supplied data: 1. encoded ---[DECODE]--> decoded 2. decoded ---[ENCODE]-->
     * encoded 3. decoded ---[WRAP-WRAP-WRAP-etc...] --> decoded
     * <p/>
     * By "[WRAP-WRAP-WRAP-etc...]" we mean situation where the Base32OutputStream wraps itself in encode and decode
     * mode over and over again.
     * 
     * @param encoded
     * Base32 encoded data
     * @param decoded
     * the data from above, but decoded
     * @param chunkSize
     * chunk size (line-length) of the Base32 encoded data.
     * @param separator
     * Line separator in the Base32 encoded data.
     * @throws Exception
     * Usually signifies a bug in the Base32 commons-codec implementation.
     */
private void testByChunk(final byte[] encoded, final byte[] decoded, final int chunkSize, final byte[] separator) throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(), this, "testByChunk");
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    OutputStream out = new Base32OutputStream(byteOut, true, chunkSize, separator);
    out.write(decoded);
    out.close();
    byte[] output = byteOut.toByteArray();
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 1528, null, 1527, java.util.Arrays.equals(output, encoded));
    byteOut = new ByteArrayOutputStream();
    out = new Base32OutputStream(byteOut, false);
    out.write(encoded);
    out.close();
    output = byteOut.toByteArray();
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 1530, null, 1529, java.util.Arrays.equals(output, decoded));
    byteOut = new ByteArrayOutputStream();
    out = byteOut;
    for (int i = 0; i < 10; i++) {
        out = new Base32OutputStream(out, false);
        out = new Base32OutputStream(out, true, chunkSize, separator);
    }
    out.write(decoded);
    out.close();
    output = byteOut.toByteArray();
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(), 1532, null, 1531, java.util.Arrays.equals(output, decoded));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
Example 2
Project: Time4J-master  File: GregorianTransformationTest.java View source code
@Parameters(name = "{index}: unix-days({0}-{1}-{2})={3}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][] { { 1970, 1, 1, 0 }, { 1970, 1, 2, 1 }, { 1970, 1, 31, 30 }, { 1970, 2, 1, 31 }, { 1970, 2, 28, 58 }, { 1970, 3, 1, 59 }, { 1972, 2, 1, 31 + 2 * 365 }, { 1972, 2, 28, 58 + 2 * 365 }, { 1972, 2, 29, 59 + 2 * 365 }, { 1972, 3, 1, 60 + 2 * 365 }, { 1972, 4, 1, 91 + 2 * 365 }, { 1972, 5, 1, 121 + 2 * 365 }, { 1972, 6, 1, 152 + 2 * 365 }, { 1972, 7, 1, 182 + 2 * 365 }, { 1972, 8, 1, 213 + 2 * 365 }, { 1972, 9, 1, 244 + 2 * 365 }, { 1972, 10, 1, 274 + 2 * 365 }, { 1972, 11, 1, 305 + 2 * 365 }, { 1972, 12, 1, 335 + 2 * 365 }, { 1973, 1, 1, 3 * 365 + 1 }, { -4713, 11, 24, -2440588 }, { 2000, 3, 1, 30 * 365 + 31 + 29 + 7 }, { 1899, 12, 31, -25568 }, { 1900, 1, 1, -25567 }, { 1900, 1, 2, -25566 }, { 1900, 1, 3, -25565 }, { 1900, 1, 4, -25564 }, { 1900, 1, 5, -25563 }, { 1900, 1, 6, -25562 }, { 1900, 1, 7, -25561 }, { 1900, 1, 8, -25560 }, { 1900, 1, 9, -25559 }, { 1900, 1, 10, -25558 }, { 1900, 1, 11, -25557 }, { 1900, 1, 12, -25556 }, { 1900, 1, 13, -25555 }, { 1900, 1, 14, -25554 }, { 1900, 1, 15, -25553 }, { 1900, 1, 16, -25552 }, { 1900, 1, 17, -25551 }, { 1900, 1, 18, -25550 }, { 1900, 1, 19, -25549 }, { 1900, 1, 20, -25548 }, { 1900, 1, 21, -25547 }, { 1900, 1, 22, -25546 }, { 1900, 1, 23, -25545 }, { 1900, 1, 24, -25544 }, { 1900, 1, 25, -25543 }, { 1900, 1, 26, -25542 }, { 1900, 1, 27, -25541 }, { 1900, 1, 28, -25540 }, { 1900, 1, 29, -25539 }, { 1900, 1, 30, -25538 }, { 1900, 1, 31, -25537 }, { 1900, 2, 1, -25536 }, { 1900, 2, 2, -25535 }, { 1900, 2, 3, -25534 }, { 1900, 2, 4, -25533 }, { 1900, 2, 5, -25532 }, { 1900, 2, 6, -25531 }, { 1900, 2, 7, -25530 }, { 1900, 2, 8, -25529 }, { 1900, 2, 9, -25528 }, { 1900, 2, 10, -25527 }, { 1900, 2, 11, -25526 }, { 1900, 2, 12, -25525 }, { 1900, 2, 13, -25524 }, { 1900, 2, 14, -25523 }, { 1900, 2, 15, -25522 }, { 1900, 2, 16, -25521 }, { 1900, 2, 17, -25520 }, { 1900, 2, 18, -25519 }, { 1900, 2, 19, -25518 }, { 1900, 2, 20, -25517 }, { 1900, 2, 21, -25516 }, { 1900, 2, 22, -25515 }, { 1900, 2, 23, -25514 }, { 1900, 2, 24, -25513 }, { 1900, 2, 25, -25512 }, { 1900, 2, 26, -25511 }, { 1900, 2, 27, -25510 }, { 1900, 2, 28, -25509 }, { 1900, 3, 1, -25508 }, { 1900, 3, 2, -25507 }, { 1900, 3, 3, -25506 }, { 1900, 3, 4, -25505 }, { 1900, 3, 5, -25504 }, { 1900, 3, 6, -25503 }, { 1900, 3, 7, -25502 }, { 1900, 3, 8, -25501 }, { 1900, 3, 9, -25500 }, { 1900, 3, 10, -25499 }, { 1900, 3, 11, -25498 }, { 1900, 3, 12, -25497 }, { 1900, 3, 13, -25496 }, { 1900, 3, 14, -25495 }, { 1900, 3, 15, -25494 }, { 1900, 3, 16, -25493 }, { 1900, 3, 17, -25492 }, { 1900, 3, 18, -25491 }, { 1900, 3, 19, -25490 }, { 1900, 3, 20, -25489 }, { 1900, 3, 21, -25488 }, { 1900, 3, 22, -25487 }, { 1900, 3, 23, -25486 }, { 1900, 3, 24, -25485 }, { 1900, 3, 25, -25484 }, { 1900, 3, 26, -25483 }, { 1900, 3, 27, -25482 }, { 1900, 3, 28, -25481 }, { 1900, 3, 29, -25480 }, { 1900, 3, 30, -25479 }, { 1900, 3, 31, -25478 }, { 1900, 4, 1, -25477 }, { 1900, 4, 2, -25476 }, { 1900, 4, 3, -25475 }, { 1900, 4, 4, -25474 }, { 1900, 4, 5, -25473 }, { 1900, 4, 6, -25472 }, { 1900, 4, 7, -25471 }, { 1900, 4, 8, -25470 }, { 1900, 4, 9, -25469 }, { 1900, 4, 10, -25468 }, { 1900, 4, 11, -25467 }, { 1900, 4, 12, -25466 }, { 1900, 4, 13, -25465 }, { 1900, 4, 14, -25464 }, { 1900, 4, 15, -25463 }, { 1900, 4, 16, -25462 }, { 1900, 4, 17, -25461 }, { 1900, 4, 18, -25460 }, { 1900, 4, 19, -25459 }, { 1900, 4, 20, -25458 }, { 1900, 4, 21, -25457 }, { 1900, 4, 22, -25456 }, { 1900, 4, 23, -25455 }, { 1900, 4, 24, -25454 }, { 1900, 4, 25, -25453 }, { 1900, 4, 26, -25452 }, { 1900, 4, 27, -25451 }, { 1900, 4, 28, -25450 }, { 1900, 4, 29, -25449 }, { 1900, 4, 30, -25448 }, { 1900, 5, 1, -25447 }, { 1900, 5, 2, -25446 }, { 1900, 5, 3, -25445 }, { 1900, 5, 4, -25444 }, { 1900, 5, 5, -25443 }, { 1900, 5, 6, -25442 }, { 1900, 5, 7, -25441 }, { 1900, 5, 8, -25440 }, { 1900, 5, 9, -25439 }, { 1900, 5, 10, -25438 }, { 1900, 5, 11, -25437 }, { 1900, 5, 12, -25436 }, { 1900, 5, 13, -25435 }, { 1900, 5, 14, -25434 }, { 1900, 5, 15, -25433 }, { 1900, 5, 16, -25432 }, { 1900, 5, 17, -25431 }, { 1900, 5, 18, -25430 }, { 1900, 5, 19, -25429 }, { 1900, 5, 20, -25428 }, { 1900, 5, 21, -25427 }, { 1900, 5, 22, -25426 }, { 1900, 5, 23, -25425 }, { 1900, 5, 24, -25424 }, { 1900, 5, 25, -25423 }, { 1900, 5, 26, -25422 }, { 1900, 5, 27, -25421 }, { 1900, 5, 28, -25420 }, { 1900, 5, 29, -25419 }, { 1900, 5, 30, -25418 }, { 1900, 5, 31, -25417 }, { 1900, 6, 1, -25416 }, { 1900, 6, 2, -25415 }, { 1900, 6, 3, -25414 }, { 1900, 6, 4, -25413 }, { 1900, 6, 5, -25412 }, { 1900, 6, 6, -25411 }, { 1900, 6, 7, -25410 }, { 1900, 6, 8, -25409 }, { 1900, 6, 9, -25408 }, { 1900, 6, 10, -25407 }, { 1900, 6, 11, -25406 }, { 1900, 6, 12, -25405 }, { 1900, 6, 13, -25404 }, { 1900, 6, 14, -25403 }, { 1900, 6, 15, -25402 }, { 1900, 6, 16, -25401 }, { 1900, 6, 17, -25400 }, { 1900, 6, 18, -25399 }, { 1900, 6, 19, -25398 }, { 1900, 6, 20, -25397 }, { 1900, 6, 21, -25396 }, { 1900, 6, 22, -25395 }, { 1900, 6, 23, -25394 }, { 1900, 6, 24, -25393 }, { 1900, 6, 25, -25392 }, { 1900, 6, 26, -25391 }, { 1900, 6, 27, -25390 }, { 1900, 6, 28, -25389 }, { 1900, 6, 29, -25388 }, { 1900, 6, 30, -25387 }, { 1900, 7, 1, -25386 }, { 1900, 7, 2, -25385 }, { 1900, 7, 3, -25384 }, { 1900, 7, 4, -25383 }, { 1900, 7, 5, -25382 }, { 1900, 7, 6, -25381 }, { 1900, 7, 7, -25380 }, { 1900, 7, 8, -25379 }, { 1900, 7, 9, -25378 }, { 1900, 7, 10, -25377 }, { 1900, 7, 11, -25376 }, { 1900, 7, 12, -25375 }, { 1900, 7, 13, -25374 }, { 1900, 7, 14, -25373 }, { 1900, 7, 15, -25372 }, { 1900, 7, 16, -25371 }, { 1900, 7, 17, -25370 }, { 1900, 7, 18, -25369 }, { 1900, 7, 19, -25368 }, { 1900, 7, 20, -25367 }, { 1900, 7, 21, -25366 }, { 1900, 7, 22, -25365 }, { 1900, 7, 23, -25364 }, { 1900, 7, 24, -25363 }, { 1900, 7, 25, -25362 }, { 1900, 7, 26, -25361 }, { 1900, 7, 27, -25360 }, { 1900, 7, 28, -25359 }, { 1900, 7, 29, -25358 }, { 1900, 7, 30, -25357 }, { 1900, 7, 31, -25356 }, { 1900, 8, 1, -25355 }, { 1900, 8, 2, -25354 }, { 1900, 8, 3, -25353 }, { 1900, 8, 4, -25352 }, { 1900, 8, 5, -25351 }, { 1900, 8, 6, -25350 }, { 1900, 8, 7, -25349 }, { 1900, 8, 8, -25348 }, { 1900, 8, 9, -25347 }, { 1900, 8, 10, -25346 }, { 1900, 8, 11, -25345 }, { 1900, 8, 12, -25344 }, { 1900, 8, 13, -25343 }, { 1900, 8, 14, -25342 }, { 1900, 8, 15, -25341 }, { 1900, 8, 16, -25340 }, { 1900, 8, 17, -25339 }, { 1900, 8, 18, -25338 }, { 1900, 8, 19, -25337 }, { 1900, 8, 20, -25336 }, { 1900, 8, 21, -25335 }, { 1900, 8, 22, -25334 }, { 1900, 8, 23, -25333 }, { 1900, 8, 24, -25332 }, { 1900, 8, 25, -25331 }, { 1900, 8, 26, -25330 }, { 1900, 8, 27, -25329 }, { 1900, 8, 28, -25328 }, { 1900, 8, 29, -25327 }, { 1900, 8, 30, -25326 }, { 1900, 8, 31, -25325 }, { 1900, 9, 1, -25324 }, { 1900, 9, 2, -25323 }, { 1900, 9, 3, -25322 }, { 1900, 9, 4, -25321 }, { 1900, 9, 5, -25320 }, { 1900, 9, 6, -25319 }, { 1900, 9, 7, -25318 }, { 1900, 9, 8, -25317 }, { 1900, 9, 9, -25316 }, { 1900, 9, 10, -25315 }, { 1900, 9, 11, -25314 }, { 1900, 9, 12, -25313 }, { 1900, 9, 13, -25312 }, { 1900, 9, 14, -25311 }, { 1900, 9, 15, -25310 }, { 1900, 9, 16, -25309 }, { 1900, 9, 17, -25308 }, { 1900, 9, 18, -25307 }, { 1900, 9, 19, -25306 }, { 1900, 9, 20, -25305 }, { 1900, 9, 21, -25304 }, { 1900, 9, 22, -25303 }, { 1900, 9, 23, -25302 }, { 1900, 9, 24, -25301 }, { 1900, 9, 25, -25300 }, { 1900, 9, 26, -25299 }, { 1900, 9, 27, -25298 }, { 1900, 9, 28, -25297 }, { 1900, 9, 29, -25296 }, { 1900, 9, 30, -25295 }, { 1900, 10, 1, -25294 }, { 1900, 10, 2, -25293 }, { 1900, 10, 3, -25292 }, { 1900, 10, 4, -25291 }, { 1900, 10, 5, -25290 }, { 1900, 10, 6, -25289 }, { 1900, 10, 7, -25288 }, { 1900, 10, 8, -25287 }, { 1900, 10, 9, -25286 }, { 1900, 10, 10, -25285 }, { 1900, 10, 11, -25284 }, { 1900, 10, 12, -25283 }, { 1900, 10, 13, -25282 }, { 1900, 10, 14, -25281 }, { 1900, 10, 15, -25280 }, { 1900, 10, 16, -25279 }, { 1900, 10, 17, -25278 }, { 1900, 10, 18, -25277 }, { 1900, 10, 19, -25276 }, { 1900, 10, 20, -25275 }, { 1900, 10, 21, -25274 }, { 1900, 10, 22, -25273 }, { 1900, 10, 23, -25272 }, { 1900, 10, 24, -25271 }, { 1900, 10, 25, -25270 }, { 1900, 10, 26, -25269 }, { 1900, 10, 27, -25268 }, { 1900, 10, 28, -25267 }, { 1900, 10, 29, -25266 }, { 1900, 10, 30, -25265 }, { 1900, 10, 31, -25264 }, { 1900, 11, 1, -25263 }, { 1900, 11, 2, -25262 }, { 1900, 11, 3, -25261 }, { 1900, 11, 4, -25260 }, { 1900, 11, 5, -25259 }, { 1900, 11, 6, -25258 }, { 1900, 11, 7, -25257 }, { 1900, 11, 8, -25256 }, { 1900, 11, 9, -25255 }, { 1900, 11, 10, -25254 }, { 1900, 11, 11, -25253 }, { 1900, 11, 12, -25252 }, { 1900, 11, 13, -25251 }, { 1900, 11, 14, -25250 }, { 1900, 11, 15, -25249 }, { 1900, 11, 16, -25248 }, { 1900, 11, 17, -25247 }, { 1900, 11, 18, -25246 }, { 1900, 11, 19, -25245 }, { 1900, 11, 20, -25244 }, { 1900, 11, 21, -25243 }, { 1900, 11, 22, -25242 }, { 1900, 11, 23, -25241 }, { 1900, 11, 24, -25240 }, { 1900, 11, 25, -25239 }, { 1900, 11, 26, -25238 }, { 1900, 11, 27, -25237 }, { 1900, 11, 28, -25236 }, { 1900, 11, 29, -25235 }, { 1900, 11, 30, -25234 }, { 1900, 12, 1, -25233 }, { 1900, 12, 2, -25232 }, { 1900, 12, 3, -25231 }, { 1900, 12, 4, -25230 }, { 1900, 12, 5, -25229 }, { 1900, 12, 6, -25228 }, { 1900, 12, 7, -25227 }, { 1900, 12, 8, -25226 }, { 1900, 12, 9, -25225 }, { 1900, 12, 10, -25224 }, { 1900, 12, 11, -25223 }, { 1900, 12, 12, -25222 }, { 1900, 12, 13, -25221 }, { 1900, 12, 14, -25220 }, { 1900, 12, 15, -25219 }, { 1900, 12, 16, -25218 }, { 1900, 12, 17, -25217 }, { 1900, 12, 18, -25216 }, { 1900, 12, 19, -25215 }, { 1900, 12, 20, -25214 }, { 1900, 12, 21, -25213 }, { 1900, 12, 22, -25212 }, { 1900, 12, 23, -25211 }, { 1900, 12, 24, -25210 }, { 1900, 12, 25, -25209 }, { 1900, 12, 26, -25208 }, { 1900, 12, 27, -25207 }, { 1900, 12, 28, -25206 }, { 1900, 12, 29, -25205 }, { 1900, 12, 30, -25204 }, { 1900, 12, 31, -25203 }, { 1901, 1, 1, -25202 } });
}
Example 3
Project: j2objc-master  File: VarargsRewriterTest.java View source code
// Verify that a single object array argument to an object varargs method is passed unchanged.
// Covers all kinds of invocation.
public void testObjectArrayVarargs() throws IOException {
    String translation = translateSourceFile("import java.util.Arrays;" + "interface Baz { void baz(Object[] o); } class Foo<T> { Foo(T... t) {} } class Bar {" + "<T> Bar(T... t) {} Bar(int i, Object[] array) { this(array); } <T> void bar(T... t) {} }" + "enum E { A(new Object[] { }); <T> E(T... t) {} }" + "class Test extends Bar { Test(Object[] array) { super(array); }" + "void test(Object[] array) { " + "Arrays.asList(array); super.bar(array); new Foo(array); Baz b = Arrays::asList;}}", "Test", "Test.m");
    assertTranslation(translation, "E_initWithNSObjectArray_withNSString_withInt_(e, [IOSObjectArray arrayWithObjects:" + "(id[]){  } count:0 type:NSObject_class_()], @\"A\", 0);");
    assertTranslatedLines(translation, "void Bar_initWithInt_withNSObjectArray_(Bar *self, jint i, IOSObjectArray *array) {", "  Bar_initWithNSObjectArray_(self, array);", "}");
    assertTranslatedLines(translation, "void Test_initWithNSObjectArray_(Test *self, IOSObjectArray *array) {", "  Bar_initWithNSObjectArray_(self, array);", "}");
    assertTranslatedLines(translation, "JavaUtilArrays_asListWithNSObjectArray_(array);", "[super barWithNSObjectArray:array];", "create_Foo_initWithNSObjectArray_(array);");
    // Lambda implementation for Arrays::asList.
    assertTranslatedLines(translation, "- (void)bazWithNSObjectArray:(IOSObjectArray *)a {", "  JavaUtilArrays_asListWithNSObjectArray_(a);", "}");
}
Example 4
Project: seasar2-master  File: MessageResourceBundleFactoryTest.java View source code
/**
     * @throws Exception
     */
public void testCalcurateBundleNames() throws Exception {
    // 言語のみ
    String[] bundleNames = MessageResourceBundleFactory.calcurateBundleNames(BASE_NAME, Locale.JAPANESE);
    List expected = java.util.Arrays.asList(new String[] { BASE_NAME, BASE_NAME + "_ja" });
    assertEquals(expected, java.util.Arrays.asList(bundleNames));
    // 言語と国
    bundleNames = MessageResourceBundleFactory.calcurateBundleNames(BASE_NAME, new Locale("ja", "JP"));
    expected = java.util.Arrays.asList(new String[] { BASE_NAME, BASE_NAME + "_ja", BASE_NAME + "_ja_JP" });
    assertEquals(expected, java.util.Arrays.asList(bundleNames));
    // 言語と国とバリアント
    bundleNames = MessageResourceBundleFactory.calcurateBundleNames(BASE_NAME, new Locale("ja", "JP", "WIN"));
    expected = java.util.Arrays.asList(new String[] { BASE_NAME, BASE_NAME + "_ja", BASE_NAME + "_ja_JP", BASE_NAME + "_ja_JP_WIN" });
    assertEquals(expected, java.util.Arrays.asList(bundleNames));
    // 言語とバリアント
    bundleNames = MessageResourceBundleFactory.calcurateBundleNames(BASE_NAME, new Locale("ja", "", "WIN"));
    expected = java.util.Arrays.asList(new String[] { BASE_NAME, BASE_NAME + "_ja", BASE_NAME + "_ja__WIN" });
    assertEquals(expected, java.util.Arrays.asList(bundleNames));
    // 国とバリアント
    bundleNames = MessageResourceBundleFactory.calcurateBundleNames(BASE_NAME, new Locale("", "JP", "WIN"));
    expected = java.util.Arrays.asList(new String[] { BASE_NAME, BASE_NAME + "__JP", BASE_NAME + "__JP_WIN" });
    assertEquals(expected, java.util.Arrays.asList(bundleNames));
    // 国のみ
    bundleNames = MessageResourceBundleFactory.calcurateBundleNames(BASE_NAME, new Locale("", "JP"));
    expected = java.util.Arrays.asList(new String[] { BASE_NAME, BASE_NAME + "__JP" });
    assertEquals(expected, java.util.Arrays.asList(bundleNames));
    // バリアントのみ
    bundleNames = MessageResourceBundleFactory.calcurateBundleNames(BASE_NAME, new Locale("", "", "WIN"));
    expected = java.util.Arrays.asList(new String[] { BASE_NAME, BASE_NAME + "___WIN" });
    assertEquals(expected, java.util.Arrays.asList(bundleNames));
}
Example 5
Project: mldht-master  File: PrefixTest.java View source code
@Test
public void testPrefixMatch() {
    byte[] reference = new byte[20];
    // bit 4
    reference[0] = 0x10;
    Key k = new Key(reference);
    Prefix p = new Prefix(k, 3);
    assertTrue(Arrays.equals(p.getHash(), reference));
    assertTrue(Arrays.equals(p.getParentPrefix().getHash(), new byte[20]));
    assertTrue(Arrays.equals(p.splitPrefixBranch(false).getHash(), tap(new byte[20],  b -> b[0] = 0x10)));
    assertTrue(Arrays.equals(p.splitPrefixBranch(true).getHash(), tap(new byte[20],  b -> b[0] = 0x18)));
    assertTrue(p.isPrefixOf(k));
    assertTrue(p.isPrefixOf(new Key(tap(new byte[20],  b -> b[0] = 0x11))));
    assertTrue(p.isPrefixOf(new Key(tap(new byte[20],  b -> b[0] = 0x1f))));
    assertFalse(p.isPrefixOf(new Key(tap(new byte[20],  b -> b[0] = 0x20))));
    assertFalse(p.isPrefixOf(new Key(tap(new byte[20],  b -> b[0] = (byte) 0x7f))));
}
Example 6
Project: sonar-java-master  File: ReplaceLambdaByMethodRefCheck_no_version.java View source code
void fun() {
    IntStream.range(1, 5).map(( x) -> x * x).map(// Noncompliant {{Replace this lambda with a method reference. (sonar.java.source not set. Assuming 8 or greater.)}}
     x -> square(x)).map(// Noncompliant
     x -> {
        return square(x);
    }).map(//Compliant
    this::square).forEach(System.out::println);
    // Noncompliant
    IntStream.range(1, 5).forEach( x -> System.out.println(x));
    // Noncompliant
    IntStream.range(1, 5).forEach(// Noncompliant
     x -> {
        System.out.println(x);
    });
    // Compliant
    IntStream.range(1, 5).forEach( x -> {
        return;
    });
    // Compliant
    Arrays.asList("bar").stream().filter( string -> string.startsWith("b"));
    // Compliant
    Arrays.asList(new A()).stream().filter( a -> a.coolerThan(0, a));
}
Example 7
Project: eclipselink.runtime-master  File: XSDTypesHolder.java View source code
public boolean equals(Object obj) {
    if (obj instanceof XSDTypesHolder) {
        for (int i = 0; i < things.size(); i++) {
            Object next = things.get(i);
            Object nextCompare = ((XSDTypesHolder) obj).things.get(i);
            if (next instanceof byte[] && nextCompare instanceof byte[]) {
                if (!(Arrays.equals((byte[]) next, (byte[]) nextCompare))) {
                    return false;
                }
            } else if (!next.equals(nextCompare)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Example 8
Project: hank-master  File: TestZooKeeperPlus.java View source code
@Test
public void testIt() throws Exception {
    final ZooKeeperPlus zk = getZk();
    zk.ensureCreated("/", null, CreateMode.PERSISTENT);
    assertExists("/", zk);
    zk.ensureCreated("/simple", "1".getBytes(), CreateMode.PERSISTENT);
    assertExists("/simple", zk);
    zk.ensureCreated("/simple", "2".getBytes(), CreateMode.PERSISTENT);
    assertExists("/simple", zk);
    assertTrue(Arrays.equals(zk.getData("/simple", false, null), "1".getBytes()));
    zk.ensureCreated("/deeper/file", null, CreateMode.PERSISTENT);
    assertExists("/deeper/file", zk);
    assertExists("/deeper", zk);
    zk.ensureCreated("/simple/even/deeper", "3".getBytes(), CreateMode.PERSISTENT);
    assertTrue(Arrays.equals(zk.getData("/simple", false, null), "1".getBytes()));
}
Example 9
Project: LambdaDojo-master  File: S406StreamInsteadOfFor.java View source code
private void wordCount() {
    List<String> sentences = Arrays.asList("Peter Piper picked", "a peck of pickled peppers.", "A peck of pickled peppers", "Peter Piper picked. ", "If Peter Piper picked", "a peck of pickled peppers,", "Where's the peck of pickled peppers", "Peter Piper picked? ");
    Map<String, Integer> result = new HashMap<>();
    for (String sentence : sentences) {
        String[] splitedSentence = sentence.split("[\\.,\\? ]");
        for (String word : splitedSentence) {
            String lowerWord = word.toLowerCase();
            int count = result.getOrDefault(lowerWord, 0);
            result.put(lowerWord, count + 1);
        }
    }
    System.out.println(result);
}
Example 10
Project: breakout-master  File: ReduxTest.java View source code
@Test
public void test1() {
    Store<Number> store = Redux.applyMiddleware(Arrays.asList(new Logger()), Redux.createStore(new Reducer<Number>() {

        @Override
        public Number apply(Number state, Action action) {
            return action.type == "INCREMENT" ? state.intValue() + 1 : state;
        }
    }, 0));
    IntHolder eventCount = new IntHolder();
    Runnable unsub = store.subscribe(() -> eventCount.value++);
    Assert.assertEquals(0, store.getState());
    Assert.assertEquals(0, eventCount.value);
    store.dispatch(new Action("INCREMENT"));
    Assert.assertEquals(1, store.getState());
    Assert.assertEquals(1, eventCount.value);
    unsub.run();
    store.dispatch(new Action("INCREMENT"));
    Assert.assertEquals(2, store.getState());
    Assert.assertEquals(1, eventCount.value);
}
Example 11
Project: java8-tutorial-master  File: Lambda1.java View source code
public static void main(String[] args) {
    List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");
    Collections.sort(names, new Comparator<String>() {

        @Override
        public int compare(String a, String b) {
            return b.compareTo(a);
        }
    });
    Collections.sort(names, (String a, String b) -> {
        return b.compareTo(a);
    });
    Collections.sort(names, (String a, String b) -> b.compareTo(a));
    Collections.sort(names, ( a,  b) -> b.compareTo(a));
    System.out.println(names);
    names.sort(Collections.reverseOrder());
    System.out.println(names);
    List<String> names2 = Arrays.asList("peter", null, "anna", "mike", "xenia");
    names2.sort(Comparator.nullsLast(String::compareTo));
    System.out.println(names2);
    List<String> names3 = null;
    Optional.ofNullable(names3).ifPresent( list -> list.sort(Comparator.naturalOrder()));
    System.out.println(names3);
}
Example 12
Project: xbnjava-master  File: OrderIntListXmpl.java View source code
public static final void main(String[] ignored) {
    int[] aiNums = new int[] { 1, 11, 29, 12, 13, 19, 7, 2, 6, 16, 10, 15, 112, 18, 20, 3, 8, 5, 9, 14 };
    System.out.println("Unsorted: " + Arrays.toString(aiNums));
    ArrayList<Integer> alNums = new ArrayList<Integer>(aiNums.length);
    for (int i : aiNums) {
        alNums.add(i);
    }
    Collections.sort(alNums);
    System.out.println("Sorted: " + Arrays.toString(alNums.toArray()));
    int ixOf12 = Collections.<Integer>binarySearch(alNums, 12);
    System.out.println("Index of number 12: " + ixOf12);
}
Example 13
Project: GlowstonePlusPlus-master  File: BlockPotato.java View source code
@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
    if (block.getData() >= CropState.RIPE.ordinal()) {
        if (random.nextInt(100) < 2) {
            return Collections.unmodifiableList(Arrays.asList(new ItemStack(Material.POTATO_ITEM, random.nextInt(4) + 1), new ItemStack(Material.POISONOUS_POTATO, 1)));
        } else {
            return Collections.unmodifiableList(Arrays.asList(new ItemStack(Material.POTATO_ITEM, random.nextInt(4) + 1)));
        }
    } else {
        return Collections.unmodifiableList(Arrays.asList(new ItemStack(Material.POTATO_ITEM, 1)));
    }
}
Example 14
Project: ARTPart-master  File: Arrays2Test.java View source code
/**
     * java.util.Arrays#binarySearch(double[], double)
     */
public void test_binarySearch$DD() {
    double[] specials = new double[] { Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -2d, -Double.MIN_VALUE, -0d, 0d, Double.MIN_VALUE, 2d, Double.MAX_VALUE, Double.POSITIVE_INFINITY, Double.NaN };
    for (int i = 0; i < specials.length; i++) {
        int result = Arrays.binarySearch(specials, specials[i]);
        assertTrue("Assert 0: " + specials[i] + " invalid: " + result, result == i);
    }
    assertEquals("Assert 1: Invalid search index for -1d", -4, Arrays.binarySearch(specials, -1d));
    assertEquals("Assert 2: Invalid search index for 1d", -8, Arrays.binarySearch(specials, 1d));
}
Example 15
Project: checkstyle-master  File: InputMethodReferences.java View source code
public void main(String[] args) {
    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
    numbers.forEach(String.CASE_INSENSITIVE_ORDER::equals);
    InputMethodReferences tl = new InputMethodReferences();
    String roster = new String();
    Supplier<InputMethodReferences> supplier = InputMethodReferences<String>::new;
    numbers.forEach(this::println);
    numbers.forEach(super::println);
    Supplier<InputMethodReferences2> supplier2 = InputMethodReferences2::new;
    Supplier<InputMethodReferences2> suppl = InputMethodReferences2::<Integer>new;
    Function<Integer, String[]> messageArrayFactory = String[]::new;
}
Example 16
Project: abmash-master  File: HeadlinePredicate.java View source code
@Override
public void buildCommands() {
    List<String> headlineSelectors = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6");
    JQuery elementsWithBiggerFontSize = // all elements but inputs and iframes
    JQueryFactory.select("'*:not(input,iframe)'", 50).filterCSS("font-size", CSSAttributeComparator.GREATER_THAN, // elements with bigger font size
    "jQuery(document.body).css('font-size')").filter(// only elements with inner text
    "function() { return jQuery(this).text().trim().length; }");
    if (text != null) {
        containsText("'" + StringUtils.join(headlineSelectors, ',') + "'", text);
        containsAttribute("'" + StringUtils.join(headlineSelectors, ',') + "'", "*", text);
        containsText(elementsWithBiggerFontSize, text);
        containsAttribute(elementsWithBiggerFontSize, "*", text);
    } else {
        add(JQueryFactory.select("'" + StringUtils.join(headlineSelectors, ',') + "'", 100));
        add(elementsWithBiggerFontSize);
    }
}
Example 17
Project: ilarkesto-master  File: GwtServiceInterfaceGenerator.java View source code
@Override
protected void printCode(JavaPrinter out) {
    out.package_(getPackageName());
    out.beginInterface(module.getValue() + "Service", Arrays.asList(com.google.gwt.user.client.rpc.RemoteService.class.getName()));
    List<Node> calls = module.getChildrenByTypeRecursive(ServiceCall);
    for (Node call : calls) {
        List<String> params = getParameterTypesAndNames(call, "String");
        params.add(0, "int conversationNumber");
        out.interfaceMethod(getPackageName() + ".DataTransferObject", Str.lowercaseFirstLetter(call.getValue()), params);
    }
    out.endInterface();
}
Example 18
Project: usercenter-master  File: SimpleCredentialsMatcher.java View source code
protected boolean equals(Object tokenCredentials, Object accountCredentials) {
    if (log.isDebugEnabled()) {
        log.debug("Performing credentials equality check for tokenCredentials of type [" + tokenCredentials.getClass().getName() + " and accountCredentials of type [" + accountCredentials.getClass().getName() + "]");
    }
    if (isByteSource(tokenCredentials) && isByteSource(accountCredentials)) {
        if (log.isDebugEnabled()) {
            log.debug("Both credentials arguments can be easily converted to byte arrays.  Performing " + "array equals comparison");
        }
        byte[] tokenBytes = toBytes(tokenCredentials);
        byte[] accountBytes = toBytes(accountCredentials);
        return Arrays.equals(tokenBytes, accountBytes);
    } else {
        return accountCredentials.equals(tokenCredentials);
    }
}
Example 19
Project: sitebricks-master  File: FlatTemplateCompiler.java View source code
public Renderable compile(Class<?> page, Template template) {
    try {
        return registry.textWidget(template.getText(), new MvelEvaluatorCompiler(page));
    } catch (ExpressionCompileException e) {
        final List<CompileError> errors = Arrays.asList(CompileError.in(template.getText()).near(e.getError().getError().getLineNumber()).causedBy(e));
        final List<CompileError> warnings = Collections.emptyList();
        metrics.logErrorsAndWarnings(page, errors, warnings);
        throw new TemplateCompileException(page, template.getText(), errors, warnings);
    }
}
Example 20
Project: violetumleditor-master  File: MenuUtils.java View source code
public static void alterMenuBar(JMenuBar menuBar) {
    MenuElement[] subMenuElements = menuBar.getSubElements();
    List<MenuElement> menuEntryStack = new ArrayList<MenuElement>();
    if (subMenuElements.length > 0) {
        menuEntryStack.addAll(Arrays.asList(subMenuElements));
    }
    while (!menuEntryStack.isEmpty()) {
        MenuElement menuElement = menuEntryStack.get(0);
        if (menuElement instanceof JMenuItem) {
            final JMenuItem menuItem = (JMenuItem) menuElement;
            menuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    System.out.println(menuItem.getName());
                }
            });
        }
        MenuElement[] subElements = menuElement.getSubElements();
        if (subElements.length > 0) {
            menuEntryStack.addAll(Arrays.asList(subElements));
        }
        menuEntryStack.remove(0);
    }
}
Example 21
Project: quickml-master  File: PenalizedMSEScorerTest.java View source code
@Test
public void simpleTest() {
    ClassificationCounter a = new ClassificationCounter();
    a.addClassification("a", 4);
    a.addClassification("b", 9);
    a.addClassification("c", 1);
    ClassificationCounter b = new ClassificationCounter();
    b.addClassification("a", 5);
    b.addClassification("b", 9);
    b.addClassification("c", 6);
    PenalizedMSEScorer mseScorer = new PenalizedMSEScorer(0, 0.0, new AttributeStats<>(Arrays.asList(a, b), a.add(b), "a"));
    Assert.assertTrue(Math.abs(mseScorer.scoreSplit(a, b) - 0.021776929) < 0.000000001);
}
Example 22
Project: OSM2World-master  File: CAGUtilTest.java View source code
@Test
public void testOverlap() {
    List<VectorXZ> outline = asList(new VectorXZ(1, -2), new VectorXZ(1, 2), new VectorXZ(-1, 2), new VectorXZ(-1, -2), new VectorXZ(1, -2));
    List<VectorXZ> subOutline = asList(new VectorXZ(2, -1), new VectorXZ(0, -1), new VectorXZ(0, 1), new VectorXZ(2, 1), new VectorXZ(2, -1));
    List<PolygonWithHolesXZ> results = new ArrayList<PolygonWithHolesXZ>(CAGUtil.subtractPolygons(new SimplePolygonXZ(outline), Arrays.asList(new SimplePolygonXZ(subOutline))));
    assertSame(1, results.size());
    assertSameCyclicOrder(results.get(0).getOuter().getVertices(), new VectorXZ(1, -2), new VectorXZ(1, -1), new VectorXZ(0, -1), new VectorXZ(0, 1), new VectorXZ(1, 1), new VectorXZ(1, 2), new VectorXZ(-1, 2), new VectorXZ(-1, -2));
}
Example 23
Project: DrakkarKeel-master  File: _ConfigurationDisp.java View source code
public Ice.DispatchStatus __dispatch(IceInternal.Incoming in, Ice.Current __current) {
    int pos = java.util.Arrays.binarySearch(__all, __current.operation);
    if (pos < 0) {
        throw new Ice.OperationNotExistException(__current.id, __current.facet, __current.operation);
    }
    switch(pos) {
        case 0:
            {
                return drakkar.oar.slice.action.twoway._GetDisp.___getAMID(this, in, __current);
            }
        case 1:
            {
                return drakkar.oar.slice.action.twoway._GetDisp.___getSAMI(this, in, __current);
            }
        case 2:
            {
                return ___ice_id(this, in, __current);
            }
        case 3:
            {
                return ___ice_ids(this, in, __current);
            }
        case 4:
            {
                return ___ice_isA(this, in, __current);
            }
        case 5:
            {
                return ___ice_ping(this, in, __current);
            }
        case 6:
            {
                return drakkar.oar.slice.action.oneway._SendDisp.___sendAMID(this, in, __current);
            }
        case 7:
            {
                return drakkar.oar.slice.action.oneway._SendDisp.___sendSAMI(this, in, __current);
            }
    }
    assert (false);
    throw new Ice.OperationNotExistException(__current.id, __current.facet, __current.operation);
}
Example 24
Project: dove-master  File: SHA1.java View source code
/**
     * 用SHA1算法生成安全签名
     * 
     * @param token 票据
     * @param timestamp 时间戳
     * @param nonce 随机字符串
     * @param encrypt 密文
     * @return 安全签名
     * @throws AesException 
     */
public static String getSHA1(String token, String timestamp, String nonce, String encrypt) throws AesException {
    try {
        String[] array = new String[] { token, timestamp, nonce, encrypt };
        StringBuffer sb = new StringBuffer();
        // 字符串排序
        Arrays.sort(array);
        for (int i = 0; i < 4; i++) {
            sb.append(array[i]);
        }
        String str = sb.toString();
        // SHA1签名生成
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update(str.getBytes());
        byte[] digest = md.digest();
        StringBuffer hexstr = new StringBuffer();
        String shaHex = "";
        for (int i = 0; i < digest.length; i++) {
            shaHex = Integer.toHexString(digest[i] & 0xFF);
            if (shaHex.length() < 2) {
                hexstr.append(0);
            }
            hexstr.append(shaHex);
        }
        return hexstr.toString();
    } catch (Exception e) {
        throw new AesException(AesException.COMPUTE_SIGNATURE_ERROR);
    }
}
Example 25
Project: molgenis-master  File: TokenAuthenticationFilterTest.java View source code
@Test
public void doFilter() throws IOException, ServletException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain chain = mock(FilterChain.class);
    RestAuthenticationToken auth = new RestAuthenticationToken("admin", "admin", Arrays.asList(new SimpleGrantedAuthority("admin")), "token");
    request.setRequestURI("/api/v1/dataset");
    request.addHeader(TokenExtractor.TOKEN_HEADER, "token");
    when(authenticationProvider.authenticate(new RestAuthenticationToken("token"))).thenReturn(auth);
    filter.doFilter(request, response, chain);
    verify(chain).doFilter(request, response);
    assertEquals(SecurityContextHolder.getContext().getAuthentication(), auth);
}
Example 26
Project: androiddevice.info-master  File: PackageSigProperty.java View source code
@Override
public Object getProperty() {
    try {
        JSONArray result = new JSONArray();
        PackageInfo packageInfo = Application.getContext().getPackageManager().getPackageInfo("android", PackageManager.GET_SIGNATURES);
        for (Signature item : Arrays.asList(packageInfo.signatures)) {
            MessageDigest digest = null;
            try {
                digest = MessageDigest.getInstance("SHA-256");
                digest.update(item.toCharsString().getBytes());
                result.put(byteToHexString(digest.digest()));
            } catch (NoSuchAlgorithmException e) {
            }
        }
        return result;
    } catch (PackageManager.NameNotFoundException e) {
        return JSONObject.NULL;
    }
}
Example 27
Project: MyFramework-master  File: DateHelper.java View source code
public static Date parseDate(String value, Class targetType, String... formats) {
    for (String format : formats) {
        try {
            long v = new SimpleDateFormat(format).parse(value).getTime();
            return (Date) targetType.getConstructor(long.class).newInstance(v);
        } catch (ParseException e) {
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        try {
            return (Date) targetType.getConstructor(String.class).newInstance(value);
        } catch (Exception e) {
        }
    }
    throw new IllegalArgumentException("cannot parse:" + value + " for date by formats:" + Arrays.asList(formats));
}
Example 28
Project: openjdk-master  File: TypeNameTest.java View source code
public void testBounds() {
    assertEval("java.util.List<? extends String> list1 = java.util.Arrays.asList(\"\");");
    VarSnippet sn1 = (VarSnippet) varKey(assertEval("list1.iterator().next()"));
    assertEquals(sn1.typeName(), "String");
    assertEval("java.util.List<? super String> list2 = java.util.Arrays.asList(\"\");");
    VarSnippet sn2 = (VarSnippet) varKey(assertEval("list2.iterator().next()"));
    assertEquals(sn2.typeName(), "Object");
    assertEval("java.util.List<?> list3 = java.util.Arrays.asList(\"\");");
    VarSnippet sn3 = (VarSnippet) varKey(assertEval("list3.iterator().next()"));
    assertEquals(sn3.typeName(), "Object");
    assertEval("class Test1<X extends CharSequence> { public X get() { return null; } }");
    Snippet x = varKey(assertEval("Test1<?> test1 = new Test1<>();"));
    VarSnippet sn4 = (VarSnippet) varKey(assertEval("test1.get()"));
    assertEquals(sn4.typeName(), "Object");
    assertEval("class Test2<X extends Number & CharSequence> { public X get() { return null; } }");
    assertEval("Test2<?> test2 = new Test2<>();");
    VarSnippet sn5 = (VarSnippet) varKey(assertEval("test2.get()"));
    assertEquals(sn5.typeName(), "Object");
    assertEval("class Test3<T> { T[][] get() { return null; } }", added(VALID));
    assertEval("Test3<? extends String> test3 = new Test3<>();");
    VarSnippet sn6 = (VarSnippet) varKey(assertEval("test3.get()"));
    assertEquals(sn6.typeName(), "String[][]");
}
Example 29
Project: cloudtm-data-platform-master  File: ConverterClassAwareDmlCompiler.java View source code
public static void main(String[] args) throws Exception {
    final int c = args.length;
    final int offset = c - 3;
    final File dir = new File(args[offset]);
    final String[] baseArgs;
    if (dir.exists() && dir.isDirectory()) {
        final List<String> dmlFilenames = new ArrayList<String>();
        for (final File file : dir.listFiles()) {
            if (file.isFile() && file.getName().endsWith(".dml")) {
                dmlFilenames.add(file.getCanonicalPath());
            }
        }
        Collections.sort(dmlFilenames);
        List<URL> pluginDmlUrlList = PluginDmlUrlLoader.getPluginDmlUrlList();
        baseArgs = new String[c - 3 + dmlFilenames.size() + pluginDmlUrlList.size()];
        System.arraycopy(args, 0, baseArgs, 0, offset);
        int i = offset;
        for (URL pluginDmlUrl : pluginDmlUrlList) {
            baseArgs[i++] = pluginDmlUrl.toExternalForm();
        }
        for (final String dmlFilename : dmlFilenames) {
            baseArgs[i++] = dmlFilename;
        }
    } else {
        baseArgs = Arrays.copyOfRange(args, 0, c - 2);
    }
    DmlCompiler.main(baseArgs);
}
Example 30
Project: btpka3.github.com-master  File: PinyinTest.java View source code
@Test
public void test1() throws Exception {
    HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
    defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
    defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    defaultFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
    String[] strs = PinyinHelper.toHanyuPinyinStringArray('禅', defaultFormat);
    System.out.println(Arrays.asList(strs));
    strs = PinyinHelper.toHanyuPinyinStringArray('a', defaultFormat);
    System.out.println("--" + (strs == null ? "null" : Arrays.asList(strs)));
}
Example 31
Project: RoboBuggy-master  File: JNISetup.java View source code
/**
     * Includes all of the jni libraries that we need to be able to use all of our libraries
     *
     * @return true iff the setup completes successfully
     * @throws NoSuchFieldException     couldn't find the usr_paths
     * @throws SecurityException        couldn't get the field
     * @throws IllegalArgumentException didn't have the right params for the reflected method
     * @throws IllegalAccessException   reflected method didn't exist
     */
public static boolean setupJNI() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    final String pathToAdd = "library";
    final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
    usrPathsField.setAccessible(true);
    //get array of paths
    final String[] paths = (String[]) usrPathsField.get(null);
    //check if the path to add is already present
    for (final String path : paths) {
        if (path.equals(pathToAdd)) {
            return true;
        }
    }
    //add the new path
    final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
    newPaths[newPaths.length - 1] = pathToAdd;
    usrPathsField.set(null, newPaths);
    return true;
}
Example 32
Project: expenditures-master  File: FenixJasperCompiler.java View source code
@Override
public String compileClasses(File[] sourceFiles, String classpath) throws JRException {
    // Retrieve files from the standard location
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> sources = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(sourceFiles));
    CompilationTask task = compiler.getTask(new StringWriter(), fileManager, null, Arrays.asList("-classpath", classpath), null, sources);
    if (!task.call()) {
        throw new JRException("Error compiling report java source files");
    }
    return null;
}
Example 33
Project: jnlp-master  File: TestNLP.java View source code
public static void main(String[] args) throws Exception {
    NLP nlp = new NLP("这个东西真心很赞");
    System.out.println(nlp.words());
    System.out.println(nlp.tags());
    System.out.println(nlp.sentiments());
    System.out.println(nlp.pinyin());
    nlp = new NLP("「繁體字」「繁體中文」的叫法在臺灣亦很常見。");
    System.out.println(nlp.han());
    String text = "自然语言处理是计算机科学领域与人工智能领域中的一个重要方向。\r\n它研究能实现人与计算机之间用自然语言进行有效通信的各种理论和方法。\r\n自然语言处理是一门融语言学、计算机科学、数学于一体的科学。\r\n因此,这一领域的研究将涉及自然语言,即人们日常使用的语言,\r\n所以它与语言学的研究有着密切的联系,但又有重要的区别。\r\n自然语言处理并不是一般地研究自然语言,\r\n而在于研制能有效地实现自然语言通信的计算机系统,\r\n特别是其中的软件系统。因而它是计算机科学的一部分。";
    nlp = new NLP(text);
    System.out.println(nlp.keywords(5));
    System.out.println(nlp.summary(3));
    System.out.println(nlp.sentences());
    List<List<String>> test = new ArrayList<List<String>>();
    test.add(Arrays.asList("这篇", "文章"));
    test.add(Arrays.asList("那篇", "论文"));
    test.add(Arrays.asList("这个"));
    nlp = new NLP(test);
    System.out.println(nlp.tf());
    System.out.println(nlp.idf());
    System.out.println(nlp.sim(Arrays.asList("文章")));
}
Example 34
Project: deb-kitkat-storage-access-framework-master  File: TestUtils.java View source code
public static LiveConnectSession newMockLiveConnectSession() {
    LiveAuthClient authClient = TestUtils.newMockLiveAuthClient();
    LiveConnectSession session = new LiveConnectSession(authClient);
    session.setAccessToken("access_token");
    session.setAuthenticationToken("authentication_token");
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.SECOND, 3600);
    session.setExpiresIn(calendar.getTime());
    String[] scopes = { "scope" };
    session.setScopes(Arrays.asList(scopes));
    session.setRefreshToken("refresh_token");
    session.setTokenType("token_type");
    return session;
}
Example 35
Project: raylew_algorithm-master  File: 组合问题.java View source code
public static void dfs(int cur) {
    int sum = 0;
    for (int i = 0; i < cur; i++) {
        sum += res[i];
    }
    if (sum >= goal) {
        if (sum == goal) {
            total++;
            for (int i = 0; i < cur; i++) {
                System.out.print(res[i] + ",");
            }
            System.out.println();
        }
        return;
    }
    int index = Arrays.binarySearch(arr, 2);
    for (int i = index; i < N; i++) {
        if (cur == 0) {
            res[cur] = arr[i];
            dfs(cur + 1);
        } else {
            if (arr[i] >= res[cur - 1]) {
                res[cur] = arr[i];
                dfs(cur + 1);
            }
        }
    }
}
Example 36
Project: codemap-master  File: DijkstrasAlgorithm.java View source code
public static int[] apply(Graph g, int source) {
    int[] dist = new int[g.nodes.length];
    boolean[] done = new boolean[g.nodes.length];
    Node[] todo = new Node[g.nodes.length];
    Arrays.fill(dist, Integer.MAX_VALUE);
    int index = 0;
    todo[index++] = g.nodes[source];
    done[source] = true;
    dist[source] = 0;
    for (int n = 0; n < todo.length; n++) {
        Node node = todo[n];
        if (node == null)
            break;
        int d = dist[node.index] + 1;
        for (Node each : node.edges) {
            if (done[each.index])
                continue;
            todo[index++] = each;
            dist[each.index] = d;
            done[each.index] = true;
        }
    }
    return dist;
}
Example 37
Project: tmdm-studio-se-master  File: ProcessAllCallJobVariableCandidatesHolder.java View source code
@Override
public String[] getExternalInfo() {
    if (service == null) {
        return new String[0];
    }
    Set<String> inputVariables = new HashSet<String>();
    for (WSTransformerProcessStep step : service.getProcessSteps()) {
        for (WSTransformerVariablesMapping mapping : step.getInputMappings()) {
            inputVariables.add(mapping.getPipelineVariable() == null ? TransformerMainPage.DEFAULT_VAR : mapping.getPipelineVariable());
        }
    }
    String[] results = inputVariables.toArray(new String[0]);
    Arrays.sort(results);
    return results;
}
Example 38
Project: many-ql-master  File: TestComputedQuestion.java View source code
@Parameters
public static Collection<Object[]> data() {
    return Arrays.asList(new Object[][] { { createComputedQuestion("boolean", "true"), true }, { createComputedQuestion("integer", "5"), true }, { createComputedQuestion("integer", "5.0"), true }, { createComputedQuestion("float", "5"), true }, { createComputedQuestion("float", "5.0"), true }, { createComputedQuestion("money", "5"), true }, { createComputedQuestion("money", "5.0"), true }, { createComputedQuestion("string", "\"String\""), true }, { createComputedQuestion("boolean", "5"), false }, { createComputedQuestion("boolean", "5.0"), false }, { createComputedQuestion("boolean", "\"String\""), false }, { createComputedQuestion("integer", "true"), false }, { createComputedQuestion("integer", "\"String\""), false }, { createComputedQuestion("float", "true"), false }, { createComputedQuestion("float", "\"String\""), false }, { createComputedQuestion("money", "true"), false }, { createComputedQuestion("money", "\"String\""), false }, { createComputedQuestion("string", "true"), false }, { createComputedQuestion("string", "5"), false }, { createComputedQuestion("string", "5.0"), false } });
}
Example 39
Project: framework-master  File: ComboBoxTextFieldEventOrder.java View source code
@Override
protected void setup() {
    TextField textField = new TextField("text field");
    textField.setImmediate(true);
    final Select select = new Select("select", Arrays.asList("1", "2", "3", "4"));
    textField.addListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            // or
            select.addItem(Long.valueOf(select.size() + 1).toString());
        // just
        // select.requestRepaint();
        }
    });
    addComponent(textField);
    addComponent(select);
}
Example 40
Project: GATECH-master  File: DataSetLabelBinarySeperator.java View source code
public static void seperateLabels(DataSet set) {
    int numberOfLabels = 0;
    ArrayList<Integer> labels = new ArrayList<Integer>();
    //count up the number of distinct labels
    for (int i = 0; i < set.size(); i++) {
        if (!labels.contains(new Integer(set.getInstances()[i].getLabel().getDiscrete()))) {
            numberOfLabels++;
            labels.add(new Integer(set.getInstances()[i].getLabel().getDiscrete()));
        }
    }
    double[] values = new double[numberOfLabels];
    for (int i = 0; i < values.length; i++) {
        values[i] = 0;
    }
    for (int i = 0; i < set.size(); i++) {
        int labelValue = set.getInstances()[i].getLabel().getDiscrete() % values.length;
        values[labelValue] = 1;
        Instance instance = new Instance(Arrays.copyOf(values, values.length));
        set.get(i).setLabel(instance);
        values[labelValue] = 0;
    }
}
Example 41
Project: CodingSpectator-master  File: RemoveFilterDialog.java View source code
public void prompt(Shell shell) {
    ListDialog dialog = new ListDialog(shell) {

        @Override
        protected int getTableStyle() {
            return super.getTableStyle() - SWT.SINGLE + SWT.MULTI;
        }
    };
    dialog.setTitle(Messages.RemoveFilterDialog_0);
    dialog.setMessage(Messages.RemoveFilterDialog_1);
    dialog.setAddCancelButton(true);
    dialog.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return (String) element;
        }
    });
    dialog.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            return (Object[]) inputElement;
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    String[] filterPatterns = filter.getFilterPatterns();
    Arrays.sort(filterPatterns);
    dialog.setInput(filterPatterns);
    dialog.open();
    Object[] selected = dialog.getResult();
    if (selected == null)
        return;
    filter.removeFilterPatterns(selected);
}
Example 42
Project: cassandra-dev-master  File: CommitLogTest.java View source code
@Test
public void testMain() throws IOException {
// TODO this is useless, since it assumes we have a working set of commit logs to parse
/*
        File logDir = new File(DatabaseDescriptor.getLogFileLocation());
        File[] files = logDir.listFiles();
        Arrays.sort( files, new FileUtils.FileComparator() );

        byte[] bytes = new byte[CommitLogHeader.size(Integer.parseInt(args[0]))];
        for ( File file : files )
        {
            CommitLog clog = new CommitLog( file );
            clog.readCommitLogHeader(file.getAbsolutePath(), bytes);
            DataInputBuffer bufIn = new DataInputBuffer();
            bufIn.reset(bytes, 0, bytes.length);
            CommitLogHeader clHeader = CommitLogHeader.serializer().deserialize(bufIn);

            StringBuilder sb = new StringBuilder("");
            for ( byte b : bytes )
            {
                sb.append(b);
                sb.append(" ");
            }

            System.out.println("FILE:" + file);
            System.out.println(clHeader.toString());
        }
        */
}
Example 43
Project: cms-ce-master  File: PreferenceXmlCreatorTest.java View source code
@Test
public void testCreatePreferencesDocumentMultiple() throws Exception {
    final String expectedXml = getXml("/com/enonic/cms/core/preference/MultiplePreferencesDocument-result.xml");
    final PreferenceEntity pref1 = new PreferenceEntity();
    final PreferenceKey key1 = new PreferenceKey("user:ABC1234.GLOBAL.key1");
    pref1.setKey(key1);
    pref1.setValue("value1");
    final PreferenceEntity pref2 = new PreferenceEntity();
    final PreferenceKey key2 = new PreferenceKey("user:ABC1234.GLOBAL.key2");
    pref2.setKey(key2);
    pref2.setValue("value2");
    final XMLDocument xmlDoc = PreferenceXmlCreator.createPreferencesDocument(Arrays.asList(pref1, pref2));
    assertEquals(expectedXml, getFormattedXmlString(xmlDoc));
}
Example 44
Project: JBound-master  File: Exercises.java View source code
protected Restriction forClasses(final Class<?> exercisedClass, final Class<?>... otherExercisedClasses) {
    if (exercisedClass == null) {
        throw new NullPointerException("exercisedClass can not be null");
    }
    if (otherExercisedClasses == null) {
        throw new NullPointerException("otherExercisedClasses can not be null");
    }
    final List<Class<?>> exercisedClasses = new ArrayList<Class<?>>();
    exercisedClasses.add(exercisedClass);
    exercisedClasses.addAll(Arrays.asList(otherExercisedClasses));
    final Builder builder = new Builder(exercisedClasses);
    exercisesBuilders.add(builder);
    return builder;
}
Example 45
Project: lettuce-master  File: ConnectToMasterSlaveUsingElastiCacheCluster.java View source code
public static void main(String[] args) {
    // Syntax: redis://[password@]host[:port][/databaseNumber]
    RedisClient redisClient = RedisClient.create();
    List<RedisURI> nodes = Arrays.asList(RedisURI.create("redis://host1"), RedisURI.create("redis://host2"), RedisURI.create("redis://host3"));
    StatefulRedisMasterSlaveConnection<String, String> connection = MasterSlave.connect(redisClient, new Utf8StringCodec(), nodes);
    connection.setReadFrom(ReadFrom.MASTER_PREFERRED);
    System.out.println("Connected to Redis");
    connection.close();
    redisClient.shutdown();
}
Example 46
Project: eclipse.jdt.core-master  File: A_out.java View source code
public void function1(Object param1, Object param2, Object param3, Object param4) throws Exc1, Ex2, Ex3 {
    List<String> strings = Arrays.asList("aaa", "bbb", "ccc", "ddd");
    int aa = 11111, bb = 22222, cc = 33333, dd = 44444;
    param1.field1.field2.field3.function();
    param2.function1().function2().function3().function4();
    String sss1 = this.array.length > 3 ? "yes" : "no";
    String sss2 = this.array.length > 3 ? "yes" : "no";
    try (InputStream in = new IStream();
        OutputStream out = new OStream();
        Object o = null) {
        System.out.println(aa * (aa + bb) * cc * (cc + aa));
    } catch (Exception1Exception2 | Exception3 |  e) {
        System.out.println(param3.function1(aa, bb));
    }
    this.getWriter().println("aaaaa" + //
    "bbbbbb" + "ccc");
}
Example 47
Project: ocr-tools-master  File: ResultXmlMergerTest.java View source code
@Test
public void shouldMergeTwoWellFormed() throws XpathException, SAXException, IOException {
    InputStream stream1 = new ByteArrayInputStream(input1.getBytes());
    InputStream stream2 = new ByteArrayInputStream(input2.getBytes());
    List<InputStream> inputs = Arrays.asList(stream1, stream2);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    Merger mergerSut = new ResultXmlMerger();
    mergerSut.mergeBuffered(inputs, output);
    String result = output.toString();
    System.out.println(result);
    assertXpathEvaluatesTo("2", "count(//Statistics)", result);
    assertXpathEvaluatesTo("1500", "sum([email protected])", result);
    assertXpathEvaluatesTo("150", "sum([email protected])", result);
}
Example 48
Project: MUtils-master  File: ThreadUtil.java View source code
/**
     * Get threads for group
     */
public static Thread[] getGroup(String name) {
    Thread[] activeThreads = new Thread[Thread.activeCount()];
    int enumCount = Thread.enumerate(activeThreads);
    LinkedList<Thread> group = new LinkedList<Thread>();
    for (int i = 0; i < enumCount; i++) {
        Thread t = activeThreads[i];
        ThreadGroup tGroup = t.getThreadGroup();
        if (tGroup == null) {
            continue;
        }
        String gName = tGroup.getName();
        if (gName != null && gName.equals(name)) {
            group.add(t);
        }
    }
    Arrays.fill(activeThreads, null);
    Thread[] groupThreads = new Thread[group.size()];
    group.toArray(groupThreads);
    group.clear();
    return groupThreads;
}
Example 49
Project: McMMOPlus-master  File: AlchemyBrewCheckTask.java View source code
@Override
public void run() {
    Location location = brewingStand.getLocation();
    ItemStack[] newInventory = Arrays.copyOfRange(brewingStand.getInventory().getContents(), 0, 4);
    boolean validBrew = AlchemyPotionBrewer.isValidBrew(player, newInventory);
    if (Alchemy.brewingStandMap.containsKey(location)) {
        if (oldInventory[Alchemy.INGREDIENT_SLOT] == null || newInventory[Alchemy.INGREDIENT_SLOT] == null || !oldInventory[Alchemy.INGREDIENT_SLOT].isSimilar(newInventory[Alchemy.INGREDIENT_SLOT]) || !validBrew) {
            Alchemy.brewingStandMap.get(location).cancelBrew();
        }
    } else if (validBrew) {
        Alchemy.brewingStandMap.put(location, new AlchemyBrewTask(brewingStand, player));
    }
}
Example 50
Project: openjdk8-jdk-master  File: MacClone.java View source code
private static void doTest(String algo, SecretKey skey, AlgorithmParameterSpec params) throws Exception {
    //
    // Clone an uninitialized Mac object
    //
    Mac mac = Mac.getInstance(algo, "SunJCE");
    Mac macClone = (Mac) mac.clone();
    System.out.println(macClone.getProvider().toString());
    System.out.println(macClone.getAlgorithm());
    boolean thrown = false;
    try {
        macClone.update((byte) 0x12);
    } catch (IllegalStateException ise) {
        thrown = true;
    }
    if (!thrown) {
        throw new Exception("Expected IllegalStateException not thrown");
    }
    //
    // Clone an initialized Mac object
    //
    mac = Mac.getInstance(algo, "SunJCE");
    mac.init(skey, params);
    macClone = (Mac) mac.clone();
    System.out.println(macClone.getProvider().toString());
    System.out.println(macClone.getAlgorithm());
    mac.update((byte) 0x12);
    macClone.update((byte) 0x12);
    byte[] macFinal = mac.doFinal();
    byte[] macCloneFinal = macClone.doFinal();
    if (!java.util.Arrays.equals(macFinal, macCloneFinal)) {
        throw new Exception("ERROR: MAC result of init clone is different");
    } else
        System.out.println("MAC check#1 passed");
    //
    // Clone an updated Mac object
    //
    mac.update((byte) 0x12);
    macClone = (Mac) mac.clone();
    mac.update((byte) 0x34);
    macClone.update((byte) 0x34);
    macFinal = mac.doFinal();
    macCloneFinal = macClone.doFinal();
    if (!java.util.Arrays.equals(macFinal, macCloneFinal)) {
        throw new Exception("ERROR: MAC result of updated clone is different");
    } else
        System.out.println("MAC check#2 passed");
}
Example 51
Project: neo4j-jdbc-master  File: ResultSetTest.java View source code
@SuppressWarnings("unchecked")
@Parameterized.Parameters
public static Collection<ResultSet[]> data() {
    row = Arrays.<Object>asList("0", 1, (short) 2, 3L, (byte) 4, 5f, 6d, BigDecimal.valueOf(7L), null, new String[] { "array" }, Collections.singletonMap("a", 1), Collections.singletonList("list"));
    List<Neo4jColumnMetaData> columns = asList(col("String", Types.VARCHAR), col("int", Types.INTEGER), col("short", Types.SMALLINT), col("long", Types.BIGINT), col("byte", Types.TINYINT), col("float", Types.FLOAT), col("double", Types.DOUBLE), col("BigDecimal", Types.NUMERIC), col("Null", Types.NULL), col("Array", Types.ARRAY), col("Map", Types.STRUCT), col("List", Types.ARRAY));
    return Arrays.<ResultSet[]>asList(new ResultSet[] { new ListResultSet(columns, Arrays.<List<Object>>asList(row), null) }, new ResultSet[] { new IteratorResultSet(columns, Arrays.<Object[]>asList(row.toArray()).iterator(), null) });
}