List of usage examples for java.util ArrayList clone
public Object clone()
From source file:com.supremainc.biostar2.widget.FilterView.java
private void selectDevice() { mSelectDevicePopup.show(SelectType.DEVICE, new OnSelectResultListener<ListDevice>() { @Override//from w w w . j av a 2 s. co m public void OnResult(ArrayList<ListDevice> selectedItem) { if (selectedItem == null) { return; } setDeviceResult((ArrayList<BaseDevice>) selectedItem.clone()); } }, null, mContext.getString(R.string.select_device_orginal), true, true); }
From source file:me.preilly.SimplePush.java
public void pushMessage() { ApnsService service = null;/*from www . j a va 2 s.c o m*/ try { InputStream certStream = this.getClass().getClassLoader().getResourceAsStream(certName); service = APNS.newService().withNoErrorDetection().withCert(certStream, certPass) .withSandboxDestination().build(); service.start(); System.out.println("Start..."); ArrayList clients = new ArrayList(); clients.add("50f10bbdea425f18b420cdc4447c8fe4a64ecfb2b9692dd5daf67d03d4558ce5"); System.out.println("Sending " + clients.size() + " messages"); try { String message = "Trulia test message with ID:" + this.generateUniqueKey(); String sound = "default"; int badge = 0; simplePayload = APNS.newPayload().alertBody(message).badge(badge).sound(sound).build(); sendingList = (ArrayList) clients.clone(); Iterator<String> iterator = sendingList.iterator(); while (iterator.hasNext()) { String token = iterator.next(); service.push(token, simplePayload); } } catch (Exception ex) { ex.printStackTrace(); } } catch (Exception ex) { // more logging ex.printStackTrace(); } finally { // check if the service was // successfull initialized and // stop it here, if it was if (service != null) { System.out.println("No more messages to send"); service.stop(); } } }
From source file:com.bailen.radioOnline.servlet.servlet.java
@RequestMapping(value = "/ratings/{rating}/{idCancion}/{fav}", method = RequestMethod.GET, produces = "application/json") public String ratings(@PathVariable String rating, @PathVariable String idCancion, @PathVariable String fav) { cancActual = -1;//from w ww.j a v a 2 s. c om Incidencia error = reja.ratings(usuario.getApiKey(), rating, idCancion, fav); for (int i = 0; i < canc.size(); ++i) { if (canc.get(i).getId() == Integer.parseInt(idCancion)) { cancActual = i; } } bandera = true; try { Cancion[] aux = reja.getRatings(usuario.getApiKey()); ArrayList<Cancion> puntuAux = new ArrayList<>(); for (int i = 0; i < aux.length; ++i) { puntuAux.add(aux[i]); } puntuaciones = (ArrayList<Cancion>) puntuAux.clone(); } catch (Exception e) { return e.getMessage(); } return "redirect:/" + backward + "/" + canc.get(cancActual).getId(); }
From source file:org.opencyc.constraintsolver.ForwardCheckingSearcher.java
/** * Applies the all-different constraint rule to the remaining domains and returns <tt>true</tt> * iff no domains are wiped out./*from w w w . j a va2 s .c o m*/ * * @param rule the all-different constraint rule * @param remainingRuleVariables the variables left to instantiate in the constraint rule * @param level the current level of solution search depth * @param currentBinding the current variable and bound value * @return <tt>true</tt> iff no remaining variable domains are wiped out */ protected boolean checkForwardDifferentRule(ConstraintRule rule, ArrayList remainingRuleVariables, int level, Binding currentBinding) { Object value = currentBinding.getValue(); ArrayList differentVariables = (ArrayList) remainingRuleVariables.clone(); differentVariables.remove(currentBinding.getCycVariable()); for (int i = 0; i < differentVariables.size(); i++) { CycVariable differentVariable = (CycVariable) differentVariables.get(i); if (valueDomains.getUnmarkedDomainValues(differentVariable).contains(value) && !valueDomains.isDomainMarked(differentVariable, value)) { if (verbosity > 6) System.out.println(" " + (new Binding(differentVariable, value)).cyclify() + " is ruled out by " + currentBinding.cyclify()); valueDomains.markDomain(differentVariable, value, new Integer(level)); if (valueDomains.isDomainWipedOut(differentVariable)) { if (verbosity > 6) System.out.println(" domain wiped out for " + differentVariable.cyclify()); return false; } } } return true; }
From source file:com.bailen.radioOnline.servlet.servlet.java
@RequestMapping(value = "/identificado", method = RequestMethod.GET, produces = "text/html") public @ResponseBody ModelAndView identificado() { ModelAndView model;//from w w w . jav a 2 s . c om try { Cancion[] aux = reja.getRatings(usuario.getApiKey()); ArrayList<Cancion> puntuAux = new ArrayList<>(); if (aux != null) { for (int i = 0; i < aux.length; ++i) { puntuAux.add(aux[i]); } } puntuaciones = (ArrayList<Cancion>) puntuAux.clone(); puntuacionesAux = (ArrayList<Cancion>) puntuAux.clone(); model = new ModelAndView("identificado"); model.addObject("puntuaciones", puntuaciones); if (bandera == false) { cancActual = 0; model.addObject("actual", cancActual); model.addObject("usuario", usuario); model.addObject("persona", persona); model = random(model); } else { bandera = false; model.addObject("canciones", canc); model.addObject("actual", cancActual); model.addObject("error", "la puntuacion se realizo correctamente"); model.addObject("usuario", usuario); model.addObject("persona", persona); } return model; } catch (Exception e) { model = new ModelAndView("errorPage"); model.addObject("error", e.getMessage()); return model; } }
From source file:org.erdc.cobie.shared.spreadsheetml.transformation.cobietab.COBieSpreadSheet.java
License:asdf
@SuppressWarnings("unchecked") private static Map<String, ArrayList<Map<String, String>>> cobieDocumentToStringMap(COBIEDocument cobie) { try {/*w ww . ja v a 2s. com*/ Map<String, ArrayList<Map<String, String>>> cobieDocMap = new HashMap<String, ArrayList<Map<String, String>>>(); COBIEType cType = cobie.getCOBIE(); COBIEType.Contacts contacts = cType.getContacts(); COBIEType.Facilities facilities = cType.getFacilities(); COBIEType.Spaces spaces = cType.getSpaces(); COBIEType.Zones zones = cType.getZones(); COBIEType.Types types = cType.getTypes(); COBIEType.Floors floors = cType.getFloors(); COBIEType.Components components = cType.getComponents(); COBIEType.Systems systems = cType.getSystems(); COBIEType.Assemblies assemblies = cType.getAssemblies(); COBIEType.Spares spares = cType.getSpares(); COBIEType.Resources resources = cType.getResources(); COBIEType.Jobs jobs = cType.getJobs(); COBIEType.Connections connections = cType.getConnections(); COBIEType.Documents documents = cType.getDocuments(); COBIEType.Attributes attributes = cType.getAttributes(); COBIEType.Coordinates coordinates = cType.getCoordinates(); String tempMasterKey = COBieUtility.CobieSheetName.Contact.name(); ArrayList<Map<String, String>> tmpArray = new ArrayList<Map<String, String>>(); Map<String, String> tmpElementMap = new HashMap<String, String>(); if ((contacts != null) && !contacts.isNil()) { for (ContactType contact : contacts.getContactArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(contact); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((facilities != null) && !facilities.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Facility.name(); for (FacilityType facility : facilities.getFacilityArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(facility); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((floors != null) && !floors.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Floor.name(); for (FloorType floor : floors.getFloorArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(floor); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((spaces != null) && !spaces.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Space.name(); for (SpaceType space : spaces.getSpaceArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(space); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((zones != null) && !zones.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Zone.name(); for (ZoneType zone : zones.getZoneArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(zone); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((types != null) && !types.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Type.name(); for (TypeType type : types.getTypeArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(type); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((components != null) && !components.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Component.name(); for (ComponentType component : components.getComponentArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(component); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((systems != null) && !systems.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.System.name(); for (SystemType system : systems.getSystemArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(system); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((assemblies != null) && !assemblies.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Assembly.name(); for (AssemblyType assembly : assemblies.getAssemblyArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(assembly); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((spares != null) && !spares.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Spare.name(); for (SpareType spare : spares.getSpareArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(spare); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((resources != null) && !resources.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Resource.name(); for (ResourceType resource : resources.getResourceArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(resource); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((jobs != null) && !jobs.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Job.name(); for (JobType job : jobs.getJobArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(job); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((connections != null) && !connections.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Connection.name(); for (ConnectionType connection : connections.getConnectionArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(connection); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((documents != null) && !documents.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Document.name(); for (DocumentType document : documents.getDocumentArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(document); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((attributes != null) && !attributes.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Attribute.name(); for (AttributeType attribute : attributes.getAttributeArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(attribute); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } if ((coordinates != null) && !coordinates.isNil()) { tmpArray.clear(); tempMasterKey = COBieUtility.CobieSheetName.Coordinate.name(); for (CoordinateType coordinate : coordinates.getCoordinateArray()) { tmpElementMap = COBieUtility.elementMapFromXMLObject(coordinate); tmpArray.add(tmpElementMap); } cobieDocMap.put(tempMasterKey, (ArrayList<Map<String, String>>) tmpArray.clone()); } return cobieDocMap; } catch (NullPointerException e) { return null; } }
From source file:com.bailen.radioOnline.servlet.servlet.java
@RequestMapping(value = "/randomId", method = RequestMethod.GET, produces = "application/json") public @ResponseBody ModelAndView randomId() { ModelAndView model = new ModelAndView("identificado"); if (!banderaPlus) { try {//from w w w . j a va 2 s . co m backward = "randomId"; ArrayList<Cancion> canciones = new ArrayList<>(); Cancion[] inter = reja.random(usuario.getApiKey()); for (int i = 0; i < inter.length; ++i) { canciones.add(inter[i]); } model.addObject("canciones", canciones); canc = (ArrayList<Cancion>) canciones.clone(); cancActual = 0; model.addObject("actual", cancActual); model.addObject("usuario", usuario); model.addObject("persona", persona); model.addObject("puntuaciones", puntuaciones); return model; } catch (Exception e) { model = new ModelAndView("errorPage"); model.addObject("error", e.getMessage()); return model; } } else { try { backward = "randomId"; banderaPlus = false; ArrayList<Cancion> canciones = new ArrayList<>(); Cancion[] inter = reja.random(usuario.getApiKey()); for (int i = 0; i < inter.length; ++i) { canciones.add(inter[i]); } for (int i = 0; i < canciones.size(); ++i) { canc.add(canciones.get(i)); } model.addObject("actual", cancActual); model.addObject("usuario", usuario); model.addObject("persona", persona); model.addObject("canciones", canc); model.addObject("puntuaciones", puntuaciones); return model; } catch (Exception e) { model = new ModelAndView("errorPage"); model.addObject("error", e.getMessage()); return model; } } }
From source file:com.bailen.radioOnline.servlet.servlet.java
@RequestMapping(value = "/recommendations", method = RequestMethod.GET, produces = "application/json") public @ResponseBody ModelAndView recommendations() { ModelAndView model = new ModelAndView("identificado"); if (!banderaPlus) { try {// w w w . j a v a2 s.c om backward = "recommendations"; ArrayList<Cancion> canciones = new ArrayList<>(); Cancion[] inter = reja.recommendations(usuario.getApiKey()); for (int i = 0; i < inter.length; ++i) { canciones.add(inter[i]); } model.addObject("canciones", canciones); canc = (ArrayList<Cancion>) canciones.clone(); cancActual = 0; model.addObject("actual", cancActual); model.addObject("usuario", usuario); model.addObject("persona", persona); model.addObject("puntuaciones", puntuaciones); return model; } catch (Exception e) { model = new ModelAndView("errorPage"); model.addObject("error", e.getMessage()); return model; } } else { try { backward = "recommendations"; banderaPlus = false; ArrayList<Cancion> canciones = new ArrayList<>(); Cancion[] inter = reja.recommendations(usuario.getApiKey()); for (int i = 0; i < inter.length; ++i) { canciones.add(inter[i]); } for (int i = 0; i < canciones.size(); ++i) { canc.add(canciones.get(i)); } model.addObject("actual", cancActual); model.addObject("usuario", usuario); model.addObject("persona", persona); model.addObject("canciones", canc); model.addObject("puntuaciones", puntuaciones); return model; } catch (Exception e) { model = new ModelAndView("errorPage"); model.addObject("error", e.getMessage()); return model; } } }
From source file:org.opencyc.constraintsolver.ForwardCheckingSearcher.java
/** * Performs a depth-first search of the solution space, using forward checking * to prune alternatives. Employs recursion to search subtrees. * * @param variables is the <tt>ArrayList</tt> of remaining variables to solve * @param level is the current depth of the search * @return <tt>true</tt> when done with the search *///w w w. j a v a2s . co m public boolean search(ArrayList variables, int level) throws IOException, CycApiException { CycVariable selectedVariable = selectVariable(variables); ArrayList remainingDomain = valueDomains.getUnmarkedDomainValues(selectedVariable); ArrayList remainingVariables = (ArrayList) variables.clone(); remainingVariables.remove(selectedVariable); if (verbosity > 2) { System.out.println("\nSearching level " + level); System.out.println(" variable " + selectedVariable.cyclify()); System.out.println(" remaining domain " + remainingDomain); System.out.println(" remaining vars " + remainingVariables); } // Iterate through the unmarked domain values, solving the subtree recursively, // backtracking when required. for (int i = 0; i < remainingDomain.size(); i++) { Object selectedValue = remainingDomain.get(i); Binding currentBinding = new Binding(selectedVariable, selectedValue); solution.addBindingToCurrentSolution(currentBinding); nbrSteps++; if (verbosity > 2) System.out.println(" trial solution " + solution.getCurrentSolution()); if (variables.size() == 1) { // Trivial case where the last variable is under consideration. solution.setNbrSolutionsFound(solution.getNbrSolutionsFound() + 1); if (verbosity > 0) { if (solution.getNbrSolutionsFound() == 1) System.out.println("\nFound a solution\n"); else System.out.println("\nFound solution " + solution.getNbrSolutionsFound() + "\n"); solution.displaySolution(solution.getCurrentSolution()); System.out.println(); } // The last variable is solved, have all the solutions requested been found? if (constraintProblem.nbrSolutionsRequested != null) if (constraintProblem.nbrSolutionsRequested.intValue() == solution.getNbrSolutionsFound()) // Done and stop the search. return true; // More solutions are needed, record this solution. solution.recordNewSolution(currentBinding); } else { // Try to achieve partial arc-consistency in the subtree. if (checkForwardRules(remainingVariables, level, currentBinding) && search(remainingVariables, level + 1)) // Requested solution(s) found in the subtree. return true; // Otherwise backtrack, selecting next unmarked domain value. solution.removeBindingFromCurrentSolution(currentBinding); if (verbosity > 2) { System.out.println(" backtracking from " + currentBinding); System.out.println(" trial solution " + solution.getCurrentSolution()); } restore(remainingVariables, level); } } // Done with this branch of the search tree, and keep searching. return false; }
From source file:com.bailen.radioOnline.servlet.servlet.java
@RequestMapping(value = "/random", method = RequestMethod.GET, produces = "application/json") public @ResponseBody ModelAndView random(ModelAndView model) { try {// w ww. j a v a 2s. com backward = "randomId"; usuario.setApiKey("717c03766e5fafba6ecf4781338a7547"); ArrayList<Cancion> canciones = new ArrayList<>(); Cancion[] inter = reja.random(usuario.getApiKey()); for (int i = 0; i < inter.length; ++i) { canciones.add(inter[i]); } int cont = 0; model.addObject("cont", cont); model.addObject("canciones", canciones); canc = (ArrayList<Cancion>) canciones.clone(); cancActual = 0; model.addObject("actual", cancActual); return model; } catch (Exception e) { model = new ModelAndView("errorPage"); model.addObject("error", e.getMessage()); return model; } }