Recently shared snippets for language "Java"

public static void main(String[] args) {

		List<String> listwithnulls = new ArrayList<String>();
		listwithnulls.add("apple");
		listwithnulls.add(null);
		listwithnulls.add("mango");
		listwithnulls.add(null);
		listwithnulls.add("banana");
		System.out.println("Let's now Filter Null Elements - ");
		listwithnulls.stream().filter(value -> value != null).forEach(System.out::println);

	}
Created 2 years ago by anonymous
public void testRandomEdits() throws IOException {
    List<Input> keys = new ArrayList<>();
    int numTerms = atLeast(100);
    for (int i = 0; i < numTerms; i++) {
      keys.add(new Input("boo" + TestUtil.randomSimpleString(random()), 1 + random().nextInt(100)));
    }
    keys.add(new Input("foo bar boo far", 12));
    MockAnalyzer analyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, false);
    Directory tempDir = getDirectory();
    FuzzySuggester suggester = new FuzzySuggester(tempDir, "fuzzy", analyzer, analyzer, FuzzySuggester.EXACT_FIRST | FuzzySuggester.PRESERVE_SEP, 256, -1, true, FuzzySuggester.DEFAULT_MAX_EDITS, FuzzySuggester.DEFAULT_TRANSPOSITIONS,
                                                  0, FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH, FuzzySuggester.DEFAULT_UNICODE_AWARE);
    suggester.build(new InputArrayIterator(keys));
    int numIters = atLeast(10);
    for (int i = 0; i < numIters; i++) {
      String addRandomEdit = addRandomEdit("foo bar boo", FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX);
      List<LookupResult> results = suggester.lookup(TestUtil.stringToCharSequence(addRandomEdit, random()), false, 2);
      assertEquals(addRandomEdit, 1, results.size());
      assertEquals("foo bar boo far", results.get(0).key.toString());
      assertEquals(12, results.get(0).value, 0.01F);  
    }
    IOUtils.close(analyzer, tempDir);
  }
// set request time out to 10 min to avoid a timeout for this request
			java.util.Map<String, Object> requestContext = ((javax.xml.ws.BindingProvider) omsQuery)
					.getRequestContext();
			requestContext.put("sun.net.client.defaultReadTimeout",
					new Integer(600000));
			requestContext.put("sun.net.client.defaultConnectTimeout",
					new Integer(600000));
			requestContext.put("com.sun.xml.internal.ws.connect.timeout",
					new Integer(600000));
			requestContext.put("com.sun.xml.internal.ws.request.timeout",
					new Integer(600000));
			requestContext.put("com.sun.xml.ws.request.timeout", new Integer(
					600000));
Created 2 years ago by anonymous
public static void main(String[] args) {
		ArrayList<String> result = new ArrayList<String>() ;
		result.add("Kate.A");
		result.add("Kate.B");
		result.add("Kate.C");
		result.add("Date.D");
		result.add("Date.E");
		result.add("Date.F");
		
		Map<String, List<String>> map = result.stream().collect(Collectors.toMap(each -> each.split("\\.")[0],
				each -> new ArrayList<String>(Arrays.asList(each.split("\\.")[1])), (oldValue, newValue) -> {
					oldValue.addAll(newValue);
					return oldValue;
				}));
		System.out.println(map);
		
	}
Created 2 years ago by anonymous
public class FireBaseUtils {
private static FirebaseDatabase mDatabase;

public static FirebaseDatabase getDatabase() {
   if (mDatabase == null) {
      mDatabase = FirebaseDatabase.getInstance();
      mDatabase.setPersistenceEnabled(true);
   }
return mDatabase;
}

}