Java Code Examples for scala.collection.Iterator#hasNext()

The following examples show how to use scala.collection.Iterator#hasNext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KafkaAuthBinding.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
public void addAcls(scala.collection.immutable.Set<Acl> acls, final Resource resource) {
    verifyAcls(acls);
    LOG.info("Adding Acl: acl->" + acls + " resource->" + resource);

    final Iterator<Acl> iterator = acls.iterator();
    while (iterator.hasNext()) {
        final Acl acl = iterator.next();
        final String role = getRole(acl);
        if (!roleExists(role)) {
            throw new KafkaException("Can not add Acl for non-existent Role: " + role);
        }
        execute(new Command<Void>() {
            @Override
            public Void run(SentryGenericServiceClient client) throws Exception {
                client.grantPrivilege(
                    requestorName, role, COMPONENT_NAME, toTSentryPrivilege(acl, resource));
                return null;
            }
        });
    }
}
 
Example 2
Source File: KafkaAuthBinding.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
public boolean removeAcls(scala.collection.immutable.Set<Acl> acls, final Resource resource) {
    verifyAcls(acls);
    LOG.info("Removing Acl: acl->" + acls + " resource->" + resource);
    final Iterator<Acl> iterator = acls.iterator();
    while (iterator.hasNext()) {
        final Acl acl = iterator.next();
        final String role = getRole(acl);
        try {
            execute(new Command<Void>() {
                @Override
                public Void run(SentryGenericServiceClient client) throws Exception {
                    client.dropPrivilege(
                            requestorName, role, toTSentryPrivilege(acl, resource));
                    return null;
                }
            });
        } catch (KafkaException kex) {
            LOG.error("Failed to remove acls.", kex);
            return false;
        }
    }

    return true;
}
 
Example 3
Source File: ParserQueryFunctionsTest.java    From odata with Apache License 2.0 6 votes vote down vote up
private void testQueryFunction(String operator) throws ODataException {
    EqExpr expr = getExprFromOperator(operator);
    MethodCallExpr call = (MethodCallExpr) expr.left();
    assertThat(call.methodName(), is(operator));
    List<Expression> args = call.args();
    Iterator iter = args.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof EntityPathExpr) {
            EntityPathExpr entityPathExpr = (EntityPathExpr) obj;
            PropertyPathExpr propertyPath = (PropertyPathExpr) entityPathExpr.subPath().get();
            assertThat(propertyPath.propertyName(), is("name"));
        }
    }
    LiteralExpr literal = (LiteralExpr) expr.right();
    NumberLiteral number = (NumberLiteral) literal.value();
    assertThat(number.value(), is(new BigDecimal(new java.math.BigDecimal(19))));
}
 
Example 4
Source File: PythonCorrelateSplitRule.java    From flink with Apache License 2.0 5 votes vote down vote up
private List<String> createNewFieldNames(
	RelDataType rowType,
	RexBuilder rexBuilder,
	int primitiveFieldCount,
	ArrayBuffer<RexNode> extractedRexNodes,
	List<RexNode> calcProjects) {
	for (int i = 0; i < primitiveFieldCount; i++) {
		calcProjects.add(RexInputRef.of(i, rowType));
	}
	// add the fields of the extracted rex calls.
	Iterator<RexNode> iterator = extractedRexNodes.iterator();
	while (iterator.hasNext()) {
		calcProjects.add(iterator.next());
	}

	List<String> nameList = new LinkedList<>();
	for (int i = 0; i < primitiveFieldCount; i++) {
		nameList.add(rowType.getFieldNames().get(i));
	}
	Iterator<Object> indicesIterator = extractedRexNodes.indices().iterator();
	while (indicesIterator.hasNext()) {
		nameList.add("f" + indicesIterator.next());
	}
	return SqlValidatorUtil.uniquify(
		nameList,
		rexBuilder.getTypeFactory().getTypeSystem().isSchemaCaseSensitive());
}
 
