示例#1
0
 @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
 /**
  * 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
 @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
 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
 /**
  * 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
 @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
 @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
 /** 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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 /**
  * 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()])));
 }