public void testSetProperties() throws Exception { Session s = openSession(); Transaction t = s.beginTransaction(); Simple simple = new Simple(); simple.setName("Simple 1"); s.save(simple, new Long(10)); Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count"); q.setProperties(simple); assertTrue(q.list().get(0) == simple); // misuse of "Single" as a propertyobject, but it was the first testclass i found with a // collection ;) Single single = new Single() { // trivial hack to test properties with arrays. String[] getStuff() { return (String[]) getSeveral().toArray(new String[getSeveral().size()]); } }; List l = new ArrayList(); l.add("Simple 1"); l.add("Slimeball"); single.setSeveral(l); q = s.createQuery("from Simple s where s.name in (:several)"); q.setProperties(single); assertTrue(q.list().get(0) == simple); q = s.createQuery("from Simple s where s.name in (:stuff)"); q.setProperties(single); assertTrue(q.list().get(0) == simple); s.delete(simple); t.commit(); s.close(); }
@Setup public void setup() { source = Single.just(1); flatmapped = source.flatMap( new Func1<Integer, Single<Integer>>() { @Override public Single<Integer> call(Integer t) { return Single.just(t); } }); flatmapped = source.flatMap( new Func1<Integer, Single<Integer>>() { @Override public Single<Integer> call(Integer t) { return source; } }); sourceObserveOn = source.observeOn(Schedulers.computation()); sourceSubscribeOn = source.subscribeOn(Schedulers.computation()); // ---------- scheduledExecutor = Executors.newScheduledThreadPool(1); Scheduler s = Schedulers.from(scheduledExecutor); sourceObserveOnScheduledExecutor = source.observeOn(s); sourceSubscribeOnScheduledExecutor = source.subscribeOn(s); // ---------- executor = Executors.newSingleThreadExecutor(); Scheduler se = Schedulers.from(executor); sourceObserveOnExecutor = source.observeOn(se); sourceSubscribeOnExecutor = source.subscribeOn(se); // -------- // Scheduler fj = Schedulers.from(ForkJoinPool.commonPool()); // sourceObserveOnFJ = source.observeOn(fj); // sourceSubscribeOnFJ = source.subscribeOn(fj); }
public String toString() { String nameToShow = (name == null) ? "(no name)" : name; if (singleList.size() == 0) { return "empty tuple with name " + nameToShow; } StringBuilder sb = new StringBuilder(); sb.append(nameToShow); sb.append(": "); for (Single single : singleList) { sb.append(single.toString()); sb.append(" "); } return sb.toString(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_friends); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar ab = getSupportActionBar(); ab.setDisplayHomeAsUpEnabled(true); queue = Single.getInstance().getRequestQueue(); pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); token = pref.getString("token", "none"); tvq = (TextView) findViewById(R.id.tvq); btnSearch = (Button) findViewById(R.id.btnSearch); btnSearch.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (tvq.getText().toString().trim().equals("")) { Toast.makeText(SearchFriendsActivity.this, "Please enter a query", Toast.LENGTH_SHORT) .show(); } else { Intent i; i = new Intent(getApplicationContext(), AddFriendsActivity.class); // -1 specifies add more friends i.putExtra("group_id", -1L); i.putExtra("q", tvq.getText().toString().trim()); startActivity(i); } } }); }
@Benchmark public void observeOnSchExec(Blackhole bh) { LatchedSingleSubscriber o = new LatchedSingleSubscriber(bh); sourceObserveOnScheduledExecutor.subscribe(o); o.awaitSpin(); }
@Benchmark public void subscribeOnExec(Blackhole bh) { LatchedSingleSubscriber o = new LatchedSingleSubscriber(bh); sourceSubscribeOnExecutor.subscribe(o); o.awaitSpin(); }
@Override public Expr compile(final QueryContext qc, final VarScope scp) throws QueryException { try { super.compile(qc, scp); if (expr.isValue()) return optPre(expr, qc); } catch (final QueryException ex) { if (!ex.isCatchable()) throw ex; for (final Catch c : catches) { if (c.matches(ex)) { // found a matching clause, compile and inline error message return optPre(c.compile(qc, scp).asExpr(ex, qc, scp), qc); } } throw ex; } for (final Catch c : catches) c.compile(qc, scp); return optimize(qc, scp); }
public static void main(String[] args) { Single s = Single.newInstance(); Single s1 = Single.newInstance(); System.out.println(s.equals(s1)); }
@Override public Expr comp(final QueryContext ctx) throws QueryException { super.comp(ctx); return checkUp(expr, ctx).value() ? optPre(value(ctx), ctx) : this; }
@Benchmark public void flatmapConst(Blackhole bh) { flatmapped.subscribe(new PlainSingleSubscriber(bh)); }
@Benchmark public void direct(Blackhole bh) { source.subscribe(new PlainSingleSubscriber(bh)); }