Example 5
Source File: CollectionUtils.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
public static List convertArrayBufferToList(ArrayBuffer arrayBuffer) {
    List list = new ArrayList<>();
    Iterator it = arrayBuffer.iterator();
    while (it.hasNext()) {
        list.add(it.next());
    }
    return list;
}
 
Example 6
Source File: SparkSessionBuilderImpl.java    From beakerx with Apache License 2.0 5 votes vote down vote up
public SparkConf getSparkConf() {
  SparkConf sparkConf = new SparkConf();
  Iterator iterator = getConfigIterator();
  while (iterator.hasNext()) {
    Tuple2 x = (Tuple2) iterator.next();
    sparkConf.set((String) (x)._1, (String) (x)._2);
  }
  return sparkConf;
}
 
Example 7
Source File: KafkaConsumerCommand.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
protected List<String> group() {
	List<String> groups = new ArrayList<>();
	scala.collection.immutable.List<GroupOverview> list = adminClient.listAllConsumerGroupsFlattened();
	if (list == null)
		return groups;
	Iterator<GroupOverview> iterator = list.iterator();
	while (iterator.hasNext()) {
		groups.add(iterator.next().groupId());
	}
	return groups;
}
 
Example 8
Source File: SparkSessionBuilderImpl.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getSparkConfAsMap() {
  Map<String, Object> sparkConf = new HashMap();
  Iterator iterator = getConfigIterator();
  while (iterator.hasNext()) {
    Tuple2 x = (Tuple2) iterator.next();
    sparkConf.put((String) (x)._1, (x)._2);
  }
  return sparkConf;
}
 
Example 9
Source File: KafkaConsumerCommand.java    From azeroth with Apache License 2.0 5 votes vote down vote up
protected List<String> group() {
    List<String> groups = new ArrayList<>();
    scala.collection.immutable.List<GroupOverview> list = adminClient
        .listAllConsumerGroupsFlattened();
    if (list == null)
        return groups;
    Iterator<GroupOverview> iterator = list.iterator();
    while (iterator.hasNext()) {
        groups.add(iterator.next().groupId());
    }
    return groups;
}
 
Example 10
Source File: ZkConsumerCommand.java    From azeroth with Apache License 2.0 5 votes vote down vote up
public List<BrokerInfo> fetchAllBrokers() {
    List<BrokerInfo> result = new ArrayList<>();
    Seq<Broker> brokers = zkUtils.getAllBrokersInCluster();
    Iterator<Broker> iterator = brokers.toList().iterator();
    while (iterator.hasNext()) {
        Broker broker = iterator.next();
        Node node = broker.getNode(SecurityProtocol.PLAINTEXT);
        result.add(new BrokerInfo(node.idString(), node.host(), node.port()));
    }
    return result;
}
 
Example 11
Source File: ExpressionParserTest.java    From odata with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntitySetRootElement() {
    ODataUriParser parser = new ODataUriParser(model);
    ODataUri target = parser.parseUri(SERVICE_ROOT + "Customers?$filter=Phone eq $root/Customers('A1245')/Phone");

    assertThat(target.serviceRoot() + "/", is(SERVICE_ROOT));

    ResourcePathUri resourcePathUri = (ResourcePathUri) target.relativeUri();

    List<QueryOption> options = resourcePathUri.options();
    assertThat(options.size(), is(1));

    Iterator<QueryOption> iter = options.iterator();

    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof FilterOption) {
            FilterOption option = (FilterOption) obj;

            EqExpr expr = (EqExpr) option.expression();
            EntityPathExpr pathExpr = (EntityPathExpr) expr.left();
            Option<PathExpr> subPath = pathExpr.subPath();
            PropertyPathExpr propertyPath = (PropertyPathExpr) subPath.get();

            assertThat(propertyPath.propertyName(), is(notNullValue()));
            assertThat(propertyPath.propertyName(), is("Phone"));

            EntitySetRootExpr rootExpr = (EntitySetRootExpr) expr.right();
            assertThat(rootExpr.entitySetName(), is("Customers"));

            SimpleKeyPredicate predicate = (SimpleKeyPredicate) rootExpr.keyPredicate();
            StringLiteral value = (StringLiteral) predicate.value();
            assertThat(value.value(), is("A1245"));

        }
    }
}
 
