Example usage for com.google.common.collect Multimap get

List of usage examples for com.google.common.collect Multimap get

Introduction

In this page you can find the example usage for com.google.common.collect Multimap get.

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:edu.isi.karma.modeling.research.ComputeGED.java

private static void computeGEDApp1() throws Exception {

    File ff = new File(Params.JGRAPHT_DIR);
    File[] files = ff.listFiles();

    DirectedWeightedMultigraph<Node, Link> gMain, gKarmaInitial, gKarmaFinal, gApp1Rank1, gApp1Rank2,
            gApp1Rank3;/*from   w  w w.j  a  va 2  s.c  o  m*/

    HashSet<File> fileSet = new HashSet<File>(Arrays.asList(files));

    Function<File, String> sameService = new Function<File, String>() {
        @Override
        public String apply(final File s) {
            return s.getName().substring(0, s.getName().indexOf('.'));
        }
    };

    Multimap<String, File> index = Multimaps.index(fileSet, sameService);

    for (String s : index.keySet()) {

        System.out.println(s);
        Collection<File> serviceFiles = index.get(s);
        gMain = null;
        gKarmaInitial = null;
        gKarmaFinal = null;
        gApp1Rank1 = null;
        gApp1Rank2 = null;
        gApp1Rank3 = null;

        for (File f : serviceFiles) {
            if (f.getName().endsWith(".main.jgraph")) {
                gMain = GraphUtil.deserialize(f.getPath());
            } else if (f.getName().endsWith(".karma.initial.jgraph")) {
                gKarmaInitial = GraphUtil.deserialize(f.getPath());
            } else if (f.getName().endsWith(".karma.final.jgraph")) {
                gKarmaFinal = GraphUtil.deserialize(f.getPath());
            } else if (f.getName().endsWith(".app1.rank1.jgraph")) {
                gApp1Rank1 = GraphUtil.deserialize(f.getPath());
            } else if (f.getName().endsWith(".app1.rank2.jgraph")) {
                gApp1Rank2 = GraphUtil.deserialize(f.getPath());
            } else if (f.getName().endsWith(".app1.rank3.jgraph")) {
                gApp1Rank3 = GraphUtil.deserialize(f.getPath());
            }
        }

        if (gMain == null)
            continue;
        String label;
        double distance;

        Map<String, DirectedWeightedMultigraph<Node, Link>> graphs = new TreeMap<String, DirectedWeightedMultigraph<Node, Link>>();

        label = "0- Main";
        graphs.put(label, gMain);

        if (gKarmaInitial != null) {
            distance = Util.getDistance(gMain, gKarmaInitial);
            label = "1-Karma Initial" + "-distance:" + distance;
            graphs.put(label, gKarmaInitial);
        }

        if (gKarmaFinal != null) {
            distance = Util.getDistance(gMain, gKarmaFinal);
            label = "3-Karma Final" + "-distance:" + distance;
            graphs.put(label, gKarmaFinal);
        }

        if (gApp1Rank1 != null) {
            distance = Util.getDistance(gMain, gApp1Rank1);
            label = "4-Rank1" + "-distance:" + distance;
            graphs.put(label, gApp1Rank1);
        }

        if (gApp1Rank2 != null) {
            distance = Util.getDistance(gMain, gApp1Rank2);
            label = "5-Rank2" + "-distance:" + distance;
            graphs.put(label, gApp1Rank2);
        }

        if (gApp1Rank3 != null) {
            distance = Util.getDistance(gMain, gApp1Rank3);
            label = "6-Rank3" + "-distance:" + distance;
            graphs.put(label, gApp1Rank3);
        }

        GraphVizUtil.exportJGraphToGraphvizFile(graphs, s, Params.OUTPUT_DIR + s + ".app1.out.dot");
    }
}

From source file:com.eucalyptus.vm.NetworkGroupsMetadata.java

private static String groupsToString(Multimap<String, String> networks) {
    StringBuilder buf = new StringBuilder();
    for (String networkName : networks.keySet()) {
        buf.append("GROUP ").append(networkName);
        for (String ip : networks.get(networkName)) {
            buf.append(" ").append(ip);
        }//from   w w  w  .  ja  v  a 2 s  .c  o m
        buf.append("\n");
    }
    return buf.toString();
}

From source file:org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorExtensions.java

/**
 * get a task editor extension for a specific task attribute
 * //from ww w  . ja  v  a2 s .c  om
 * @param taskRepository
 * @param taskAttribute
 * @return the extension, or null if there is none
 * @see #getTaskEditorExtension(TaskRepository);
 * @since 3.11
 */
