List of usage examples for java.util ArrayList remove
public boolean remove(Object o)
From source file:de.cynapsys.homeautomation.webserviceImpl.RoomWebServiceImpl.java
@Override public boolean detachDeviceFromRoom(Device device, Long roomID) { try {//from w ww . j a v a 2s. c o m Room r = getRoomById(roomID); ArrayList<Device> deviceList = (ArrayList) r.getDevices(); deviceList.remove(device); roomService.save(r); return true; } catch (Exception e) { return false; } }
From source file:org.camelcookbook.splitjoin.splitparallel.SplitParallelProcessingTimeoutSpringTest.java
@Test public void testSplittingInParallel() throws InterruptedException { List<String> messageFragments = new ArrayList<String>(); int fragmentCount = 50; for (int i = 0; i < fragmentCount; i++) { messageFragments.add("fragment" + i); }//from ww w. j a v a 2s. c o m MockEndpoint mockSplit = getMockEndpoint("mock:split"); mockSplit.setExpectedMessageCount(fragmentCount - 1); ArrayList<String> expectedFragments = new ArrayList<String>(messageFragments); int indexDelayed = 20; expectedFragments.remove(indexDelayed); mockSplit.expectedBodiesReceivedInAnyOrder(expectedFragments); MockEndpoint mockDelayed = getMockEndpoint("mock:delayed"); mockDelayed.setExpectedMessageCount(1); MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.setExpectedMessageCount(1); template.sendBody("direct:in", messageFragments); assertMockEndpointsSatisfied(); }
From source file:com.moez.QKSMS.model.MediaModelFactory.java
/** * This method is meant to identify the part in the given PduBody that corresponds to the given * src string./*from w ww .j a v a 2s .c o m*/ * * Essentially, a SMIL MMS is formatted as follows: * * 1. A smil/application part, which contains XML-like formatting for images, text, audio, * slideshows, videos, etc. * 2. One or more parts that correspond to one of the elements that was mentioned in the * formatting above. * * In the smil/application part, elements are identified by a "src" attribute in an XML-like * element. The challenge of this method lies in the fact that sometimes, the src string isn't * located at all in the part that it is meant to identify. * * We employ several methods of pairing src strings up to parts, using certain patterns we've * seen in failed MMS messages. These are described in this method. * TODO TODO TODO: Create a testing suite for this! */ private static PduPart findPart(final Context context, PduBody pb, String src, ArrayList<String> srcs) { PduPart result = null; if (src != null) { src = unescapeXML(src); // Sometimes, src takes the form of "cid:[NUMBER]". if (contentIdSrc(src)) { // Extract the content ID, and try finding the part using that. result = pb.getPartByContentId("<" + src.substring("cid:".length()) + ">"); if (result == null) { // Another thing that can happen is that there is a slideshow of images, each with // "cid:[NUMBER]" src, but the parts aren't labelled with the content ID. If // this is the case, then we just return the ith image part, where i is the position // of src if all the srcs are sorted in ascending order as content IDs. srcs may // include duplicates; we remove those and then identify i when the list is free from // duplicates. // // i.e., for srcs = [ "cid:755", "cid:755", "cid:756", "cid:757", "cid:758" ], // the i of "cid:755" is 0; for "cid:756" is 1, etc. // First check that all the src strings are content IDs. boolean allContentIDs = true; for (String _src : srcs) { if (!contentIdSrc(_src)) { allContentIDs = false; break; } } if (allContentIDs) { // Now, build a list of long IDs, sort them, and remove the duplicates. ArrayList<Long> cids = new ArrayList<>(); for (String _src : srcs) { cids.add(getContentId(_src)); } Collections.sort(cids); int removed = 0; long previous = -1; for (int i = 0; i < cids.size() - removed; i++) { long cid = cids.get(i); if (cid == previous) { cids.remove(i); removed++; } else { previous = cid; } } // Find the i such that getContentId(src) == cids[i] long cid = getContentId(src); int i = cids.indexOf(cid); // Finally, since the SMIL formatted part will come first, we expect to see // 1 + cids.size() parts, and the right part for this particular cid will be // 1 + i. if (1 + i < pb.getPartsNum()) { result = pb.getPart(i + 1); } } } } else if (textSrc(src)) { // This is just a text src, so look for the PduPart that is has the "text/plain" // content type. for (int i = 0; i < pb.getPartsNum(); i++) { PduPart part = pb.getPart(i); String contentType = byteArrayToString(part.getContentType()); if ("text/plain".equals(contentType)) { result = part; break; } } } // Try a few more things in case the previous processing didn't work correctly: // Search by name if (result == null) { result = pb.getPartByName(src); } // Search by filename if (result == null) { result = pb.getPartByFileName(src); } // Search by content location if (result == null) { result = pb.getPartByContentLocation(src); } // Try treating the src string as a content ID, and searching by content ID. if (result == null) { result = pb.getPartByContentId("<" + src + ">"); } // TODO: // four remaining cases currently in Firebase: // 1. src: "image:[NUMBER]" (broken formatting) // 2. src: "[NUMBER]" (broken formatting) // 3. src: "[name].vcf" (we don't support x-vcard) // 3. src: "Current Location.loc.vcf" (we don't support x-vcard) } if (result != null) { return result; } if (pb.getPartsNum() > 0) { final JSONArray array = new JSONArray(); for (int i = 0; i < pb.getPartsNum(); i++) { JSONObject object = new JSONObject(); try { object.put("part_number", i); } catch (Exception e) { e.printStackTrace(); } try { object.put("location", i); } catch (Exception e) { e.printStackTrace(); } try { object.put("charset", pb.getPart(i).getCharset()); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_disposition", byteArrayToString(pb.getPart(i).getContentDisposition())); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_id", byteArrayToString(pb.getPart(i).getContentId())); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_location", byteArrayToString(pb.getPart(i).getContentLocation())); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_transfer_encoding", byteArrayToString(pb.getPart(i).getContentTransferEncoding())); } catch (Exception e) { e.printStackTrace(); } try { object.put("content_type", byteArrayToString(pb.getPart(i).getContentType())); } catch (Exception e) { e.printStackTrace(); } try { object.put("data", byteArrayToString(pb.getPart(i).getData())); } catch (Exception e) { e.printStackTrace(); } try { object.put("data_uri", pb.getPart(i).getDataUri()); } catch (Exception e) { e.printStackTrace(); } try { object.put("file_name", byteArrayToString(pb.getPart(i).getFilename())); } catch (Exception e) { e.printStackTrace(); } try { object.put("name", byteArrayToString(pb.getPart(i).getName())); } catch (Exception e) { e.printStackTrace(); } if (pb.getPart(i).generateLocation() != null) { Log.d(TAG, "Location: " + pb.getPart(i).generateLocation()); if (pb.getPart(i).generateLocation().contains(src)) { return pb.getPart(i); } } array.put(object); } } throw new IllegalArgumentException("No part found for the model."); }
From source file:info.archinnov.achilles.entity.parsing.validator.EntityParsingValidator.java
public void validatePropertyMetas(EntityParsingContext context, PropertyMeta idMeta) { log.debug("Validate that there is at least one property meta for the entity class {}", context.getCurrentEntityClass().getCanonicalName()); ArrayList<PropertyMeta> metas = new ArrayList<PropertyMeta>(context.getPropertyMetas().values()); metas.remove(idMeta); Validator.validateBeanMappingFalse(metas.isEmpty(), "The entity '" + context.getCurrentEntityClass().getCanonicalName() + "' should have at least one field with javax.persistence.Column/javax.persistence.Id/javax.persistence.EmbeddedId annotations"); }
From source file:com.sasav.blackjack.dao.GameDao.java
public Card pullRandomCardFromDeck(Game game, GameActor actor) { ArrayList<Card> cardDeck = game.getCardDeck(); int index = (int) (Math.random() * cardDeck.size()); Card card = cardDeck.get(index);// w w w . ja va 2 s . co m cardDeck.remove(index); Session session = sessionFactory.openSession(); session.flush(); session.close(); return null; }
From source file:com.baasbox.service.user.UserService.java
public static void unregisterDevice(String pushToken) throws SqlInjectionException { ODocument user = getCurrentUser();//from w w w .ja v a 2 s. c om ODocument systemProps = user.field(UserDao.ATTRIBUTES_SYSTEM); ArrayList<ODocument> loginInfos = systemProps.field(UserDao.USER_LOGIN_INFO); for (ODocument loginInfo : loginInfos) { if (loginInfo.field(UserDao.USER_PUSH_TOKEN) != null && loginInfo.field(UserDao.USER_PUSH_TOKEN).equals(pushToken)) { loginInfos.remove(loginInfo); break; } } systemProps.save(); }
From source file:com.baasbox.service.user.UserService.java
public static void logout(String pushToken) throws SqlInjectionException { ODocument user = getCurrentUser();/*www . j av a 2 s . c o m*/ ODocument systemProps = user.field(UserDao.ATTRIBUTES_SYSTEM); ArrayList<ODocument> loginInfos = systemProps.field(UserDao.USER_LOGIN_INFO); for (ODocument loginInfo : loginInfos) { if (loginInfo.field(UserDao.USER_PUSH_TOKEN) != null && loginInfo.field(UserDao.USER_PUSH_TOKEN).equals(pushToken)) { loginInfos.remove(loginInfo); break; } } systemProps.save(); }
From source file:com.draagon.meta.manager.ObjectManager.java
/** * Clips the specified objects by the provided range */// www . jav a2s . co m public static Collection<Object> distinctObjects(Collection<?> objs) throws MetaException { // TODO: Check this, as I don't think it works! ArrayList<Object> a = new ArrayList<Object>(objs); for (Iterator<Object> i = a.iterator(); i.hasNext();) { Object o = i.next(); // Find the first index of the object int fi = a.indexOf(o); // Remove all objects of the same value int li = 0; while ((li = a.lastIndexOf(o)) != fi) a.remove(li); } return a; }
From source file:alpine.notification.NotificationService.java
/** * {@inheritDoc}// ww w .j a v a 2 s. c om * @since 1.3.0 */ public void unsubscribe(Subscription subscription) { for (ArrayList<Subscription> list : SUBSCRIPTION_MAP.values()) { list.remove(subscription); } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.MultiAxesCrosshairOverlay.java
public void removeRangeCrosshair(int axisIdx, Crosshair crosshair) { if (rangeCrosshairs.size() > axisIdx) { ArrayList<Crosshair> crosshairsForRange = rangeCrosshairs.get(axisIdx); crosshairsForRange.remove(crosshair); crosshair.removePropertyChangeListener(this); }//w w w. jav a2 s . com }