Example 12
Source File: KafkaAuthBinding.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private void addExistingAclsForResource(java.util.Map<Resource, scala.collection.immutable.Set<Acl>> resourceAclsMap, Resource resource, java.util.Set<Acl> newAclsJava) {
    final scala.collection.immutable.Set<Acl> existingAcls = resourceAclsMap.get(resource);
    if (existingAcls != null) {
        final Iterator<Acl> aclsIter = existingAcls.iterator();
        while (aclsIter.hasNext()) {
            Acl curAcl = aclsIter.next();
            newAclsJava.add(curAcl);
        }
    }
}
 
Example 13
Source File: KafkaAdminClient.java    From common-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Manually converting to java map to avoid binary compatibility issues between scala versions when using JavaConverters
 */
static <K, V> Map<K, V> convertToJavaMap(Iterator<Tuple2<K, V>> mapIterator) {
    Map<K, V> map = new HashMap<>();
    while(mapIterator.hasNext()) {
        Tuple2<K, V> entry = mapIterator.next();
        map.put(entry.copy$default$1(), entry.copy$default$2());
    }
    return Collections.unmodifiableMap(map);
}
 
Example 14
Source File: KafkaAdminClient.java    From common-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Manually converting to java set to avoid binary compatibility issues between scala versions when using JavaConverters
 */
static <E> Set<E> convertToJavaSet(Iterator<E> iterator) {
    Set<E> set = new HashSet<>();
    while(iterator.hasNext()) {
        set.add(iterator.next());
    }
    return Collections.unmodifiableSet(set);
}
 
Example 15
Source File: DataConverter.java    From AsyncDao with MIT License 5 votes vote down vote up
public static Map<String, Object> rowDataToMap(RowData rowData, ModelMap resultMap, List<String> columnNames) {
    Map<String, Object> res = new HashMap<>();
    Iterator<Object> iterable = rowData.iterator();
    int index = 0;
    while (iterable.hasNext()) {
        Object item = iterable.next();
        String property = getProperty(resultMap, columnNames.get(index));
        res.put(property, item);
        index++;
    }
    return res;
}
 
Example 16
Source File: PythonCorrelateSplitRule.java    From flink with Apache License 2.0 5 votes vote down vote up
private List<String> createNewFieldNames(
	RelDataType rowType,
	RexBuilder rexBuilder,
	int primitiveFieldCount,
	ArrayBuffer<RexNode> extractedRexNodes,
	List<RexNode> calcProjects) {
	for (int i = 0; i < primitiveFieldCount; i++) {
		calcProjects.add(RexInputRef.of(i, rowType));
	}
	// add the fields of the extracted rex calls.
	Iterator<RexNode> iterator = extractedRexNodes.iterator();
	while (iterator.hasNext()) {
		calcProjects.add(iterator.next());
	}

	List<String> nameList = new LinkedList<>();
	for (int i = 0; i < primitiveFieldCount; i++) {
		nameList.add(rowType.getFieldNames().get(i));
	}
	Iterator<Object> indicesIterator = extractedRexNodes.indices().iterator();
	while (indicesIterator.hasNext()) {
		nameList.add("f" + indicesIterator.next());
	}
	return SqlValidatorUtil.uniquify(
		nameList,
		rexBuilder.getTypeFactory().getTypeSystem().isSchemaCaseSensitive());
}
 
Example 17
Source File: DataConverter.java    From AsyncDao with MIT License 5 votes vote down vote up
public static <T> T queryResultToObject(QueryResult queryResult, Class<T> clazz, ModelMap resultMap) {
    final Option<ResultSet> rows = queryResult.rows();
    if (rows.isDefined()) {
        List<String> columnNames = ScalaUtils.toJavaList(rows.get().columnNames().toList());
        Iterator<RowData> iterator = rows.get().iterator();
        if (iterator.hasNext()) {
            try {
                return rowDataToObject(iterator.next(), clazz, resultMap, columnNames);
            } catch (Exception e) {
                log.error("convert object error :{}", e);
            }
        }
    }
    return null;
}
 
