Example usage for com.google.common.collect Maps newEnumMap

List of usage examples for com.google.common.collect Maps newEnumMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newEnumMap.

Prototype

public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(Map<K, ? extends V> map) 

Source Link

Document

Creates an EnumMap with the same mappings as the specified map.

Usage

From source file:com.notifier.desktop.notification.impl.NotificationManagerImpl.java

@Inject
public NotificationManagerImpl(Provider<ApplicationPreferences> preferencesProvider, SwtManager swtManager,
        OperatingSystemProcessManager processManager, DeviceManager deviceManager,
        @Tray NotificationBroadcaster trayBroadcaster, @Growl NotificationBroadcaster growlBroadcaster,
        @Libnotify NotificationBroadcaster libnotifyBroadcaster,
        @Msn InstantMessagingNotificationBroadcaster msnBroadcaster) {
    this.broadcasters = ImmutableList.of(trayBroadcaster, growlBroadcaster, libnotifyBroadcaster,
            msnBroadcaster);/*from  ww  w.ja v a 2  s .c  o m*/
    this.swtManager = swtManager;
    this.processManager = processManager;
    this.deviceManager = deviceManager;
    this.lastNotifications = new MapMaker().initialCapacity(50).expiration(60, SECONDS).makeMap();

    ApplicationPreferences prefs = preferencesProvider.get();
    this.privateMode = prefs.isPrivateMode();
    this.notificationConfigurations = Maps.newEnumMap(Notification.Type.class);
    for (Notification.Type type : Notification.Type.values()) {
        NotificationConfiguration config = new NotificationConfiguration(type);
        config.setEnabled(prefs.isNotificationEnabled(type));
        config.setSendToClipboard(prefs.isNotificationClipboard(type));
        config.setExecuteCommand(prefs.isNotificationExecuteCommand(type));
        config.setCommand(prefs.getNotificationCommand(type));
        notificationConfigurations.put(type, config);
    }
}

From source file:com.torodb.torod.db.backends.postgresql.converters.json.PostgreSQLValueToJsonConverterProvider.java

private PostgreSQLValueToJsonConverterProvider() {
    converters = Maps.newEnumMap(ScalarType.class);
    converters.put(ScalarType.ARRAY,//from ww w  .  jav  a  2s  . c  o  m
            new ArrayValueToJsonConverter(PostgreSQLValueToArrayConverterProvider.getInstance()));
    converters.put(ScalarType.BOOLEAN, new BooleanValueToJsonConverter());
    converters.put(ScalarType.DATE, new DateValueToJsonConverter());
    converters.put(ScalarType.INSTANT, new InstantValueToJsonConverter());
    converters.put(ScalarType.DOUBLE, new DoubleValueToJsonConverter());
    converters.put(ScalarType.INTEGER, new IntegerValueToJsonConverter());
    converters.put(ScalarType.LONG, new LongValueToJsonConverter());
    converters.put(ScalarType.NULL, new NullValueToJsonConverter());
    converters.put(ScalarType.STRING, new StringValueToJsonConverter());
    converters.put(ScalarType.TIME, new TimeValueToJsonConverter());
    converters.put(ScalarType.MONGO_OBJECT_ID, new MongoObjectIdValueToJsonConverter());
    converters.put(ScalarType.MONGO_TIMESTAMP, new MongoTimestampValueToJsonConverter());
    converters.put(ScalarType.BINARY, new BinaryValueToJsonConverter());

    SetView<ScalarType> withoutConverter = Sets.difference(converters.keySet(), SUPPORTED_TYPES);
    if (!withoutConverter.isEmpty()) {
        throw new AssertionError("It is not defined how to convert from the following scalar "
                + "types to json: " + withoutConverter);
    }
}

From source file:org.geosdi.geoplatform.gml.api.parser.base.parameter.GMLBaseParametersRepo.java

