本文整理汇总了Java中com.google.common.collect.Sets类的典型用法代码示例。如果您正苦于以下问题:Java Sets类的具体用法?Java Sets怎么用?Java Sets使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sets类属于com.google.common.collect包,在下文中一共展示了Sets类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEdges
import com.google.common.collect.Sets; //导入依赖的package包/类
@Override
public Iterable<Edge> getEdges(final Iterable<String> ids, final EnumSet<FetchHint> fetchHints, final Long endTime, final Authorizations authorizations) {
return new LookAheadIterable<String, Edge>() {
@Override
protected boolean isIncluded(String src, Edge edge) {
return edge != null;
}
@Override
protected Edge convert(String id) {
return getEdge(id, fetchHints, endTime, authorizations);
}
@Override
protected Iterator<String> createIterator() {
return Sets.newHashSet(ids).iterator();
}
};
}
示例2: discoverComponentsFor
import com.google.common.collect.Sets; //导入依赖的package包/类
public static Set<Component> discoverComponentsFor(Descriptor desc)
{
Set<Component.Type> knownTypes = Sets.difference(Component.TYPES, Collections.singleton(Component.Type.CUSTOM));
Set<Component> components = Sets.newHashSetWithExpectedSize(knownTypes.size());
for (Component.Type componentType : knownTypes)
{
if (componentType == Component.Type.DIGEST)
{
if (desc.digestComponent != null && new File(desc.filenameFor(desc.digestComponent)).exists())
components.add(desc.digestComponent);
}
else
{
Component component = new Component(componentType);
if (new File(desc.filenameFor(component)).exists())
components.add(component);
}
}
return components;
}
示例3: prepareModel
import com.google.common.collect.Sets; //导入依赖的package包/类
private void prepareModel() {
when(sourcelist1.getIdentifier()).thenReturn(SOURCELIST_1_ID);
when(sourcelist2.getIdentifier()).thenReturn(SOURCELIST_2_ID);
when(client1.getDragItemId()).thenReturn(ITEM_1_ID);
when(client2.getDragItemId()).thenReturn(ITEM_2_ID);
when(client3.getDragItemId()).thenReturn(ITEM_3_ID);
when(model.containsClient(CLIENT_1_ID)).thenReturn(true);
when(model.containsClient(CLIENT_2_ID)).thenReturn(true);
when(model.containsClient(CLIENT_3_ID)).thenReturn(true);
when(model.getClientById(CLIENT_1_ID)).thenReturn(client1);
when(model.getClientById(CLIENT_2_ID)).thenReturn(client2);
when(model.getClientById(CLIENT_3_ID)).thenReturn(client3);
when(model.getSourcelistById(SOURCELIST_1_ID)).thenReturn(sourcelist1);
when(model.getSourcelistById(SOURCELIST_2_ID)).thenReturn(sourcelist2);
when(model.getSourceLists()).thenReturn(Sets.newHashSet(sourcelist1, sourcelist2));
when(model.getSourcelistByClientId(CLIENT_1_ID)).thenReturn(sourcelist1);
when(model.getSourcelistByClientId(CLIENT_2_ID)).thenReturn(sourcelist2);
when(model.getSourcelistByClientId(CLIENT_3_ID)).thenReturn(sourcelist2);
when(model.getClients(sourcelist1)).thenReturn(Lists.newArrayList(client1));
when(model.getClients(sourcelist2)).thenReturn(Lists.newArrayList(client2, client3));
}
示例4: PropertyInteger
import com.google.common.collect.Sets; //导入依赖的package包/类
protected PropertyInteger(String name, int min, int max)
{
super(name, Integer.class);
if (min < 0)
{
throw new IllegalArgumentException("Min value of " + name + " must be 0 or greater");
}
else if (max <= min)
{
throw new IllegalArgumentException("Max value of " + name + " must be greater than min (" + min + ")");
}
else
{
Set<Integer> set = Sets.<Integer>newHashSet();
for (int i = min; i <= max; ++i)
{
set.add(Integer.valueOf(i));
}
this.allowedValues = ImmutableSet.copyOf(set);
}
}
示例5: readRecord
import com.google.common.collect.Sets; //导入依赖的package包/类
public Record readRecord(RecordSchema schema, JsonNode node) {
GenericRecord record = new GenericRecord(schema);
Set<String> jsonFields = Sets.newHashSet(node.fieldNames());
for (Field f : schema.getFields()) {
try {
if (!f.isRemoved()) {
JsonNode fieldValue = findValue(node, f, jsonFields);
if (fieldValue != null) {
Object val = getNodeData(f.getSchema(), fieldValue);
record.set(f.getOrd(), val);
}
}
} catch (Exception e) {
throw new RuntimeException("Exception reading field " + f.getName(), e);
}
}
if (!jsonFields.isEmpty()) {
throw new RuntimeException("Unknown fields " + jsonFields + " in JSON found");
}
return record;
}
示例6: testFindInstancesByIds
import com.google.common.collect.Sets; //导入依赖的package包/类
@Test
@Rollback
public void testFindInstancesByIds() throws Exception {
String someAppId = "someAppId";
String someClusterName = "someClusterName";
String someDataCenter = "someDataCenter";
String someIp = "someIp";
String anotherIp = "anotherIp";
Instance someInstance = instanceService.createInstance(assembleInstance(someAppId,
someClusterName, someDataCenter, someIp));
Instance anotherInstance = instanceService.createInstance(assembleInstance(someAppId,
someClusterName, someDataCenter, anotherIp));
List<Instance> instances = instanceService.findInstancesByIds(Sets.newHashSet(someInstance
.getId(), anotherInstance.getId()));
Set<String> ips = instances.stream().map(Instance::getIp).collect(Collectors.toSet());
assertEquals(2, instances.size());
assertEquals(Sets.newHashSet(someIp, anotherIp), ips);
}
示例7: createJvmAssemblyLocalComponentMetaData
import com.google.common.collect.Sets; //导入依赖的package包/类
private void createJvmAssemblyLocalComponentMetaData(EnumMap<UsageKind, List<PublishArtifact>> artifacts, JvmAssembly assembly, EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage, boolean toAssembly) {
configureUsageMetadata(UsageKind.API,
Collections.<DependencySpec>emptyList(),
dependenciesPerUsage);
configureUsageMetadata(UsageKind.RUNTIME,
Collections.<DependencySpec>emptyList(),
dependenciesPerUsage);
if (toAssembly) {
// TODO:Cedric This is an approximation: when a component wants to compile against the assembly of
// a library (not the jar), then we should give it the *stubbed classes* instead of the raw classes. However:
// - there's no such thing as a "stubbed classes assembly"
// - for performance reasons only the classes that belong to the API are stubbed, so we would miss the classes that do not belong to the API
// So this makes the UsageKind.API misleading (should this be COMPILE?).
addArtifact(UsageKind.API, assembly.getClassDirectories(), artifacts, assembly);
addArtifact(UsageKind.RUNTIME, Sets.union(assembly.getClassDirectories(), assembly.getResourceDirectories()), artifacts, assembly);
}
}
示例8: fictitiousSwitchTest
import com.google.common.collect.Sets; //导入依赖的package包/类
@Test
public void fictitiousSwitchTest() {
Set<String> switchIds = Sets.newHashSet("BD", "BL");
Network network = FictitiousSwitchFactory.create();
List<Boolean> expectedSwitchStates = getSwitchStates(network, switchIds);
BranchTripping tripping = new BranchTripping("CJ", "C");
Set<Switch> switchesToOpen = new HashSet<>();
Set<Terminal> terminalsToDisconnect = new HashSet<>();
tripping.traverse(network, null, switchesToOpen, terminalsToDisconnect);
assertEquals(switchIds, switchesToOpen.stream().map(Switch::getId).collect(Collectors.toSet()));
assertEquals(Collections.emptySet(), terminalsToDisconnect);
tripping.modify(network, null);
assertTrue(network.getSwitch("BD").isOpen());
assertTrue(network.getSwitch("BL").isOpen());
List<Boolean> switchStates = getSwitchStates(network, switchIds);
assertEquals(expectedSwitchStates, switchStates);
}
示例9: register
import com.google.common.collect.Sets; //导入依赖的package包/类
public void register(DrillOperatorTable operatorTable) {
SqlOperator op;
for (Entry<String, Collection<DrillFuncHolder>> function : methods.asMap().entrySet()) {
Set<Integer> argCounts = Sets.newHashSet();
String name = function.getKey().toUpperCase();
for (DrillFuncHolder func : function.getValue()) {
if (argCounts.add(func.getParamCount())) {
if (func.isAggregating()) {
op = new DrillSqlAggOperator(name, func.getParamCount());
} else {
boolean isDeterministic;
// prevent Drill from folding constant functions with types that cannot be materialized
// into literals
if (DrillConstExecutor.NON_REDUCIBLE_TYPES.contains(func.getReturnType().getMinorType())) {
isDeterministic = false;
} else {
isDeterministic = func.isDeterministic();
}
op = new DrillSqlOperator(name, func.getParamCount(), func.getReturnType(), isDeterministic);
}
operatorTable.add(function.getKey(), op);
}
}
}
}
示例10: testGetPorts
import com.google.common.collect.Sets; //导入依赖的package包/类
@Test
public final void testGetPorts() {
putDevice(DID1, SW1);
putDevice(DID2, SW1);
List<PortDescription> pds = Arrays.<PortDescription>asList(
new DefaultPortDescription(P1, true),
new DefaultPortDescription(P2, true)
);
deviceStore.updatePorts(PID, DID1, pds);
Set<PortNumber> expectedPorts = Sets.newHashSet(P1, P2);
List<Port> ports = deviceStore.getPorts(DID1);
for (Port port : ports) {
assertTrue("Port is enabled", port.isEnabled());
assertTrue("PortNumber is one of expected",
expectedPorts.remove(port.number()));
}
assertTrue("Event for all expectedport appeared", expectedPorts.isEmpty());
assertTrue("DID2 has no ports", deviceStore.getPorts(DID2).isEmpty());
}
示例11: expandDerivRightwards
import com.google.common.collect.Sets; //导入依赖的package包/类
private void expandDerivRightwards(Derivation leftChild) {
if (parser.verbose(6))
LogInfo.begin_track("Expanding rightward");
Map<String, List<Rule>> rhsCategoriesToRules = parser.leftToRightSiblingMap.get(leftChild.cat);
if (rhsCategoriesToRules != null) {
for (int i = 1; leftChild.end + i <= numTokens; ++i) {
Set<String> intersection = Sets.intersection(rhsCategoriesToRules.keySet(), chart[leftChild.end][leftChild.end + i].keySet());
for (String rhsCategory : intersection) {
List<Rule> compatibleRules = rhsCategoriesToRules.get(rhsCategory);
List<Derivation> rightChildren = chart[leftChild.end][leftChild.end + i].get(rhsCategory);
generateParentDerivations(leftChild, rightChildren, true, compatibleRules);
}
}
// handle terminals
if (leftChild.end < numTokens)
handleTerminalExpansion(leftChild, false, rhsCategoriesToRules);
}
if (parser.verbose(6))
LogInfo.end_track();
}
示例12: get
import com.google.common.collect.Sets; //导入依赖的package包/类
@Override
public Set<String> get() {
try {
try (InputStream inputStream = getClass().getResourceAsStream("SQL_RESERVED_WORDS.txt")) {
if (inputStream == null) {
throw new RuntimeException("Could not find resource: [SQL_RESERVED_WORDS.txt] near [" + getClass() + "]");
}
InputStreamReader streamReader = new InputStreamReader(inputStream, "UTF-8");
HashSet<String> sqlReservedWords = Sets.newHashSet(Splitter.on("\r\n").split(CharStreams.toString(streamReader)));
// temporary removal of words we currently have to allow
sqlReservedWords.remove("TYPE"); // DB2
sqlReservedWords.remove("OPERATION"); // DB2, SQL Server "future", PostGres
sqlReservedWords.remove("METHOD"); // PostGres
sqlReservedWords.remove("LANGUAGE"); // DB2, ODBC (?), SQL Server "future", PostGres
sqlReservedWords.remove("LOCATION"); // PostGres
sqlReservedWords.remove("YEAR"); // DB2, ODBC (?), SQL Server "future", PostGres
sqlReservedWords.remove("DAY"); // DB2, ODBC (?), SQL Server "future", PostGres
sqlReservedWords.remove("SECURITY"); // DB2, PostGres
return ImmutableSet.copyOf(sqlReservedWords);
}
} catch (IOException e) {
throw new RuntimeException("Failed to load [SQL_RESERVED_WORDS.txt]", e);
}
}
示例13: testOldConfig
import com.google.common.collect.Sets; //导入依赖的package包/类
@Test
public void testOldConfig() throws EventDeliveryException {
config.put(DatasetSinkConstants.CONFIG_KITE_DATASET_URI, null);
config.put(DatasetSinkConstants.CONFIG_KITE_REPO_URI, FILE_REPO_URI);
config.put(DatasetSinkConstants.CONFIG_KITE_DATASET_NAME, DATASET_NAME);
DatasetSink sink = sink(in, config);
// run the sink
sink.start();
sink.process();
sink.stop();
Assert.assertEquals(
Sets.newHashSet(expected),
read(Datasets.load(FILE_DATASET_URI)));
Assert.assertEquals("Should have committed", 0, remaining(in));
}
示例14: setUp
import com.google.common.collect.Sets; //导入依赖的package包/类
@Before
public void setUp() {
DatastoreContext datastoreContext = DatastoreContext.newBuilder().dataStoreName(dataStoreName)
.shardInitializationTimeout(10, TimeUnit.SECONDS).build();
Configuration configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider()) {
@Override
public Collection<MemberName> getUniqueMemberNamesForAllShards() {
return Sets.newHashSet(MemberName.forName("member-1"));
}
};
DatastoreContextFactory mockContextFactory = mock(DatastoreContextFactory.class);
Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
dataStore = new DistributedDataStore(getSystem(), new MockClusterWrapper(), configuration,
mockContextFactory, null);
dataStore.onGlobalContextUpdated(SchemaContextHelper.entityOwners());
}
示例15: init
import com.google.common.collect.Sets; //导入依赖的package包/类
@PostConstruct
public void init() {
// init env handler into map
String[] beanNameByType = springContext.getBeanNameByType(EnvHandler.class);
for (String bean : beanNameByType) {
EnvHandler envHandler = (EnvHandler) springContext.getBean(bean);
envHandlerMap.put(envHandler.env().name(), envHandler);
}
// init env list
Set<EnvKey> keys = Sets.newHashSet(FlowEnvs.values());
keys.addAll(Sets.newHashSet(GitEnvs.values()));
keys.addAll(Sets.newHashSet(GitToggleEnvs.values()));
keys.addAll(Sets.newHashSet(JobEnvs.values()));
keys.addAll(Sets.newHashSet(AgentEnvs.values()));
for (EnvKey key : keys) {
envKeyMap.put(key.name(), key);
if (key.isEditable()) {
editableKeyMap.put(key.name(), key);
} else {
noneEditableKeyMap.put(key.name(), key);
}
}
}