List of usage examples for java.util ArrayList isEmpty
public boolean isEmpty()
From source file:org.apache.solr.core.BlobRepository.java
private Replica getSystemCollReplica() { ZkStateReader zkStateReader = this.coreContainer.getZkController().getZkStateReader(); ClusterState cs = zkStateReader.getClusterState(); DocCollection coll = cs.getCollectionOrNull(CollectionsHandler.SYSTEM_COLL); if (coll == null) throw new SolrException(SERVICE_UNAVAILABLE, ".system collection not available"); ArrayList<Slice> slices = new ArrayList<>(coll.getActiveSlices()); if (slices.isEmpty()) throw new SolrException(SERVICE_UNAVAILABLE, "No active slices for .system collection"); Collections.shuffle(slices, RANDOM); //do load balancing Replica replica = null;/*from ww w. j a v a 2 s. c o m*/ for (Slice slice : slices) { List<Replica> replicas = new ArrayList<>(slice.getReplicasMap().values()); Collections.shuffle(replicas, RANDOM); for (Replica r : replicas) { if (r.getState() == Replica.State.ACTIVE) { if (zkStateReader.getClusterState().getLiveNodes() .contains(r.get(ZkStateReader.NODE_NAME_PROP))) { replica = r; break; } else { log.info("replica {} says it is active but not a member of live nodes", r.get(ZkStateReader.NODE_NAME_PROP)); } } } } if (replica == null) { throw new SolrException(SERVICE_UNAVAILABLE, ".no active replica available for .system collection"); } return replica; }
From source file:coolmap.canvas.action.PasteRowNodesAction.java
@Override public void actionPerformed(ActionEvent e) { try {//w w w.j a v a 2 s . c om CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject(); Transferable content = (Transferable) Toolkit.getDefaultToolkit().getSystemClipboard() .getContents(null); String data = (String) content.getTransferData(DataFlavor.stringFlavor); JSONObject json = new JSONObject(data); ArrayList<Range<Integer>> selectedRows = obj.getCoolMapView().getSelectedRows(); // System.out.println(selectedColumns); //if there are selections int insertionIndex = 0; if (selectedRows != null && !selectedRows.isEmpty()) { insertionIndex = selectedRows.get(0).lowerEndpoint(); //System.out.println(lower); } //else else { //append at beginning } JSONArray terms = json.getJSONArray("Terms"); String ontologyID = json.getString("OntologyID"); COntology ontology = CoolMapMaster.getCOntologyByID(ontologyID); System.out.println("Ontology:" + ontology); if (ontology == null) { return; } ArrayList<VNode> newNodes = new ArrayList<VNode>(); for (int i = 0; i < terms.length(); i++) { VNode node = new VNode(terms.getString(i), ontology); newNodes.add(node); System.out.println(node); } Rectangle centerTo = new Rectangle(0, insertionIndex, 1, 1); if (obj.getCoolMapView().getSelectedColumns() != null && !obj.getCoolMapView().getSelectedColumns().isEmpty()) { centerTo.x = ((Range<Integer>) (obj.getCoolMapView().getSelectedColumns().get(0))).lowerEndpoint(); } CoolMapState state = CoolMapState.createStateRows("Insert Row Nodes", obj, null); obj.insertRowNodes(insertionIndex, newNodes, true); obj.getCoolMapView().centerToRegion(centerTo); StateStorageMaster.addState(state); } catch (Exception ex) { System.err.println("Exception in pasting rows:" + ex); } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation.java
/** * Check if a list of URIs has any XSS problems. * Return null if there are none and return an error message if there are problems. *//*from w ww. j a v a 2 s. com*/ private String uriHasXSS(List<String> uriList) throws ScanException, PolicyException { AntiSamy antiSamy = AntiScript.getAntiSamyScanner(); ArrayList errorMsgs = new ArrayList(); for (String uri : uriList) { CleanResults cr = antiSamy.scan(uri); errorMsgs.addAll(cr.getErrorMessages()); } if (errorMsgs.isEmpty()) { return null; } else { return StringUtils.join(errorMsgs, ", "); } }
From source file:ee.ioc.cs.vsle.synthesize.SpecParser.java
/** * Reads a line from an arraylist of specification lines, removes it from * the arraylist and returns the line together with its type information * /*from w ww. java 2 s . c o m*/ * @return a specification line with its type information * @param a arraylist of specification lines */ static LineType getLine(ArrayList<String> a) throws SpecParseException { Matcher matcher; while ((a.get(0)).equals("") || a.get(0).trim().startsWith("//")) { a.remove(0); if (a.isEmpty()) { return null; } } final String line = a.get(0); a.remove(0); if (line.startsWith("alias ")) { matcher = PATTERN_ALIAS_FULL.matcher(line); if (matcher.find()) { if (matcher.group(3).indexOf(".") > -1) { throw new SpecParseException( "Alias " + matcher.group(3) + " cannot be declared with compound name"); } LineType.Alias st = new LineType.Alias(); st.setName(matcher.group(3)); String vars = matcher.group(4).trim(); st.setComponents(vars.length() == 0 ? new String[0] : vars.split(" *, *", -1)); st.setComponentType((matcher.group(2) == null || matcher.group(2).equals("null") ? "" : matcher.group(2).trim())); return new LineType(LineType.TYPE_ALIAS, st, line); } // allow empty alias declaration e.g. "alias x;" matcher = PATTERN_ALIAS_DECLARATION.matcher(line); if (matcher.find()) { if (matcher.group(3).indexOf(".") > -1) { throw new SpecParseException( "Alias " + matcher.group(3) + " cannot be declared with compound name"); } LineType.Alias st = new LineType.Alias(); st.setName(matcher.group(3)); st.setDeclaration(true); st.setComponentType((matcher.group(2) == null || matcher.group(2).equals("null") ? "" : matcher.group(2).trim())); return new LineType(LineType.TYPE_ALIAS, st, line); } return new LineType(LineType.TYPE_ERROR, null, line); } else if (line.indexOf("super") >= 0 && (matcher = PATTERN_SUPERCLASSES.matcher(line)).find()) { LineType.Superclasses st = new LineType.Superclasses(); st.setClassNames(matcher.group(1).split("#", -1)); return new LineType(LineType.TYPE_SUPERCLASSES, st, line); } else if (line.trim().startsWith("const")) { matcher = PATTERN_CONSTANT.matcher(line); if (matcher.find()) { LineType.Constant st = new LineType.Constant(); st.setName(matcher.group(2).trim()); st.setType(matcher.group(1).trim()); st.setValue(matcher.group(3).trim()); return new LineType(LineType.TYPE_CONST, st, line); } return new LineType(LineType.TYPE_ERROR, null, line); } else if (line.indexOf("=") >= 0) { // Extract on solve // equations // lets check if it's an alias, e.g. x = [a,b,c]; matcher = PATTERN_ALIAS_VARS.matcher(line); if (matcher.find()) { LineType.Alias st = new LineType.Alias(); st.setName(matcher.group(1)); String vars = matcher.group(2).trim(); st.setComponents(vars.length() == 0 ? new String[0] : vars.split(" *, *", -1)); st.setAssignment(true); return new LineType(LineType.TYPE_ALIAS, st, line); } matcher = PATTERN_ASSIGNMENT.matcher(line); if (matcher.find()) { LineType.Assignment st = new LineType.Assignment(); st.setName(matcher.group(1)); st.setValue(matcher.group(2)); return new LineType(LineType.TYPE_ASSIGNMENT, st, line); } matcher = PATTERN_EQUATION.matcher(line); if (matcher.find()) { LineType.Equation st = new LineType.Equation(); st.setEq(line); return new LineType(LineType.TYPE_EQUATION, st, line); } return new LineType(LineType.TYPE_ERROR, null, line); } else if (line.indexOf("->") >= 0) { //axiom matcher = PATTERN_AXIOM_FULL.matcher(line); if (matcher.find()) { LineType.Axiom st = new LineType.Axiom(); //check for subtasks //FIXME - this pattern allows subtasks to be anywhere in the axiom, but they need to come before anything else Matcher subMatcher = PATTERN_AXIOM_SUBTASKS.matcher(line); while (subMatcher.find()) { String subtaskString = subMatcher.group(0); Matcher singleSubtaskMatcher = PATTERN_AXIOM_SUBTASK.matcher(subtaskString); if (singleSubtaskMatcher.find()) { String context = singleSubtaskMatcher.group(2); String[] subInputs = singleSubtaskMatcher.group(3).trim().split(" *, *", -1); String[] subOutputs = singleSubtaskMatcher.group(4).trim().split(" *, *", -1); st.getSubtasks().put(subtaskString, new String[][] { new String[] { context }, subInputs, subOutputs }); } else { return new LineType(LineType.TYPE_ERROR, null, line); } } String newLine = line.replaceAll("\\[([^\\]\\[]*) *-> *([^\\]\\[]*)\\]", "#"); matcher = PATTERN_AXIOM_FULL.matcher(newLine); if (matcher.find()) { String in = matcher.group(1).trim(); st.setInputs(in.length() == 0 ? new String[0] : in.split(" *, *", -1)); String out = matcher.group(2).trim(); st.setOutputs(out.length() == 0 ? new String[0] : out.split(" *, *", -1)); st.setMethod(matcher.group(3).trim()); } else { return new LineType(LineType.TYPE_ERROR, null, line); } return new LineType(LineType.TYPE_AXIOM, st, line); } //specaxiom matcher = PATTERN_AXIOM_SPEC.matcher(line); if (matcher.find()) { LineType.Axiom st = new LineType.Axiom(); st.setSpecAxiom(true); String in = matcher.group(1).trim(); st.setInputs(in.length() == 0 ? new String[0] : in.split(" *, *", -1)); String out = matcher.group(2).trim(); st.setOutputs(out.length() == 0 ? new String[0] : out.split(" *, *", -1)); return new LineType(LineType.TYPE_SPECAXIOM, st, line); } return new LineType(LineType.TYPE_ERROR, null, line); } else { matcher = PATTERN_DECLARATION.matcher(line); if (matcher.find()) { LineType.Declaration st = new LineType.Declaration(); st.setStatic((matcher.group(1) != null)); st.setType(matcher.group(2).trim()); st.setNames(matcher.group(6).trim().split(" *, *", -1)); return new LineType(LineType.TYPE_DECLARATION, st, line); } return new LineType(LineType.TYPE_ERROR, null, line); } }
From source file:com.brightcove.com.uploader.verifier.RetrieveJSONResponseforVideo.java
public ArrayList<Object> getMetaData(String metaDataName) { ArrayList<Object> property = new ArrayList<Object>(); property = jsonResponse.retrieveArrayPropertyFromJSONResponse(metaDataName); if (property.size() == 0) { property = jsonResponse.retrieveJSONObjectFromJSONResponse(metaDataName); if (property.isEmpty() && !property.contains("renditions") && !property.contains("IOSRenditions")) { property.add(jsonResponse.retrievePropertyFromJSONResponse(metaDataName)); }//from w w w . j a v a 2 s . c om } return property; }
From source file:org.eclipse.lyo.testsuite.oslcv2.cm.ChangeRequestRdfXmlTests.java
@Parameters public static Collection<Object[]> getAllDescriptionUrls() throws IOException { //Checks the ServiceProviderCatalog at the specified baseUrl of the REST service in order to grab all urls //to other ServiceProvidersCatalogs contained within it, recursively, in order to find the URLs of all //query factories of the REST service. ArrayList<String> serviceUrls = getServiceProviderURLsUsingRdfXml(setupProps.getProperty("baseUri"), onlyOnce);//from w ww . j a va 2s .co m ArrayList<String> capabilityURLsUsingRdfXml = TestsBase .getCapabilityURLsUsingRdfXml(OSLCConstants.QUERY_BASE_PROP, serviceUrls, true); String where = setupProps.getProperty("changeRequestsWhere"); if (where == null) { String queryProperty = setupProps.getProperty("queryEqualityProperty"); String queryPropertyValue = setupProps.getProperty("queryEqualityValue"); where = queryProperty + "=\"" + queryPropertyValue + "\""; } String additionalParameters = setupProps.getProperty("queryAdditionalParameters"); String query = (additionalParameters.length() == 0) ? "?" : "?" + additionalParameters + "&"; query = query + "oslc.where=" + URLEncoder.encode(where, "UTF-8") + "&oslc.pageSize=1"; ArrayList<String> results = new ArrayList<String>(); for (String queryBaseUri : capabilityURLsUsingRdfXml) { String queryUrl = OSLCUtils.addQueryStringToURL(queryBaseUri, query); HttpResponse resp = OSLCUtils.getResponseFromUrl(setupBaseUrl, queryUrl, basicCreds, OSLCConstants.CT_RDF, headers); Model queryModel = ModelFactory.createDefaultModel(); queryModel.read(resp.getEntity().getContent(), queryBaseUri, OSLCConstants.JENA_RDF_XML); RDFUtils.validateModel(queryModel); Property member = queryModel.createProperty(OSLCConstants.RDFS_MEMBER); Resource queryBase = queryModel.getResource(queryBaseUri); Selector select = new SimpleSelector(queryBase, member, (RDFNode) null); StmtIterator statements = queryModel.listStatements(select); while (statements.hasNext()) { results.add(statements.nextStatement().getObject().toString()); if (onlyOnce) return toCollection(results); } if (!results.isEmpty() && onlyOnce) break; } return toCollection(results); }
From source file:androidGLUESigner.helpers.SettingsHelper.java
/** * Saves the changed document list into sharedprefereces * @param values the new values to be saved * @param editor default shared preferences editor. *//*from w ww . j a va 2 s . c o m*/ private void saveNewDocList(ArrayList<String> values, Editor editor) { JSONArray a = new JSONArray(); for (int i = 0; i < values.size(); i++) { a.put(values.get(i)); } if (!values.isEmpty()) { editor.putString("signedDocs", a.toString()); } else { editor.putString("signedDocs", null); } editor.apply(); }
From source file:microsoft.exchange.webservices.data.misc.MapiTypeConverterMapEntry.java
/** * Validates array value.//from w ww . j av a 2 s .c o m * * @param value the value * @throws ArgumentException the argument exception * @throws ArgumentNullException the argument exception */ private void validateValueAsArray(Object value) throws ArgumentException, ArgumentNullException { if (value == null) { throw new ArgumentNullException("value"); } if (value instanceof ArrayList) { ArrayList<?> arrayList = (ArrayList<?>) value; if (arrayList.isEmpty()) { throw new ArgumentException("The Array value must have at least one element."); } if (arrayList.get(0).getClass() != this.getType()) { throw new ArgumentException(String.format("Type %s can't be used as an array of type %s.", value.getClass(), this.getType())); } } }
From source file:com.dilmus.dilshad.scabi.deprecated.Dao2.java
public boolean isEmpty(ArrayList<String> fieldList) { if (null == fieldList) return true; if (fieldList.isEmpty()) return true; return false; }
From source file:edu.usf.cutr.opentripplanner.android.tasks.OTPGeocoding.java
/** * Filters the addresses obtained in geocoding process, removing the * results outside server limits./*from w ww . j ava 2 s . c o m*/ * * @param the list of addresses to filter * @return a new list filtered */ private ArrayList<Address> filterAddressesBBox(ArrayList<Address> addresses) { if (!(addresses == null || addresses.isEmpty())) { ArrayList<Address> addressesFiltered = new ArrayList<Address>(addresses); for (Address address : addressesFiltered) { if (!LocationUtil.checkPointInBoundingBox(new LatLng(address.getLatitude(), address.getLongitude()), selectedServer, OTPApp.CHECK_BOUNDS_ACCEPTABLE_ERROR)) { addressesFiltered.remove(address); } } return addressesFiltered; } return addresses; }