List of usage examples for java.util ListIterator hasNext
boolean hasNext();
From source file:com.aliyun.openservices.odps.console.resource.CreateResourceCommand.java
public static AddResourceCommand parse(String commandString, ExecutionContext sessionContext) throws ODPSConsoleException { String[] tokens = new AntlrObject(commandString).getTokenStringArray(); if (tokens != null && tokens.length >= 2 && tokens[0].toUpperCase().equals("CREATE") && tokens[1].toUpperCase().equals("RESOURCE")) { GnuParser parser = new GnuParser(); Options options = new Options(); options.addOption("p", "project", true, null); options.addOption("c", "comment", true, null); options.addOption("f", "force", false, null); try {// w ww . ja va 2 s. c o m CommandLine cl = parser.parse(options, tokens); String refName = null; String alias = ""; String comment = null; String type = null; String partitionSpec = ""; boolean isUpdate = false; List<String> argList = cl.getArgList(); int size = argList.size(); if (size < 4) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Missing parameters"); } ListIterator<String> iter = argList.listIterator(); iter.next(); iter.next(); type = iter.next(); refName = iter.next(); if (iter.hasNext()) { String item = iter.next(); if (item.equals("(")) { boolean isParenPaired = false; while (iter.hasNext()) { String s = iter.next(); if (s.equals(")")) { isParenPaired = true; break; } partitionSpec += s; } if (!isParenPaired) { throw new ODPSConsoleException( ODPSConsoleConstants.BAD_COMMAND + "Unpaired parenthesis"); } if (!iter.hasNext()) { throw new ODPSConsoleException( ODPSConsoleConstants.BAD_COMMAND + "Missing parameter: alias"); } item = iter.next(); } alias = item; } if (iter.hasNext()) { throw new ODPSConsoleException( ODPSConsoleConstants.BAD_COMMAND + "Illegal parameter: " + iter.next()); } String projectName = null; Option[] opts = cl.getOptions(); for (Option opt : opts) { if ("f".equals(opt.getOpt())) { isUpdate = true; } else if ("c".equals(opt.getOpt())) { comment = opt.getValue(); } else if ("p".equals(opt.getOpt())) { projectName = opt.getValue(); } else { throw new ODPSConsoleException( ODPSConsoleConstants.BAD_COMMAND + "Illegal option: " + opt.getOpt()); } } return new AddResourceCommand(commandString, sessionContext, refName, alias, comment, type, partitionSpec, isUpdate, projectName); } catch (ParseException e) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Invalid parameters"); } } else { return null; } }
From source file:com.ibm.soatf.config.DirectoryStructureManager.java
private static void validateIfaceStructure(Interface iface) throws FrameworkConfigurationException { try {/* w w w . j a v a2 s . com*/ final MasterFrameworkConfig FCFG = ConfigurationManager.getInstance().getFrameworkConfig(); final MasterConfiguration MCFG = ConfigurationManager.getInstance().getMasterConfig(); File soaTestHome = FCFG.getSoaTestHome(); final File interfaceFolder = new File(soaTestHome, iface.getName() + "_" + FCFG.getValidFileSystemObjectName(iface.getDescription())); logger.trace("Working directory after format: " + interfaceFolder); try { createFolder(interfaceFolder); } catch (FrameworkExecutionException ex) { logger.error("Could not create folder " + interfaceFolder.getAbsolutePath()); } /* * Create interface dummy projects folders. There will be nothing saved under those folders. * Main purpose is just to have the user view on all projects under the interface, because there doesn't exist * one general naming interace convention, which is wrong!!! */ if (iface.getProjects() != null) { final ListIterator<Project> projectIt = iface.getProjects().getProject().listIterator(); while (projectIt.hasNext()) { File projectFolder = new File(interfaceFolder, OSB_REFERENCE_PROJECT_DIR_NAME_PREFIX + projectIt.next().getName()); try { createFolder(projectFolder); } catch (FrameworkExecutionException ex) { logger.error("Could not create project folder " + projectFolder.getAbsolutePath()); } } final File interfaceConfigFile = new File(interfaceFolder, IFACE_CONFIG_FILENAME); if (!interfaceConfigFile.exists()) { logger.warn("Interface configuration file is missing for interface " + iface.getName() + " " + iface.getDescription()); return; } //masterConfig.getIfaceConfigFile(iface.getName()); if (interfaceConfigFile.exists()) { try { InterfaceConfiguration ICFG = MCFG.getInterfaceConfig(iface); final ListIterator<IfaceFlowPattern> ifaceFlowPatternIterator = ICFG.getIfaceFlowPatterns() .listIterator(); IfaceFlowPattern ifaceFlowPattern; logger.debug("Processing " + interfaceConfigFile.getAbsolutePath()); while (ifaceFlowPatternIterator.hasNext()) { ifaceFlowPattern = ifaceFlowPatternIterator.next(); final File patternDirectory = new File(interfaceFolder, FLOW_PATTERN_DIR_NAME_PREFIX + FCFG.getValidFileSystemObjectName(ifaceFlowPattern.getRefId())); createFolder(patternDirectory); final String testName = ifaceFlowPattern.getInstanceMetadata().getTestName(); if (testName.isEmpty()) { throw new FrameworkConfigurationException( "There is missing test name in config.xml instance metadata element in file " + interfaceConfigFile.getAbsolutePath() + "."); } final File testScenarioNameDirectory = new File(patternDirectory, FCFG.getValidFileSystemObjectName(testName)); createFolder(testScenarioNameDirectory); /*final ListIterator<FileSystemProjectStructure.FlowPatternInstanceRoot.Directory> patternFoldersIterator = masterConfig.getXmlConfig().getFileSystemStructure().getFlowPatternInstanceRoot().getDirectory().listIterator(); while (patternFoldersIterator.hasNext()) { final String fldName = frameworkConfig.getValidFileSystemObjectName(patternFoldersIterator.next().getName()); final File dir = new File(testScenarioNameDirectory, fldName); createFolder(dir); // This is to check the pattern source folder and don't let it clean up cleanFolder(dir); }*/ final File reportDir = new File(testScenarioNameDirectory, MCFG.getReportDirName()); createFolder(reportDir); cleanFolder(reportDir); final File archiveDir = new File(testScenarioNameDirectory, MCFG.getArchiveDirName()); createFolder(archiveDir); final ListIterator<IfaceTestScenario> ifaceTCIterator = ifaceFlowPattern .getIfaceTestScenario().listIterator(); IfaceTestScenario ifaceTestScenario; while (ifaceTCIterator.hasNext()) { ifaceTestScenario = ifaceTCIterator.next(); final File testScenario = new File(testScenarioNameDirectory, FCFG.getValidFileSystemObjectName(ifaceTestScenario.getRefId())); createFolder(testScenario); final ListIterator<FileSystemProjectStructure.TestRoot.Directory> foldersIterator = MCFG .getXmlConfig().getFileSystemStructure().getTestRoot().getDirectory() .listIterator(); while (foldersIterator.hasNext()) { final String fldName = FCFG .getValidFileSystemObjectName(foldersIterator.next().getName()); final File dir = new File(testScenario, fldName); createFolder(dir); // This is to check the pattern source folder and don't let it clean up cleanFolder(dir); } } } } catch (FrameworkConfigurationException fce) { logger.error("Configuration for interface " + iface.getName() + " is invalid", fce); } catch (FrameworkExecutionException fee) { logger.error("Could not create folder.", fee); } } else { generateSampleIfaceConfigFile(interfaceConfigFile); } } else { logger.warn("Interface " + iface.getName() + "_" + iface.getDescription() + " has no projects defined."); } } catch (FrameworkConfigurationException ex) { final String msg = "TODO"; throw new FrameworkConfigurationException(msg, ex); } }
From source file:com.amazonaws.hbase.kinesis.utils.EMRUtils.java
/** * Helper method to determine if an Amazon EMR cluster exists * /* ww w . j av a 2 s .co m*/ * @param client * The {@link AmazonElasticMapReduceClient} with read permissions * @param clusterIdentifier * The Amazon EMR cluster to check * @return true if the Amazon EMR cluster exists, otherwise false */ public static boolean clusterExists(AmazonElasticMapReduce client, String clusterIdentifier) { if (clusterIdentifier != null && !clusterIdentifier.isEmpty()) { ListClustersResult clustersList = client.listClusters(); ListIterator<ClusterSummary> iterator = clustersList.getClusters().listIterator(); ClusterSummary summary; for (summary = iterator.next(); iterator.hasNext(); summary = iterator.next()) { if (summary.getId().equals(clusterIdentifier)) { DescribeClusterRequest describeClusterRequest = new DescribeClusterRequest() .withClusterId(clusterIdentifier); DescribeClusterResult result = client.describeCluster(describeClusterRequest); if (result != null) { Cluster cluster = result.getCluster(); //check if HBase is installed on this cluster if (isHBaseInstalled(client, cluster.getId())) return false; String state = cluster.getStatus().getState(); LOG.info(clusterIdentifier + " is " + state + ". "); if (state.equalsIgnoreCase("RUNNING") || state.equalsIgnoreCase("WAITING")) { LOG.info("The cluster with id " + clusterIdentifier + " exists and is " + state); return true; } } } } } LOG.info("The cluster with id " + clusterIdentifier + " does not exist"); return false; }
From source file:com.projity.algorithm.buffer.GroupedCalculatedValues.java
public static GroupedCalculatedValues union(GroupedCalculatedValues values1, GroupedCalculatedValues values2) { GroupedCalculatedValues c1, c2;/*from w ww. ja v a 2s . co m*/ if (values1.size() >= values2.size()) { c1 = values1; c2 = values2; } else { c1 = values2; c2 = values1; } GroupedCalculatedValues c = new GroupedCalculatedValues(); ListIterator i1 = c1.values.listIterator(); ListIterator i2 = c2.values.listIterator(); Point p1, p2 = null; while (i1.hasNext()) { p1 = (Point) i1.next(); while (i2.hasNext()) { p2 = (Point) i2.next(); if (p2.date < p1.date) { c.values.add(p2); } else if (p2.date > p1.date) { i2.previous(); break; } else break; } if (p2 != null && p1.date == p2.date) c.values.add(new Point(p1.date, p1.value + p2.value)); else c.values.add(p1); } while (i2.hasNext()) { c.values.add((Point) i2.next()); } return c; }
From source file:exm.stc.ic.ICUtil.java
public static void removeDuplicates(List<Var> varList) { ListIterator<Var> it = varList.listIterator(); HashSet<Var> alreadySeen = new HashSet<Var>(); while (it.hasNext()) { Var v = it.next();//from w w w. j a v a 2s . c o m if (alreadySeen.contains(v)) { it.remove(); } else { alreadySeen.add(v); } } }
From source file:com.cinchapi.concourse.lang.Parser.java
/** * Go through a list of symbols and group the expressions together in a * {@link Expression} object./* www. ja va 2 s .com*/ * * @param symbols * @return the expression */ protected static List<Symbol> groupExpressions(List<Symbol> symbols) { // visible // for // testing try { List<Symbol> grouped = Lists.newArrayList(); ListIterator<Symbol> it = symbols.listIterator(); while (it.hasNext()) { Symbol symbol = it.next(); if (symbol instanceof KeySymbol) { // NOTE: We are assuming that the list of symbols is well // formed, and, as such, the next elements will be an // operator and one or more symbols. If this is not the // case, this method will throw a ClassCastException OperatorSymbol operator = (OperatorSymbol) it.next(); ValueSymbol value = (ValueSymbol) it.next(); Expression expression; if (operator.getOperator() == Operator.BETWEEN) { ValueSymbol value2 = (ValueSymbol) it.next(); expression = Expression.create((KeySymbol) symbol, operator, value, value2); } else { expression = Expression.create((KeySymbol) symbol, operator, value); } grouped.add(expression); } else if (symbol instanceof TimestampSymbol) { // Add the // timestamp to the // previously // generated // Expression ((Expression) Iterables.getLast(grouped)).setTimestamp((TimestampSymbol) symbol); } else { grouped.add(symbol); } } return grouped; } catch (ClassCastException e) { throw new SyntaxException(e.getMessage()); } }
From source file:Main.java
/** * Returns a list iterator that swaps all previous/next calls. * <p><b>Important:</b> The returned iterator violates the {@link ListIterator#nextIndex()} and {@link ListIterator#previousIndex()} specifications. *//*from w w w. jav a 2 s.c o m*/ public static <E> ListIterator<E> reverse(ListIterator<E> iterator) { return new ListIterator<E>() { @Override public boolean hasNext() { return iterator.hasPrevious(); } @Override public E next() { return iterator.previous(); } @Override public boolean hasPrevious() { return iterator.hasNext(); } @Override public E previous() { return iterator.next(); } @Override public int nextIndex() { return iterator.previousIndex(); } @Override public int previousIndex() { return iterator.nextIndex(); } @Override public void remove() { iterator.remove(); } @Override public void set(E e) { iterator.set(e); } @Override public void add(E e) { iterator.add(e); } }; }
From source file:Alias2.java
public static void verify(List output, List expected) { verifyLength(output.size(), expected.size(), Test.EXACT); if (!expected.equals(output)) { //find the line of mismatch ListIterator it1 = expected.listIterator(); ListIterator it2 = output.listIterator(); while (it1.hasNext() && it2.hasNext() && it1.next().equals(it2.next())) ;/* www. ja v a 2 s . co m*/ throw new LineMismatchException(it1.nextIndex(), it1.previous().toString(), it2.previous().toString()); } }
From source file:com.worldline.easycukes.commons.helpers.JSONHelper.java
/** * Returns <b>true</b> if JSON array a1 is equals to JSON array a2. * * @param a1 a {@link JSONArray} containing some JSON data * @param a2 another {@link JSONArray} containing some JSON data * @return true if the json arrays are equals *//* w w w. j a v a 2 s.co m*/ public static boolean equals(@NonNull JSONArray a1, @NonNull JSONArray a2) { if (a1 == a2) return true; if (a1.size() != a2.size()) return false; final ListIterator i1 = a1.listIterator(); ListIterator i2; boolean found = false; while (i1.hasNext()) { final Object o1 = i1.next(); found = false; i2 = a2.listIterator(); if (o1 instanceof JSONObject) while (i2.hasNext()) { final Object o2 = i2.next(); if (!(o2 instanceof JSONObject)) return false; if (equals((JSONObject) o1, (JSONObject) o2)) found = true; } else if (o1 instanceof JSONArray) while (i2.hasNext()) { final Object o2 = i2.next(); if (!(o2 instanceof JSONArray)) return false; if (equals((JSONArray) o1, (JSONArray) o2)) found = true; } else while (i2.hasNext()) { final Object o2 = i2.next(); if (o1.equals(o2)) found = true; } if (!found) return false; } return true; }
From source file:com.cloud.utils.UriUtils.java
public static String getUpdateUri(String url, boolean encrypt) { String updatedPath = null;//from w w w . j a v a 2 s. co m try { String query = URIUtil.getQuery(url); URIBuilder builder = new URIBuilder(url); builder.removeQuery(); StringBuilder updatedQuery = new StringBuilder(); List<NameValuePair> queryParams = getUserDetails(query); ListIterator<NameValuePair> iterator = queryParams.listIterator(); while (iterator.hasNext()) { NameValuePair param = iterator.next(); String value = null; if ("password".equalsIgnoreCase(param.getName()) && param.getValue() != null) { value = encrypt ? DBEncryptionUtil.encrypt(param.getValue()) : DBEncryptionUtil.decrypt(param.getValue()); } else { value = param.getValue(); } if (updatedQuery.length() == 0) { updatedQuery.append(param.getName()).append('=').append(value); } else { updatedQuery.append('&').append(param.getName()).append('=').append(value); } } String schemeAndHost = ""; URI newUri = builder.build(); if (newUri.getScheme() != null) { schemeAndHost = newUri.getScheme() + "://" + newUri.getHost(); } updatedPath = schemeAndHost + newUri.getPath() + "?" + updatedQuery; } catch (URISyntaxException e) { throw new CloudRuntimeException("Couldn't generate an updated uri. " + e.getMessage()); } return updatedPath; }