Example 18
Source File: GarmadonSparkStorageStatusListener.java    From garmadon with Apache License 2.0 5 votes vote down vote up
/**
 * capture new rdd information
 */
@Override
public void onStageSubmitted(SparkListenerStageSubmitted event) {
    Iterator<RDDInfo> it = event.stageInfo().rddInfos().iterator();
    while (it.hasNext()) {
        RDDInfo info = it.next();
        if (info.storageLevel().isValid()) {
            liveRDDs.computeIfAbsent(info.id(), key -> new GarmadonRDDStorageInfo(info.name()));
        }
    }
}
 
Example 19
Source File: CsvSourceTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSourceDataFromLookupTable() {
    CubeManager cubeMgr = CubeManager.getInstance(getTestConfig());
    CubeInstance cube = cubeMgr.getCube(CUBE_NAME);
    Iterator<TableDesc> iterator = MetadataConverter.extractLookupTable(cube).iterator();
    while (iterator.hasNext()) {
        TableDesc lookup = iterator.next();
        NSparkCubingEngine.NSparkCubingSource cubingSource = new CsvSource().adaptToBuildEngine(NSparkCubingEngine.NSparkCubingSource.class);
        Dataset<Row> sourceData = cubingSource.getSourceData(lookup, ss, Maps.newHashMap());
        List<Row> rows = sourceData.collectAsList();
        Assert.assertTrue(rows != null && rows.size() > 0);
    }
}
 
Example 20
Source File: KafkaConfigModelGenerator.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
private static Map<String, ConfigModel> configs() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    ConfigDef def = brokerConfigs();
    Map<String, String> dynamicUpdates = brokerDynamicUpdates();
    Method getConfigValueMethod = def.getClass().getDeclaredMethod("getConfigValue", ConfigDef.ConfigKey.class, String.class);
    getConfigValueMethod.setAccessible(true);

    Method sortedConfigs = ConfigDef.class.getDeclaredMethod("sortedConfigs");
    sortedConfigs.setAccessible(true);

    List<ConfigDef.ConfigKey> keys = (List) sortedConfigs.invoke(def);
    Map<String, ConfigModel> result = new TreeMap<>();
    for (ConfigDef.ConfigKey key : keys) {
        String configName = String.valueOf(getConfigValueMethod.invoke(def, key, "Name"));
        Type type = parseType(String.valueOf(getConfigValueMethod.invoke(def, key, "Type")));
        Scope scope = parseScope(dynamicUpdates.getOrDefault(key.name, "read-only"));
        ConfigModel descriptor = new ConfigModel();
        descriptor.setType(type);
        descriptor.setScope(scope);

        if (key.validator instanceof ConfigDef.Range) {
            descriptor = range(key, descriptor);
        } else if (key.validator instanceof ConfigDef.ValidString) {
            descriptor.setValues(enumer(key.validator));
        } else if (key.validator instanceof ConfigDef.ValidList) {
            descriptor.setItems(validList(key));
        } else if (key.validator instanceof ApiVersionValidator$) {
            Iterator<ApiVersion> iterator = ApiVersion$.MODULE$.allVersions().iterator();
            LinkedHashSet<String> versions = new LinkedHashSet<>();
            while (iterator.hasNext()) {
                ApiVersion next = iterator.next();
                ApiVersion$.MODULE$.apply(next.shortVersion());
                versions.add(Pattern.quote(next.shortVersion()) + "(\\.[0-9]+)*");
                ApiVersion$.MODULE$.apply(next.version());
                versions.add(Pattern.quote(next.version()));
            }
            descriptor.setPattern(String.join("|", versions));
        } else if (key.validator != null) {
            throw new IllegalStateException(key.validator.getClass().toString());
        }
        result.put(configName, descriptor);
    }
    return result;
}