コード例 #1
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 @Override
 public Iterator<Item> iterator() {
   PathQuery pq = new PathQuery(services.getModel());
   pq.addViews(PQUtil.getStar(services.getModel(), getType()));
   pq.addConstraint(Constraints.in(type, name));
   Iterator<Map<String, Object>> it = services.getQueryService().getRowMapIterator(pq);
   return new ItemIterator(it);
 }
コード例 #2
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Add items to this list by using a query.
  *
  * @param items The items to add to the list.
  */
 private void appendItems(Iterable<Item> items) {
   PathQuery pq = new PathQuery(services.getModel());
   pq.addViews(getType() + ".id");
   Set<String> values = new HashSet<String>();
   for (Item i : items) {
     values.add(Integer.toString(i.getId()));
   }
   pq.addConstraint(Constraints.oneOfValues(getType() + ".id", values));
   update(services.getListService().append(this, pq));
 }
コード例 #3
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 @SuppressWarnings("unchecked")
 @Override
 public boolean removeAll(@SuppressWarnings("rawtypes") Collection c) {
   int priorSize = getSize();
   if (c instanceof ItemList) {
     ItemList res = subtract(((ItemList) c));
     update(res);
     delete();
     res.rename(getName());
   } else if (!c.isEmpty()) {
     try {
       Item[] is = (Item[]) c.toArray(new Item[0]);
       String path = is[0].getType() + ".id";
       PathQuery pq = new PathQuery(services.getModel());
       pq.addView(path);
       pq.addConstraint(
           Constraints.oneOfValues(
               path,
               collect(
                   collect(Arrays.asList(is), invokerTransformer("getId")),
                   stringValueTransformer())));
       createListAndSubtract(pq);
     } catch (ArrayStoreException e) {
       // Do nothing - we didn't get a collection of items.
     }
   }
   return priorSize != getSize();
 }
コード例 #4
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 private void createListAndSubtract(PathQuery pq) {
   ListCreationInfo info = services.getListService().new ListCreationInfo(pq);
   ItemList removalList = null;
   try {
     removalList = services.getListService().createList(info);
     ItemList res = subtract(removalList);
     update(res);
     delete();
     res.rename(getName());
   } finally {
     try {
       removalList.delete();
     } catch (Exception e) {
       // Ignore
     }
   }
 }
コード例 #5
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Convenience method for finding members of a collection matching certain properties.
  *
  * <p>This search is implemented with a query that performs case-insensitive matching on values.
  * Null constraints will be honoured, but other lookups will be converted to strings. Wild-cards
  * are permitted wherever they are permitted in path-queries. <br>
  * Using a query to back the search means that finding matching members is efficient even over
  * large lists - you will not need to pull in and iterate over thousands of rows of data to find
  * items if you have specific conditions. <br>
  * These conditions must all match for the result to be included. For more specific and flexible
  * searching strategies, please see the {@link PathQuery} API.
  *
  * @param conditions The properties these elements should have.
  * @return A list of matching items.
  */
 public List<Item> find(Map<String, Object> conditions) {
   List<Item> ret = new ArrayList<Item>();
   PathQuery q = new PathQuery(services.getModel());
   q.addViews(PQUtil.getStar(services.getModel(), type));
   q.addConstraint(Constraints.in(type, name));
   for (Entry<String, Object> condition : conditions.entrySet()) {
     String path = type + "." + condition.getKey();
     if (condition.getValue() == null) {
       q.addConstraint(Constraints.isNull(path));
     } else {
       q.addConstraint(Constraints.eq(path, condition.getValue().toString()));
     }
   }
   List<Map<String, Object>> results = services.getQueryService().getRowsAsMaps(q);
   for (Map<String, Object> result : results) {
     ret.add(new Item(services, type, result));
   }
   return ret;
 }
コード例 #6
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 @Override
 public boolean remove(Object i) {
   int priorSize = getSize();
   if (i instanceof Item) {
     Item item = (Item) i;
     String path = item.getType() + ".id";
     PathQuery pq = new PathQuery(services.getModel());
     pq.addView(path);
     pq.addConstraint(Constraints.eq(path, Integer.toString(item.getId())));
     createListAndSubtract(pq);
   }
   return priorSize != getSize();
 }
