/**
* When providing 2 unapplied upgrade steps
* and one unapplied upgrade with with-only constraint (AddJamAmount should be applied only with AddJamType)
* When determining the upgrade path
* Then all 3 steps are applied in the correct order.
*/
@Test
public void testConditionalUpgradeStepIsExecuted() {
// given
List<Class<? extends UpgradeStep>> upgradeSteps = new ArrayList<>();
upgradeSteps.add(AddJamType.class);
upgradeSteps.add(AddDiameter.class);
upgradeSteps.add(AddJamAmount.class); // to be executed only with AddJamType
upgradeSteps.add(AddJamAmountUnit.class); // to be executed only with AddJamAmount
UpgradePathFinder pathFinder = makeFinder(upgradeSteps, appliedSteps());
Schema current = schema(sconeTable);
Schema target = schema(upgradedSconeTableWithJamAmount);
// when
List<UpgradeStep> path = pathFinder.determinePath(current, target, Sets.<String>newHashSet()).getUpgradeSteps();
// then
assertEquals("Number of upgrades steps", 4, path.size());
assertSame("First", AddDiameter.class, path.get(0).getClass());
assertSame("Second", AddJamType.class, path.get(1).getClass());
assertSame("Third", AddJamAmountUnit.class, path.get(2).getClass());
assertSame("Last", AddJamAmount.class, path.get(3).getClass());
}
java类com.google.common.collect.Sets的实例源码
TestUpgradePathFinder.java 文件源码
项目:morf
阅读 40
收藏 0
点赞 0
评论 0
GraphBase.java 文件源码
项目:memory-graph
阅读 34
收藏 0
点赞 0
评论 0
@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();
}
};
}
SSTable.java 文件源码
项目:sstable-adaptor
阅读 24
收藏 0
点赞 0
评论 0
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;
}
SourcelistLockingControllerTest.java 文件源码
项目:empiria.player
阅读 35
收藏 0
点赞 0
评论 0
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));
}
PropertyInteger.java 文件源码
项目:BaseClient
阅读 31
收藏 0
点赞 0
评论 0
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);
}
}
JsonReader.java 文件源码
项目:travny
阅读 40
收藏 0
点赞 0
评论 0
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;
}
InstanceServiceTest.java 文件源码
项目:apollo-custom
阅读 31
收藏 0
点赞 0
评论 0
@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);
}
JvmLocalLibraryMetaDataAdapter.java 文件源码
项目:Reer
阅读 30
收藏 0
点赞 0
评论 0
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);
}
}
BranchTrippingTest.java 文件源码
项目:powsybl-core
阅读 31
收藏 0
点赞 0
评论 0
@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);
}
DrillFunctionRegistry.java 文件源码
项目:QDrill
阅读 30
收藏 0
点赞 0
评论 0
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);
}
}
}
}
SimpleDeviceStoreTest.java 文件源码
项目:athena
阅读 26
收藏 0
点赞 0
评论 0
@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());
}
AbstractReinforcementParserState.java 文件源码
项目:TextHIN
阅读 30
收藏 0
点赞 0
评论 0
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();
}
SchemaValidator.java 文件源码
项目:morf
阅读 32
收藏 0
点赞 0
评论 0
@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);
}
}
TestDatasetSink.java 文件源码
项目:flume-release-1.7.0
阅读 46
收藏 0
点赞 0
评论 0
@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));
}
DistributedEntityOwnershipServiceTest.java 文件源码
项目:hashsdn-controller
阅读 31
收藏 0
点赞 0
评论 0
@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());
}
EnvServiceImpl.java 文件源码
项目:flow-platform
阅读 32
收藏 0
点赞 0
评论 0
@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);
}
}
}
ServerConfigurationManager.java 文件源码
项目:DecompiledMinecraft
阅读 35
收藏 0
点赞 0
评论 0
protected void sendScoreboard(ServerScoreboard scoreboardIn, EntityPlayerMP playerIn)
{
Set<ScoreObjective> set = Sets.<ScoreObjective>newHashSet();
for (ScorePlayerTeam scoreplayerteam : scoreboardIn.getTeams())
{
playerIn.playerNetServerHandler.sendPacket(new S3EPacketTeams(scoreplayerteam, 0));
}
for (int i = 0; i < 19; ++i)
{
ScoreObjective scoreobjective = scoreboardIn.getObjectiveInDisplaySlot(i);
if (scoreobjective != null && !set.contains(scoreobjective))
{
for (Packet packet : scoreboardIn.func_96550_d(scoreobjective))
{
playerIn.playerNetServerHandler.sendPacket(packet);
}
set.add(scoreobjective);
}
}
}
ValueAttribute.java 文件源码
项目:GitHub
阅读 38
收藏 0
点赞 0
评论 0
private List<CharSequence> extractAnnotationsForElement(ElementType elementType, Set<String> additionalAnnotations) {
List<CharSequence> allAnnotations = Lists.newArrayListWithCapacity(1);
boolean dontHaveJsonPropetyAnnotationAlready = Annotations.getAnnotationLines(element,
Collections.singleton(Annotations.JACKSON_PROPERTY),
false,
elementType,
importsResolver,
nullability).isEmpty();
if (dontHaveJsonPropetyAnnotationAlready) {
allAnnotations.add(jacksonPropertyAnnotation());
}
allAnnotations.addAll(
Annotations.getAnnotationLines(element,
Sets.union(additionalAnnotations,
protoclass().styles().style().additionalJsonAnnotationsNames()),
protoclass().environment().hasJacksonLib(),
elementType,
importsResolver,
nullability));
return allAnnotations;
}
AutoriseerOnderzoekServiceImpl.java 文件源码
项目:OperatieBRP
阅读 31
收藏 0
点赞 0
评论 0
private void corrigeerVoorMutatielevering(final List<Onderzoekbundel> teLeverenOnderzoekbundels, final OnderzoekData data) {
final Set<MetaRecord> origineleDelta = Sets.newHashSet(data.berichtgegevens.getDeltaRecords());
final Collection<MetaObject> gewijzigdeBetrokkenheden = bepaalBetrokkenhedenInDelta(data.berichtgegevens);
for (Onderzoekbundel onderzoekbundel : teLeverenOnderzoekbundels) {
//als de mutatie enkel het onderzoek geraakt heeft, maar niet het eigenlijke gegeven dat aangewezen wordt
//dan moet dat gegeven alsnog toegevoegd worden aan de delta. Dit voorkomt dat het onderzoek wel getoond
//wordt maar het gegeven niet.
final Collection<MetaModel> metaModels = data.gegevensInOnderzoek.get(onderzoekbundel);
final Set<MetaRecord> records = geefRecordsVanOnderzoekgegeven(metaModels);
records.retainAll(data.berichtgegevens.getGeautoriseerdeRecords());
for (final MetaRecord record : records) {
//toon onderzoeken op identificerende gegevens (die niet in de delta zitten) van een betrokkenheid
//alleen als *iets* van de betrokkenheid gewijzigd is.
if (gegevenInOnderzoekZitInDelta(onderzoekbundel, data, origineleDelta) ||
origineleDelta.contains(record) || bepaalTonenIdentificerendGegeven(gewijzigdeBetrokkenheden, record)) {
voegOnderzoekToeAanDelta(onderzoekbundel, data);
//behoud de geautoriseerde records die in delta zitten of in identificerende groep zitten, door ze aan de set deltarecords toe te voegen
data.berichtgegevens.addDeltaRecord(record);
}
}
}
}
PropertyInteger.java 文件源码
项目:CustomWorldGen
阅读 25
收藏 0
点赞 0
评论 0
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);
}
}
PersistentRegistryManager.java 文件源码
项目:CustomWorldGen
阅读 33
收藏 0
点赞 0
评论 0
private <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(ResourceLocation registryName, Class<T> type, ResourceLocation defaultObjectKey, int minId, int maxId, IForgeRegistry.AddCallback<T> addCallback, IForgeRegistry.ClearCallback<T> clearCallback, IForgeRegistry.CreateCallback<T> createCallback, IForgeRegistry.SubstitutionCallback<T> substitutionCallback)
{
Set<Class<?>> parents = Sets.newHashSet();
findSuperTypes(type, parents);
SetView<Class<?>> overlappedTypes = Sets.intersection(parents, registrySuperTypes.keySet());
if (!overlappedTypes.isEmpty())
{
Class<?> foundType = overlappedTypes.iterator().next();
FMLLog.severe("Found existing registry of type %1s named %2s, you cannot create a new registry (%3s) with type %4s, as %4s has a parent of that type", foundType, registrySuperTypes.get(foundType), registryName, type);
throw new IllegalArgumentException("Duplicate registry parent type found - you can only have one registry for a particular super type");
}
FMLControlledNamespacedRegistry<T> fmlControlledNamespacedRegistry = new FMLControlledNamespacedRegistry<T>(defaultObjectKey, minId, maxId, type, registries, addCallback, clearCallback, createCallback, substitutionCallback);
registries.put(registryName, fmlControlledNamespacedRegistry);
registrySuperTypes.put(type, registryName);
return getRegistry(registryName, type);
}
WatchKeysUtil.java 文件源码
项目:apollo-custom
阅读 22
收藏 0
点赞 0
评论 0
/**
* Assemble watch keys for the given appId, cluster, namespaces, dataCenter combination
*
* @return a multimap with namespace as the key and watch keys as the value
*/
public Multimap<String, String> assembleAllWatchKeys(String appId, String clusterName,
Set<String> namespaces,
String dataCenter) {
Multimap<String, String> watchedKeysMap =
assembleWatchKeys(appId, clusterName, namespaces, dataCenter);
//Every app has an 'application' namespace
if (!(namespaces.size() == 1 && namespaces.contains(ConfigConsts.NAMESPACE_APPLICATION))) {
Set<String> namespacesBelongToAppId = namespacesBelongToAppId(appId, namespaces);
Set<String> publicNamespaces = Sets.difference(namespaces, namespacesBelongToAppId);
//Listen on more namespaces if it's a public namespace
if (!publicNamespaces.isEmpty()) {
watchedKeysMap
.putAll(findPublicConfigWatchKeys(appId, clusterName, publicNamespaces, dataCenter));
}
}
return watchedKeysMap;
}
MediaTypeClassifierBuilder.java 文件源码
项目:url-classifier
阅读 52
收藏 0
点赞 0
评论 0
MediaTypeClassifierImpl(Iterable<? extends MediaType> mts) {
Table<String, String, Set<MediaType>> typeTable =
HashBasedTable.<String, String, Set<MediaType>>create();
for (MediaType mt : mts) {
String type = mt.type();
String subtype = mt.subtype();
Set<MediaType> typeSet = typeTable.get(type, subtype);
if (typeSet == null) {
typeSet = Sets.newLinkedHashSet();
typeTable.put(type, subtype, typeSet);
}
typeSet.add(mt);
}
ImmutableTable.Builder<String, String, ImmutableSet<MediaType>> b =
ImmutableTable.builder();
for (Table.Cell<String, String, Set<MediaType>> cell
: typeTable.cellSet()) {
b.put(cell.getRowKey(), cell.getColumnKey(), ImmutableSet.copyOf(cell.getValue()));
}
this.types = b.build();
}
DefaultMynlpSegment.java 文件源码
项目:mynlp
阅读 23
收藏 0
点赞 0
评论 0
public static void main(String[] args) {
List<Integer> xlist = Lists.newArrayList();
for (int i = 0; i < 100000; i++) {
xlist.add(i);
}
Spliterator<Integer> spliterator = Iterables.concat(xlist).spliterator();
Set<String> xset = Sets.newHashSet();
Stream<Double> stream = StreamSupport.stream(spliterator, true).map(
num -> {
double r = num / 2.0;
xset.add(Thread.currentThread().getName());
return r;
});
Iterator<Double> iterator = stream.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
System.out.println(xset);
}
ControlPlaneRedirectManagerTest.java 文件源码
项目:athena
阅读 32
收藏 0
点赞 0
评论 0
/**
* Setup Interface expectation for all Testcases.
**/
private void setUpInterfaceService() {
Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
interfaceIpAddresses1
.add(new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), IpPrefix.valueOf("192.168.10.0/24")));
Interface sw1Eth1 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH1, interfaceIpAddresses1,
MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE);
interfaces.add(sw1Eth1);
Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet();
interfaceIpAddresses2
.add(new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), IpPrefix.valueOf("192.168.20.0/24")));
Interface sw1Eth2 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH2, interfaceIpAddresses2,
MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE);
interfaces.add(sw1Eth2);
Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet();
interfaceIpAddresses3
.add(new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), IpPrefix.valueOf("192.168.30.0/24")));
Interface sw1Eth3 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH3, interfaceIpAddresses3,
MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE);
interfaces.add(sw1Eth3);
}
FlowRuleDriverProvider.java 文件源码
项目:athena
阅读 26
收藏 0
点赞 0
评论 0
@Override
public void executeBatch(FlowRuleBatchOperation batch) {
ImmutableList.Builder<FlowRule> toAdd = ImmutableList.builder();
ImmutableList.Builder<FlowRule> toRemove = ImmutableList.builder();
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
if (fbe.operator() == ADD || fbe.operator() == MODIFY) {
toAdd.add(fbe.target());
} else if (fbe.operator() == REMOVE) {
toRemove.add(fbe.target());
}
}
ImmutableList<FlowRule> rulesToAdd = toAdd.build();
ImmutableList<FlowRule> rulesToRemove = toRemove.build();
Collection<FlowRule> added = applyFlowRules(batch.deviceId(), rulesToAdd);
Collection<FlowRule> removed = removeFlowRules(batch.deviceId(), rulesToRemove);
Set<FlowRule> failedRules = Sets.union(Sets.difference(copyOf(rulesToAdd), copyOf(added)),
Sets.difference(copyOf(rulesToRemove), copyOf(removed)));
CompletedBatchOperation status =
new CompletedBatchOperation(failedRules.isEmpty(), failedRules, batch.deviceId());
providerService.batchOperationCompleted(batch.id(), status);
}
HashTestUtils.java 文件源码
项目:googles-monorepo-demo
阅读 35
收藏 0
点赞 0
评论 0
/**
* Checks that a Hasher returns the same HashCode when given the same input, and also
* that the collision rate looks sane.
*/
static void assertInvariants(HashFunction hashFunction) {
int objects = 100;
Set<HashCode> hashcodes = Sets.newHashSetWithExpectedSize(objects);
Random random = new Random(314159);
for (int i = 0; i < objects; i++) {
int value = random.nextInt();
HashCode hashcode1 = hashFunction.hashInt(value);
HashCode hashcode2 = hashFunction.hashInt(value);
Assert.assertEquals(hashcode1, hashcode2); // idempotent
Assert.assertEquals(hashFunction.bits(), hashcode1.bits());
Assert.assertEquals(hashFunction.bits(), hashcode1.asBytes().length * 8);
hashcodes.add(hashcode1);
}
Assert.assertTrue(hashcodes.size() > objects * 0.95); // quite relaxed test
assertHashBytesThrowsCorrectExceptions(hashFunction);
assertIndependentHashers(hashFunction);
assertShortcutsAreEquivalent(hashFunction, 512);
}
CacheBuilderFactory.java 文件源码
项目:googles-monorepo-demo
阅读 26
收藏 0
点赞 0
评论 0
/**
* Sets.cartesianProduct doesn't allow sets that contain null, but we want null to mean
* "don't call the associated CacheBuilder method" - that is, get the default CacheBuilder
* behavior. This method wraps the elements in the input sets (which may contain null) as
* Optionals, calls Sets.cartesianProduct with those, then transforms the result to unwrap
* the Optionals.
*/
private Iterable<List<Object>> buildCartesianProduct(Set<?>... sets) {
List<Set<Optional<?>>> optionalSets = Lists.newArrayListWithExpectedSize(sets.length);
for (Set<?> set : sets) {
Set<Optional<?>> optionalSet =
Sets.newLinkedHashSet(Iterables.transform(set, NULLABLE_TO_OPTIONAL));
optionalSets.add(optionalSet);
}
Set<List<Optional<?>>> cartesianProduct = Sets.cartesianProduct(optionalSets);
return Iterables.transform(cartesianProduct,
new Function<List<Optional<?>>, List<Object>>() {
@Override public List<Object> apply(List<Optional<?>> objs) {
return Lists.transform(objs, OPTIONAL_TO_NULLABLE);
}
});
}
PropertyInteger.java 文件源码
项目:BaseClient
阅读 22
收藏 0
点赞 0
评论 0
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);
}
}
PlayerList.java 文件源码
项目:CustomWorldGen
阅读 34
收藏 0
点赞 0
评论 0
protected void sendScoreboard(ServerScoreboard scoreboardIn, EntityPlayerMP playerIn)
{
Set<ScoreObjective> set = Sets.<ScoreObjective>newHashSet();
for (ScorePlayerTeam scoreplayerteam : scoreboardIn.getTeams())
{
playerIn.connection.sendPacket(new SPacketTeams(scoreplayerteam, 0));
}
for (int i = 0; i < 19; ++i)
{
ScoreObjective scoreobjective = scoreboardIn.getObjectiveInDisplaySlot(i);
if (scoreobjective != null && !set.contains(scoreobjective))
{
for (Packet<?> packet : scoreboardIn.getCreatePackets(scoreobjective))
{
playerIn.connection.sendPacket(packet);
}
set.add(scoreobjective);
}
}
}