private static void lookUpAllParameters() {
    parameters = Maps.newEnumMap(BaseParameterEnum.class);

    final ParameterValue<String[]> defaultSRSParameterFormat = new SRSFormatParameterPatterns();
    parameters.put(BaseParameterEnum.DEFAULT_SRS_PARAMETER_FORMAT, defaultSRSParameterFormat);

    final ParameterValue<GeometryFactory> defaultGeometryFactory = new GeometryFactoryParameter();
    parameters.put(BaseParameterEnum.DEFAULT_GEOMETRY_FACTORY, defaultGeometryFactory);

    final ParameterValue<DefaultSRSBaseParser> defaultSRSParser = new DefaultSRSParserParameter(
            defaultSRSParameterFormat.getValue());
    parameters.put(BaseParameterEnum.DEFAULT_SRS_PARSER, defaultSRSParser);

    final ParameterValue<CoordinateBaseParser> defaultCoordinateParser = new CoordinateParserParameter();
    parameters.put(BaseParameterEnum.DEFAULT_COORDINATE_PARSER, defaultCoordinateParser);

    final ParameterValue<GMLBasePointParser> defaultPointParser = new PointParserParameter(
            defaultGeometryFactory, defaultSRSParser, defaultCoordinateParser);
    parameters.put(BaseParameterEnum.DEFAULT_POINT_PARSER, defaultPointParser);

    final ParameterValue<GMLBaseLineStringParser> defaultLineStringParser = new LineStringParserParameter(
            defaultGeometryFactory, defaultSRSParser, defaultCoordinateParser, defaultPointParser);
    parameters.put(BaseParameterEnum.DEFAULT_LINE_STRING_PARSER, defaultLineStringParser);

    final ParameterValue<GMLBaseLinearRingParser> defaultLinearRingParser = new LinearRingParserParameter(
            defaultGeometryFactory, defaultSRSParser, defaultCoordinateParser, defaultPointParser);
    parameters.put(BaseParameterEnum.DEFAULT_LINEAR_RING_PARSER, defaultLinearRingParser);

    final ParameterValue<GMLBasePolygonParser> defaultPolygonParser = new PolygonParserParameter(
            defaultGeometryFactory, defaultSRSParser, defaultLinearRingParser);
    parameters.put(BaseParameterEnum.DEFAULT_POLYGON_PARSER, defaultPolygonParser);

    final ParameterValue<GMLBaseCurveParser> defaultCurveParser = new CurveParserParameter(
            defaultGeometryFactory, defaultSRSParser);
    parameters.put(BaseParameterEnum.DEFAULT_CURVE_PARSER, defaultCurveParser);

    final ParameterValue<GMLBaseMultiPointParser> defaultMultiPointParser = new MultiPointParserParameter(
            defaultGeometryFactory, defaultSRSParser, defaultPointParser);
    parameters.put(BaseParameterEnum.DEFAULT_MULTI_POINT_PARSER, defaultMultiPointParser);

    final ParameterValue<GMLBaseMultiLineStringParser> defaultMultiLineStringParser = new MultiLineStringParserParameter(
            defaultGeometryFactory, defaultSRSParser, defaultLineStringParser);
    parameters.put(BaseParameterEnum.DEFAULT_MULTI_LINE_STRING_PARSER, defaultMultiLineStringParser);

    final ParameterValue<GMLBaseMultiPolygonParser> defaultMultiPolygonParser = new MultiPolygonParserParameter(
            defaultGeometryFactory, defaultSRSParser, defaultPolygonParser);
    parameters.put(BaseParameterEnum.DEFAULT_MULTI_POLYGON_PARSER, defaultMultiPolygonParser);

    final ParameterValue<GMLBaseMultiSurfaceParser> defaultMultiSurfaceParser = new MultiSurfaceParserParameter(
            defaultGeometryFactory, defaultSRSParser, defaultPolygonParser);
    parameters.put(BaseParameterEnum.DEFAULT_MULTI_SURFACE_PARSER, defaultMultiSurfaceParser);

    final ParameterValue<GMLBaseSextanteParser> defaultSextanteParser = new SextanteParserParameter();
    parameters.put(BaseParameterEnum.DEFAULT_SEXTANTE_PARSER, defaultSextanteParser);

    final ParameterValue<GMLBaseMultiGeometryParser> defaultMultiGeometryParser = new MultiGeometryParserParameter();
    parameters.put(BaseParameterEnum.DEFAULT_MULTI_GEOMETRY_PARSER, defaultMultiGeometryParser);

    final ParameterValue<GMLBaseMultiCurveParser> defaultMultiCurveParser = new MultiCurveParserParameter(
            defaultGeometryFactory, defaultSRSParser);
    parameters.put(BaseParameterEnum.DEFAULT_MULTI_CURVE_PARSER, defaultMultiCurveParser);
}

From source file:ws.ip4u.mediadaemon.TVDB.java

public TVDB(String apikey, DB db) throws ParserConfigurationException, SAXException, IOException {
    this.apikey = apikey;
    this.db = db;
    service = Client.create().resource("http://www.thetvdb.com/api");
    String mirrorsXml = service.path(this.apikey + "/mirrors.xml").accept(MediaType.TEXT_XML).get(String.class);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//from www.  j  a  v  a2  s. com
    parser = factory.newDocumentBuilder();
    Document doc = parser.parse(new ByteArrayInputStream(mirrorsXml.getBytes()));

    NodeList mirrorsList = doc.getElementsByTagName("Mirrors");
    mirrors = Maps.newEnumMap(ResourceType.class);

    for (int i = 0; i < mirrorsList.getLength(); i++) {
        Node mirrorNode = mirrorsList.item(i);
        NodeList attributes = mirrorNode.getChildNodes();
        String mirrorPath = null;
        int typeMask = 0;
        for (int j = 0; j < attributes.getLength(); j++) {
            Node attrib = attributes.item(j);
            switch (attrib.getLocalName()) {
            case "mirrorpath":
                mirrorPath = attrib.getNodeValue();
                break;
            case "typemask":
                typeMask = Integer.parseInt(attrib.getNodeValue());
                break;
            }
        }
        if (mirrorPath != null) {
            for (ResourceType resourceType : ResourceType.values()) {
                if ((resourceType.typeMask & typeMask) == 1) {
                    if (!mirrors.containsKey(resourceType)) {
                        mirrors.put(resourceType, Lists.<String>newArrayList());
                    }

                    mirrors.get(resourceType).add(mirrorPath);
                }
            }
        }
    }
}