コード例 #7
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 @SuppressWarnings("unchecked")
 @Override
 public boolean containsAll(@SuppressWarnings("rawtypes") Collection c) {
   if (c == null) {
     return false;
   }
   Item[] candidates;
   try {
     candidates = (Item[]) c.toArray(new Item[c.size()]);
   } catch (ArrayStoreException e) {
     return false;
   }
   return services.getListService().contains(this, candidates);
 }
コード例 #8
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /** Make sure that the tags on this object are up-to-date with those stored on the server. */
 public void updateTags() {
   tags = services.getListService().getTags(this);
 }
コード例 #9
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Rename this list on the server.
  *
  * <p>This method will update the name of the list stored on the server, and also change of the
  * name returned by this object.
  *
  * @param newName The new name to give this list.
  */
 public void rename(String newName) {
   ItemList updated = services.getListService().rename(this, newName);
   this.name = updated.getName();
 }
コード例 #10
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Remove the items in the given lists from this list.
  *
  * <p>This call performs the operation of asymmetric difference on the current list and returns
  * the result. For operations that alter the current list see {@link #removeAll(Collection)}
  *
  * @param lists The lists to subtract from this list.
  * @param info The options describing the new list.
  * @return A new list
  */
 public ItemList subtract(ListOperationInfo info, Collection<ItemList> lists) {
   return services.getListService().subtract(info, Collections.singleton(this), lists);
 }
コード例 #11
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Remove the items in the given lists from this list.
  *
  * <p>This call performs the operation of asymmetric difference on the current list and returns
  * the result. For operations that alter the current list see {@link #removeAll(Collection)}
  *
  * @param lists The lists to subtract from this list.
  * @return A new list
  */
 public ItemList subtract(Collection<ItemList> lists) {
   return services.getListService().subtract(Collections.singleton(this), lists);
 }
コード例 #12
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Remove the items in the given lists from this list.
  *
  * <p>This call performs the operation of asymmetric difference on the current list and returns
  * the result. For operations that alter the current list see {@link #removeAll(Collection)}
  *
  * @param lists The lists to subtract from this list.
  * @param info The options describing the new list.
  * @return A new list
  */
 public ItemList subtract(ListOperationInfo info, ItemList... lists) {
   return services
       .getListService()
       .subtract(info, Collections.singleton(this), Arrays.asList(lists));
 }
コード例 #13
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Remove the items in the given lists from this list.
  *
  * <p>This call performs the operation of asymmetric difference on the current list and returns
  * the result. For operations that alter the current list see {@link #removeAll(Collection)}
  *
  * @param lists The lists to subtract from this list.
  * @return A new list
  */
 public ItemList subtract(ItemList... lists) {
   return services.getListService().subtract(Collections.singleton(this), Arrays.asList(lists));
 }
コード例 #14
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Call for this list to be deleted on the server. As soon as the call returns, this list should
  * no longer be used for any operation.
  */
 public void delete() {
   services.getListService().deleteList(this);
 }
コード例 #15
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Add some new tags to this list. After adding, list will have an updated set of tags, and the
  * tags will be stored on the server.
  *
  * @param newTags The tags to add.
  */
 public void addTags(String... newTags) {
   tags = services.getListService().addTags(this, newTags);
 }
コード例 #16
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Remove some tags from this list. After removing, the list will have an updated set of tags, and
  * the tags will be synchronised with those on the server.
  *
  * @param removeThese The tags to remove.
  */
 public void removeTags(String... removeThese) {
   tags = services.getListService().removeTags(this, removeThese);
 }
コード例 #17
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Add new items to the list by resolving the identifiers of objects.
  *
  * <p>This method will update the size of the list, and clear the items cache.
  *
  * @param ids The identifiers to use to find objects to add.
  */
 public void append(String... ids) {
   update(services.getListService().append(this, ids));
 }
コード例 #18
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Add new items to the list by resolving the identifiers of objects.
  *
  * <p>This method will update the size of the list, and clear the items cache.
  *
  * @param pq The query to run to find objects with.
  */
 public void append(PathQuery pq) {
   update(services.getListService().append(this, pq));
 }
コード例 #19
0
ファイル: ItemList.java プロジェクト: ZFIN/intermine
 /**
  * Add new items to the list by resolving the identifiers of objects.
  *
  * <p>This method will update the size of the list, and clear the items cache.
  *
  * @param ids The identifiers to use to find objects to add.
  */
 public void append(Collection<? extends String> ids) {
   update(services.getListService().append(this, ids.toArray(new String[ids.size()])));
 }