List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.eclipse.recommenders.utils.rcp.ast.ASTNodeUtils.java
public static boolean sameType(final ITypeBinding jdtType, final ITypeName crType) { final Optional<ITypeName> opt = BindingUtils.toTypeName(jdtType); if (opt.isPresent()) { return opt.get().equals(crType); }// www.ja v a2 s . c o m return false; }
From source file:org.jboss.aerogear.controller.util.ParameterExtractor.java
private static Optional<?> extractDefaultParam(final Class<?> type, final Optional<?> defaultValue) throws Exception { if (defaultValue.isPresent()) { return Optional.of(createInstance(type, defaultValue.get().toString())); }//w w w. j a va2s . c om return Optional.absent(); }
From source file:org.jboss.aerogear.controller.util.ParameterExtractor.java
private static boolean addIfPresent(final Optional<?> op, final String paramName, final Map<String, Object> args) { if (op.isPresent()) { args.put(paramName, op.get()); return true; }/* w w w . jav a 2 s .c o m*/ return false; }
From source file:org.opendaylight.vpnservice.interfacemgr.renderer.ovs.utilities.VlanTrunkSouthboundUtils.java
private static void updateTerminationPoint(InstanceIdentifier<?> bridgeIid, OvsdbBridgeAugmentation bridgeNode, String bridgeName, String parentInterface, int vlanId, DataBroker dataBroker, WriteTransaction t) { if (vlanId == 0) { LOG.error("Found vlanid 0 for bridge: {}, interface: {}", bridgeName, parentInterface); return;/*from w ww. j ava2 s. c om*/ } InstanceIdentifier<TerminationPoint> tpIid = createTerminationPointInstanceIdentifier( InstanceIdentifier.keyOf(bridgeIid.firstIdentifierOf(Node.class)), parentInterface); OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpAugmentationBuilder.setName(parentInterface); tpAugmentationBuilder.setVlanMode(OvsdbPortInterfaceAttributes.VlanMode.Trunk); OvsdbTerminationPointAugmentation terminationPointAugmentation = null; Optional<TerminationPoint> terminationPointOptional = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, tpIid, dataBroker); if (terminationPointOptional.isPresent()) { TerminationPoint terminationPoint = terminationPointOptional.get(); terminationPointAugmentation = terminationPoint .getAugmentation(OvsdbTerminationPointAugmentation.class); if (terminationPointAugmentation != null) { List<Trunks> trunks = terminationPointAugmentation.getTrunks(); if (trunks != null) { trunks.remove(new TrunksBuilder().setTrunk(new VlanId(vlanId)).build()); } tpAugmentationBuilder.setTrunks(trunks); TerminationPointBuilder tpBuilder = new TerminationPointBuilder(); tpBuilder.setKey(InstanceIdentifier.keyOf(tpIid)); tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build()); t.put(LogicalDatastoreType.CONFIGURATION, tpIid, tpBuilder.build(), true); } } }
From source file:org.dswarm.graph.gdm.utils.NodeTypeUtils.java
public static Optional<NodeType> getNodeTypeByGDMNodeType( final Optional<org.dswarm.graph.json.NodeType> optionalNodeType, final Optional<Boolean> optionalIsType) { if (!optionalNodeType.isPresent()) { return Optional.absent(); }//from ww w .jav a 2s . co m final NodeType nodeType; switch (optionalNodeType.get()) { case Literal: nodeType = NodeType.Literal; break; case Resource: if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.Resource; } else { nodeType = NodeType.TypeResource; } } else { nodeType = NodeType.Resource; } break; case BNode: if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.BNode; } else { nodeType = NodeType.TypeBNode; } } else { nodeType = NodeType.BNode; } break; default: nodeType = null; } return Optional.fromNullable(nodeType); }
From source file:org.opendaylight.vpnservice.elan.l2gw.utils.L2GatewayConnectionUtils.java
public static List<L2gatewayConnection> getAllL2gatewayConnections(DataBroker broker) { InstanceIdentifier<L2gatewayConnections> inst = InstanceIdentifier.create(Neutron.class) .child(L2gatewayConnections.class); Optional<L2gatewayConnections> l2GwConns = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst); if (l2GwConns.isPresent()) { return l2GwConns.get().getL2gatewayConnection(); }/*from ww w.ja v a2s .c o m*/ return null; }
From source file:org.opendaylight.netvirt.natservice.internal.NatOverVxlanUtil.java
public static void validateAndCreateVxlanVniPool(DataBroker broker, INeutronVpnManager neutronvpnManager, IdManagerService idManager, String poolName) { /*// w w w. j a va 2 s . co m * 1. If a NatPool doesn't exist create it. 2. If a NatPool exists, but * the range value is changed incorrectly (say some allocations exist in * the old range), we should NOT honor the new range . Throw the WARN * but continue running NAT Service with Old range. 3. If a NatPool * exists, but the given range is wider than the earlier one, we should * attempt to allocate with the new range again(TODO) */ long lowLimit = NatConstants.VNI_DEFAULT_LOW_VALUE; long highLimit = NatConstants.VNI_DEFAULT_HIGH_VALUE; String configureVniRange = neutronvpnManager.getOpenDaylightVniRangesConfig(); if (configureVniRange != null) { String[] configureVniRangeSplit = configureVniRange.split(":"); lowLimit = Long.parseLong(configureVniRangeSplit[0]); highLimit = Long.parseLong(configureVniRangeSplit[1]); } Optional<IdPool> existingIdPool = NatUtil.read(broker, LogicalDatastoreType.CONFIGURATION, getIdPoolInstance(poolName)); if (existingIdPool.isPresent()) { IdPool odlVniIdPool = existingIdPool.get(); long currentStartLimit = odlVniIdPool.getAvailableIdsHolder().getStart(); long currentEndLimit = odlVniIdPool.getAvailableIdsHolder().getEnd(); if (lowLimit == currentStartLimit && highLimit == currentEndLimit) { LOG.debug("NAT Service : OpenDaylight VXLAN VNI range pool already exists with configured Range"); } else { if (odlVniIdPool.getIdEntries() != null && odlVniIdPool.getIdEntries().size() != 0) { LOG.warn("NAT Service : Some Allocation already exists with old Range. " + "Cannot modify existing limit of OpenDaylight VXLAN VNI range pool"); } else { LOG.debug( "NAT Service : No VNI's allocated from OpenDaylight VXLAN VNI range pool." + "Delete and re-create pool with new configured Range {}-{}", lowLimit, highLimit); deleteOpenDaylightVniRangesPool(idManager, poolName); createOpenDaylightVniRangesPool(idManager, poolName, lowLimit, highLimit); } } } else { createOpenDaylightVniRangesPool(idManager, poolName, lowLimit, highLimit); } }
From source file:ec.nbdemetra.ui.Installer.java
public static void loadConfig(Collection<?> list, Preferences root) { Parsers.Parser<Config> parser = Config.xmlParser(); for (IConfigurable o : Iterables.filter(list, IConfigurable.class)) { Config current = o.getConfig();//from w w w .ja v a2 s.c o m try { if (root.nodeExists(current.getDomain())) { Preferences domain = root.node(current.getDomain()); Optional<Config> config = InstallerStep.tryGet(domain, current.getName(), parser); if (config.isPresent()) { o.setConfig(config.get()); } } } catch (BackingStoreException ex) { // do nothing? } } }
From source file:org.apache.lens.cube.parse.ColumnResolver.java
private static boolean isTimeRangeFunc(final ASTNode node) { Optional<String> funcNameOp = getNameIfFunc(node); final String funcName = funcNameOp.isPresent() ? funcNameOp.get() : null; return CubeQueryContext.TIME_RANGE_FUNC.equalsIgnoreCase(funcName); }
From source file:google.registry.model.registry.label.PremiumListUtils.java
/** * Returns the premium price for the specified label and registry, or absent if the label is not * premium./*from w w w. j a v a 2 s . c o m*/ */ public static Optional<Money> getPremiumPrice(String label, Registry registry) { // If the registry has no configured premium list, then no labels are premium. if (registry.getPremiumList() == null) { return Optional.<Money>absent(); } String listName = registry.getPremiumList().getName(); Optional<PremiumList> optionalPremiumList = PremiumList.get(listName); checkState(optionalPremiumList.isPresent(), "Could not load premium list '%s'", listName); PremiumList premiumList = optionalPremiumList.get(); PremiumListRevision revision; try { revision = cachePremiumListRevisions.get(premiumList.getRevisionKey()); } catch (InvalidCacheLoadException | ExecutionException e) { throw new RuntimeException("Could not load premium list revision " + premiumList.getRevisionKey(), e); } checkState(revision.probablePremiumLabels != null, "Probable premium labels bloom filter is null on revision '%s'", premiumList.getRevisionKey()); if (revision.probablePremiumLabels.mightContain(label)) { Key<PremiumListEntry> entryKey = Key.create(premiumList.getRevisionKey(), PremiumListEntry.class, label); try { Optional<PremiumListEntry> entry = cachePremiumListEntries.get(entryKey); return (entry.isPresent()) ? Optional.of(entry.get().getValue()) : Optional.<Money>absent(); } catch (InvalidCacheLoadException | ExecutionException e) { throw new RuntimeException("Could not load premium list entry " + entryKey, e); } } else { return Optional.<Money>absent(); } }