From source file:com.android.ide.common.res2.ValueResourceParser2.java

/**
 * Parses the file and returns a list of {@link ResourceItem} objects.
 * @return a list of resources./*from  w  ww  .  ja  v a  2s .c  o  m*/
 *
 * @throws MergingException if a merging exception happens
 */
@NonNull
List<ResourceItem> parseFile() throws MergingException {
    Document document = parseDocument(mFile);

    // get the root node
    Node rootNode = document.getDocumentElement();
    if (rootNode == null) {
        return Collections.emptyList();
    }
    NodeList nodes = rootNode.getChildNodes();

    final int count = nodes.getLength();
    // list containing the result
    List<ResourceItem> resources = Lists.newArrayListWithExpectedSize(count);
    // Multimap to detect dups
    Map<ResourceType, Set<String>> map = Maps.newEnumMap(ResourceType.class);

    for (int i = 0, n = nodes.getLength(); i < n; i++) {
        Node node = nodes.item(i);

        if (node.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        ResourceItem resource = getResource(node, mFile);
        if (resource != null) {
            // check this is not a dup
            checkDuplicate(resource, map, mFile);

            resources.add(resource);

            if (resource.getType() == ResourceType.DECLARE_STYLEABLE) {
                // Need to also create ATTR items for its children
                addStyleableItems(node, resources, map, mFile);
            }
        }
    }

    return resources;
}

From source file:se.toxbee.sleepfighter.audio.playlist.PlaylistProviderFactory.java

/**
 * Returns a PlaylistProvider that matches the ProviderID.<br/>
 * This is lazy loaded.//ww  w.  j av a2s . c  om
 *
 * @param id the ProviderID.
 * @return the provider.
 */
public PlaylistProvider getProvider(ProviderID id) {
    if (this.entries == null) {
        this.entries = Maps.newEnumMap(ProviderID.class);
    }

    PlaylistProvider provider = this.entries.get(id);

    if (provider == null) {
        switch (id) {
        case LOCAL:
            provider = new LocalPlaylistProvider();
            break;
        }

        this.entries.put(id, provider);
    }

    return provider;
}

From source file:org.erlide.ui.wizards.NewErlangProjectWizard.java

@Override
public void addPages() {
    try {// w  ww. j a va 2s.com
        super.addPages();
        info = new NewProjectData();
        info.copyFrom(ErlangProjectProperties.DEFAULT);

        buildPages = Maps.newEnumMap(ProjectConfigType.class);

        mainPage = new ErlangNewProjectCreationPage("mainPage", info);
        mainPage.setTitle(ErlideUIPlugin.getResourceString("wizards.titles.newproject"));
        mainPage.setDescription(ErlideUIPlugin.getResourceString("wizards.descs.newproject"));
        mainPage.setImageDescriptor(
                ErlideUIPlugin.getDefault().getImageDescriptor(ErlideUIConstants.IMG_NEW_PROJECT_WIZARD));
        addPage(mainPage);

        builderPage = new ErlangProjectBuilderPage("builderPage", info);
        builderPage.setTitle(ErlideUIPlugin.getResourceString("wizards.titles.builderprefs"));
        builderPage.setDescription(ErlideUIPlugin.getResourceString("wizards.descs.builderprefs"));
        builderPage.setImageDescriptor(
                ErlideUIPlugin.getDefault().getImageDescriptor(ErlideUIConstants.IMG_NEW_PROJECT_WIZARD));
        addPage(builderPage);

        for (final ProjectConfigType builder : ProjectConfigType.values()) {
            final ProjectPreferencesWizardPage buildPage = ProjectPreferencesWizardPageFactory.create(builder,
                    info);
            buildPages.put(builder, buildPage);
            buildPage.setImageDescriptor(
                    ErlideUIPlugin.getDefault().getImageDescriptor(ErlideUIConstants.IMG_NEW_PROJECT_WIZARD));
            addPage(buildPage);

        }

        // only add page if there are already projects in the workspace
        if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length > 0) {
            referencePage = new WizardNewProjectReferencePage("basicReferenceProjectPage");//$NON-NLS-1$
            referencePage.setTitle(WizardMessages.NewProject_referenceTitle);
            referencePage.setDescription(WizardMessages.NewProject_referenceDescription);
            addPage(referencePage);
        }

    } catch (final Exception x) {
        reportError(x);
    }
}