public static AbstractTaskEditorExtension getTaskEditorExtension(TaskRepository taskRepository,
        TaskAttribute taskAttribute) {
    init();
    String input = taskAttribute.getMetaData().getMediaType();
    if (input != null) {
        try {
            MediaType media = MediaType.parse(input);
            Multimap<String, String> parameters = media.parameters();
            if (parameters.containsKey(MARKUP_KEY)) {
                Iterator<String> iter = parameters.get(MARKUP_KEY).iterator();
                String markup = iter.next();
                SortedSet<RegisteredTaskEditorExtension> extensions = getTaskEditorExtensions();
                for (RegisteredTaskEditorExtension extension : extensions) {
                    if (markup.equals(extension.getName())) {
                        return extension.getExtension();
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
                    String.format("Unable to parse markup type for attribute %s", taskAttribute.toString()), //$NON-NLS-1$
                    e));
        }
    }
    return getTaskEditorExtension(taskRepository);
}

From source file:mx.bigdata.jcalais.rest.CalaisRestClient.java

public static CalaisResponse processResponse(Map<String, Object> map, final String payload) {
    Map<String, Object> doc = (Map<String, Object>) map.remove("doc");
    final CalaisObject info = extractObject(doc, "info");
    final CalaisObject meta = extractObject(doc, "meta");
    Multimap<String, CalaisObject> hierarchy = createHierarchy(map);
    final Iterable<CalaisObject> topics = Iterables.unmodifiableIterable(hierarchy.get("topics"));
    final Iterable<CalaisObject> entities = Iterables.unmodifiableIterable(hierarchy.get("entities"));
    final Iterable<CalaisObject> relations = Iterables.unmodifiableIterable(hierarchy.get("relations"));
    final Iterable<CalaisObject> socialTags = Iterables.unmodifiableIterable(hierarchy.get("socialTag"));
    return new CalaisResponse() {
        public CalaisObject getInfo() {
            return info;
        }/*from ww w. j a  va  2s. c om*/

        public CalaisObject getMeta() {
            return meta;
        }

        public Iterable<CalaisObject> getTopics() {
            return topics;
        }

        public Iterable<CalaisObject> getEntities() {
            return entities;
        }

        public Iterable<CalaisObject> getRelations() {
            return relations;
        }

        public Iterable<CalaisObject> getSocialTags() {
            return socialTags;
        }

        public String getPayload() {
            return payload;
        }
    };
}

From source file:net.minecraftforge.common.config.ConfigManager.java

public static void load(String modid, Config.Type type) {
    FMLLog.fine("Attempting to inject @Config classes into %s for type %s", modid, type);
    ClassLoader mcl = Loader.instance().getModClassLoader();
    File configDir = Loader.instance().getConfigDir();
    Multimap<Config.Type, ASMData> map = asm_data.get(modid);

    if (map == null)
        return;/*from  w  w  w . ja v a 2  s  .  c  o m*/

    for (ASMData targ : map.get(type)) {
        try {
            Class<?> cls = Class.forName(targ.getClassName(), true, mcl);
            String name = (String) targ.getAnnotationInfo().get("name");
            if (name == null)
                name = modid;
            File file = new File(configDir, name + ".cfg");

            Configuration cfg = CONFIGS.get(file.getAbsolutePath());
            if (cfg == null) {
                cfg = new Configuration(file);
                cfg.load();
                CONFIGS.put(file.getAbsolutePath(), cfg);
            }

            createConfig(cfg, cls, modid, type == Config.Type.INSTANCE);

            cfg.save();

        } catch (Exception e) {
            FMLLog.log(Level.ERROR, e, "An error occurred trying to load a config for %s into %s", modid,
                    targ.getClassName());
            throw new LoaderException(e);
        }
    }
}

From source file:scoutdoc.main.check.CheckstyleFileWriter.java

public static void write(List<Check> list, PrintWriter w) {
    w.println(XML_VERSION);//w ww  . j  a  v a2s .co  m
    w.println(CHECKSTYLE_OPEN);

    Multimap<String, Check> multimap = ArrayListMultimap.create();

    for (Check check : list) {
        String filePath = PageUtility.toFile(check.getPage()).getAbsolutePath();
        multimap.put(filePath, check);
    }

    for (String file : multimap.keySet()) {
        w.println("<file name=\"" + file + "\">");
        for (Check check : multimap.get(file)) {
            w.print("<error");
            w.print(" line=\"" + check.getLine() + "\"");
            w.print(" column=\"" + check.getColumn() + "\"");
            w.print(" severity=\"" + Objects.firstNonNull(check.getSeverity(), "") + "\"");
            w.print(" message=\"" + Strings.nullToEmpty(check.getMessage()) + "\"");
            w.print(" source=\"" + Strings.nullToEmpty(check.getSource()) + "\"");
            w.println("/>");
        }
        w.println(FILE_CLOSE);
    }
    w.println(CHECKSTYLE_CLOSE);
}

From source file:it.osm.gtfs.command.GTFSGenerateRoutesGPXs.java

public static void run() throws IOException, ParserConfigurationException, SAXException {
    Map<String, Stop> osmstops = OSMParser.applyGTFSIndex(OSMParser
            .readOSMStops(GTFSImportSetting.getInstance().getOSMPath() + GTFSImportSetting.OSM_STOP_FILE_NAME));
    Map<String, Route> routes = GTFSParser.readRoutes(
            GTFSImportSetting.getInstance().getGTFSPath() + GTFSImportSetting.GTFS_ROUTES_FILE_NAME);
    Map<String, Shape> shapes = GTFSParser.readShapes(
            GTFSImportSetting.getInstance().getGTFSPath() + GTFSImportSetting.GTFS_SHAPES_FILE_NAME);
    Map<String, StopsList> stopTimes = GTFSParser.readStopTimes(
            GTFSImportSetting.getInstance().getGTFSPath() + GTFSImportSetting.GTFS_STOP_TIME_FILE_NAME,
            osmstops);//  w w w . jav a2 s . c  o m
    List<Trip> trips = GTFSParser.readTrips(
            GTFSImportSetting.getInstance().getGTFSPath() + GTFSImportSetting.GTFS_TRIPS_FILE_NAME, routes,
            new HashMap<String, StopsList>());

    //sorting set
    Multimap<String, Trip> grouppedTrips = GTFSParser.groupTrip(trips, routes, stopTimes);
    Set<String> keys = new TreeSet<String>(grouppedTrips.keySet());

    new File(GTFSImportSetting.getInstance().getOutputPath() + "gpx").mkdirs();

    int id = 10000;
    for (String k : keys) {
        Collection<Trip> allTrips = grouppedTrips.get(k);
        Set<Trip> uniqueTrips = new HashSet<Trip>(allTrips);

        for (Trip trip : uniqueTrips) {
            Route r = routes.get(trip.getRoute().getId());
            Shape s = shapes.get(trip.getShapeID());

            FileOutputStream f = new FileOutputStream(GTFSImportSetting.getInstance().getOutputPath() + "/gpx/r"
                    + id++ + " " + r.getShortName().replace("/", "B") + " " + trip.getName().replace("/", "_")
                    + ".gpx");
            f.write(s.getGPX(r.getShortName()).getBytes());
            f.close();
        }
    }
}

From source file:org.jclouds.http.utils.ModifyRequest.java

@SuppressWarnings("unchecked")
public static <R extends HttpRequest> R replaceHeaders(R request, Multimap<String, String> headers) {
    Multimap<String, String> newHeaders = LinkedHashMultimap
            .create(checkNotNull(request, "request").getHeaders());
    for (String header : headers.keySet())
        newHeaders.replaceValues(header, headers.get(header));
    return (R) request.toBuilder().headers(newHeaders).build();
}

From source file:com.zimbra.cs.account.accesscontrol.ACLUtil.java

/**
 * Returns {@link UserRights#R_sendOnBehalfOf} rights granted to the grantee.
 *///from   w w w . java 2  s  .co m
public static List<Identity> getSendOnBehalfOf(Account grantee) throws ServiceException {
    Multimap<Right, Entry> rights = getGrantedRights(grantee,
            Collections.singleton(Provisioning.A_displayName));
    ImmutableList.Builder<Identity> result = ImmutableList.<Identity>builder();
    for (Entry entry : rights.get(UserRights.R_sendOnBehalfOf)) {
        Account grantor = (Account) entry;
        String mail = grantor.getName();
        String name = Objects.firstNonNull(grantor.getDisplayName(), mail);
        Map<String, Object> attrs = ImmutableMap.<String, Object>builder()
                .put(Provisioning.A_zimbraPrefIdentityId, grantor.getId())
                .put(Provisioning.A_zimbraPrefIdentityName, name)
                .put(Provisioning.A_zimbraPrefFromDisplay, name).put(Provisioning.A_zimbraPrefFromAddress, mail)
                .put(Provisioning.A_objectClass, AttributeClass.OC_zimbraAclTarget).build();
        result.add(new Identity(grantee, name, grantor.getId(), attrs, grantee.getProvisioning()));
    }
    return result.build();
}

From source file:eu.tomylobo.routes.util.Ini.java

public static Location loadLocation(Multimap<String, String> section, String format, boolean withYawPitch) {
    try {//  www  .  j  a v  a  2 s. c  o  m
        if (withYawPitch) {
            return new Location(loadWorld(section, format), loadVector(section, format),
                    getOnlyFloat(section.get(String.format(format, "yaw"))),
                    getOnlyFloat(section.get(String.format(format, "pitch"))));
        } else {
            return new Location(loadWorld(section, format), loadVector(section, format), 0, 0);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}