From source file:com.torodb.torod.db.backends.converters.array.ValueToArrayConverterProvider.java

private ValueToArrayConverterProvider() {
    arrayConverter = new ArrayValueToJsonConverter();
    booleanConverter = new BooleanValueToJsonConverter();
    dateConverter = new DateValueToJsonConverter();
    dateTimeConverter = new DateTimeValueToJsonConverter();
    doubleConverter = new DoubleValueToJsonConverter();
    integerConverter = new IntegerValueToJsonConverter();
    longConverter = new LongValueToJsonConverter();
    nullConverter = new NullValueToJsonConverter();
    stringConverter = new StringValueToJsonConverter();
    timeConverter = new TimeValueToJsonConverter();
    twelveBytesConverter = new TwelveBytesToArrayConverter();
    posixPatterConverter = new PosixPatternValueToJsonConverter();

    converters = Maps.newEnumMap(BasicType.class);
    converters.put(BasicType.ARRAY, arrayConverter);
    converters.put(BasicType.BOOLEAN, booleanConverter);
    converters.put(BasicType.DATE, dateConverter);
    converters.put(BasicType.DATETIME, dateTimeConverter);
    converters.put(BasicType.DOUBLE, doubleConverter);
    converters.put(BasicType.INTEGER, integerConverter);
    converters.put(BasicType.LONG, longConverter);
    converters.put(BasicType.NULL, nullConverter);
    converters.put(BasicType.STRING, stringConverter);
    converters.put(BasicType.TIME, timeConverter);
    converters.put(BasicType.TWELVE_BYTES, twelveBytesConverter);
    converters.put(BasicType.PATTERN, posixPatterConverter);
}

From source file:org.apache.hadoop.hdfs.server.namenode.AclTransformation.java

/**
 * Filters (discards) any existing ACL entries that have the same scope, type
 * and name of any entry in the ACL spec.  If necessary, recalculates the mask
 * entries.  If necessary, default entries may be inferred by copying the
 * permissions of the corresponding access entries.  It is invalid to request
 * removal of the mask entry from an ACL that would otherwise require a mask
 * entry, due to existing named entries or an unnamed group entry.
 *
 * @param existingAcl List<AclEntry> existing ACL
 * @param inAclSpec List<AclEntry> ACL spec describing entries to filter
 * @return List<AclEntry> new ACL//from w  w  w .  j  av a  2  s.  c o m
 * @throws AclException if validation fails
 */
public static List<AclEntry> filterAclEntriesByAclSpec(List<AclEntry> existingAcl, List<AclEntry> inAclSpec)
        throws AclException {
    ValidatedAclSpec aclSpec = new ValidatedAclSpec(inAclSpec);
    ArrayList<AclEntry> aclBuilder = Lists.newArrayListWithCapacity(MAX_ENTRIES);
    EnumMap<AclEntryScope, AclEntry> providedMask = Maps.newEnumMap(AclEntryScope.class);
    EnumSet<AclEntryScope> maskDirty = EnumSet.noneOf(AclEntryScope.class);
    EnumSet<AclEntryScope> scopeDirty = EnumSet.noneOf(AclEntryScope.class);
    for (AclEntry existingEntry : existingAcl) {
        if (aclSpec.containsKey(existingEntry)) {
            scopeDirty.add(existingEntry.getScope());
            if (existingEntry.getType() == MASK) {
                maskDirty.add(existingEntry.getScope());
            }
        } else {
            if (existingEntry.getType() == MASK) {
                providedMask.put(existingEntry.getScope(), existingEntry);
            } else {
                aclBuilder.add(existingEntry);
            }
        }
    }
    copyDefaultsIfNeeded(aclBuilder);
    calculateMasks(aclBuilder, providedMask, maskDirty, scopeDirty);
    return buildAndValidateAcl(aclBuilder);
}

From source file:org.pircbotx.UserChannelDao.java

protected UserChannelDao(PircBotX bot, Configuration.BotFactory botFactory) {
    this.bot = bot;
    this.botFactory = botFactory;
    this.locale = bot.getConfiguration().getLocale();
    this.mainMap = new UserChannelMap<U, C>();
    this.userNickMap = Maps.newHashMap();
    this.channelNameMap = Maps.newHashMap();
    this.privateUsers = Maps.newHashMap();

    //Initialize levels map with a UserChannelMap for each level
    this.levelsMap = Maps.newEnumMap(UserLevel.class);
    for (UserLevel level : UserLevel.values())
        levelsMap.put(level, new UserChannelMap<U, C>());
}