Example usage for com.google.common.collect Ordering explicit

List of usage examples for com.google.common.collect Ordering explicit

Introduction

In this page you can find the example usage for com.google.common.collect Ordering explicit.

Prototype

@GwtCompatible(serializable = true)
public static <T> Ordering<T> explicit(List<T> valuesInOrder) 

Source Link

Document

Returns an ordering that compares objects according to the order in which they appear in the given list.

Usage

From source file:com.eviware.loadui.ui.fx.util.ExplicitOrdering.java

public ExplicitOrdering() {
    elementsInOrder.addListener(new InvalidationListener() {
        @Override//from   ww w .  jav a 2  s . co m
        public void invalidated(Observable arg0) {
            ordering = Ordering.explicit(elementsInOrder);
        }
    });
}

From source file:com.eviware.loadui.util.collections.SafeExplicitOrdering.java

private SafeExplicitOrdering(List<T> items) {
    itemsInOrder = ImmutableList.copyOf(items);
    explicit = Ordering.explicit(items);
}

From source file:net.oneandone.maven.plugins.cycles.graph.FeedbackArcSet.java

private static <V, E> Ordering<V> vertexOrdering(DirectedGraph<V, E> graph,
        VertexEvaluator<V, DirectedGraph<V, E>> evaluator) {
    List<V> front = Lists.newLinkedList();
    List<V> back = Lists.newLinkedList();

    // FIXME: there must be an easier way to clone a graph
    DirectedGraph<V, E> g = FilterUtils.createInducedSubgraph(graph.getVertices(), graph);

    while (!g.getVertices().isEmpty()) {
        collectSinks(g, back);/* w  ww.j av  a2s  .  c o  m*/
        collectSources(g, front);
        collectMaxDelta(g, front, evaluator);
    }

    return Ordering.explicit(Lists.newArrayList(Iterables.concat(front, back)));
}

From source file:io.prestosql.execution.scheduler.AllAtOnceExecutionSchedule.java

public AllAtOnceExecutionSchedule(Collection<SqlStageExecution> stages) {
    requireNonNull(stages, "stages is null");
    List<PlanFragmentId> preferredScheduleOrder = getPreferredScheduleOrder(
            stages.stream().map(SqlStageExecution::getFragment).collect(toImmutableList()));

    Ordering<SqlStageExecution> ordering = Ordering.explicit(preferredScheduleOrder)
            .onResultOf(PlanFragment::getId).onResultOf(SqlStageExecution::getFragment);
    schedulingStages = new LinkedHashSet<>(ordering.sortedCopy(stages));
}

From source file:org.spka.cursus.publish.website.results.ResultsPagesGenerator.java

public ResultsPagesGenerator(File scoresFile) throws IOException, ImportException, ExportException {
    ScoresXMLFile scores = new TransformResults(Files.asByteSource(scoresFile));
    XSLTHTMLGenerator gen = new XSLTHTMLGenerator(Constants.DATA_FILE_PREFIX + scoresFile.getName(),
            Files.getNameWithoutExtension(scoresFile.getName()), scores);

    gen.getFooters().add("footer.xml");
    gen.getStyleSheets().add("spka.css");
    if (scores.getData().getSeries().getName().startsWith("Celtic Challenge ")) {
        gen.getStyleSheets().add("spka-cc.css");
    }/* www  .  j a  v a  2 s.c  om*/
    gen.getFlags().put("compact-race", "10");
    gen.getFlags().put("compact-event", "10");
    if (Constants.TOP_COUNTRY_SCORERS.contains(scores.getData().getSeriesResults().getScorer())) {
        gen.getFlags().put("top-country", null);
    }

    Map<String, String> classes = new TreeMap<String, String>(
            Ordering.explicit(new ArrayList<String>(CLASSES.keySet())));
    for (DataXMLClass class_ : scores.getData().getSeries().getClasses()) {
        if (CLASSES.containsKey(class_.getName())) {
            classes.put(class_.getName(), CLASSES.get(class_.getName()));
        }
    }
    gen.getClasses().putAll(classes);

    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    scores.to(buf);
    buf.close();
    pages.put(Constants.RESULTS_DIR + "/" + Constants.DATA_FILE_PREFIX + scoresFile.getName(),
            ByteSource.wrap(buf.toByteArray()));

    for (String styleSheet : gen.getStyleSheets()) {
        pages.put(Constants.RESULTS_DIR + "/" + styleSheet,
                Resources.asByteSource(Resources.getResource(Constants.RESOURCE_PATH + styleSheet)));
    }

    for (Map.Entry<String, ByteSource> page : Iterables.concat(gen.getMenuPage().entrySet(),
            gen.getSimplePage().entrySet(), gen.getSplitPages().entrySet(), gen.getCodePages().entrySet())) {
        pages.put(Constants.RESULTS_DIR + "/" + page.getKey(), page.getValue());
    }
}

From source file:de.iteratec.iteraplan.persistence.dao.RangeValueDAOImpl.java

/** {@inheritDoc} */
public List<RangeValue> reload(Collection<RangeValue> identifiers) {
    if ((identifiers == null) || identifiers.isEmpty()) {
        return new ArrayList<RangeValue>(0);
    }//from w  w  w  . jav  a2  s.c  om

    EntityToIdFunction<RangeValue, Integer> toIdFunction = new EntityToIdFunction<RangeValue, Integer>();
    Iterable<Integer> transform = Iterables.transform(identifiers, toIdFunction);

    List<RangeValue> loadElementListWithIds = loadElementListWithIds(Sets.newHashSet(transform));
    Collections.sort(loadElementListWithIds, Ordering.explicit(Lists.newArrayList(identifiers)));

    return loadElementListWithIds;
}

From source file:net.shibboleth.idp.consent.logic.impl.PreferExplicitOrderComparator.java

/**
 * Constructor.//from w  w  w  .j  av a2s  . c  o m
 * 
 * @param order the desired order, null and empty strings are ignored, duplicates are removed
 */
public PreferExplicitOrderComparator(@Nullable @NullableElements final List<String> order) {
    if (order == null) {
        explicitOrder = Collections.emptyList();
    } else {
        // trimmed
        explicitOrder = Lists.transform(order, TrimOrNullStringFunction.INSTANCE);

        // non-null
        explicitOrder = ImmutableList.copyOf(Iterables.filter(explicitOrder, Predicates.notNull()));

        // no duplicates
        explicitOrder = ImmutableSet.copyOf(explicitOrder).asList();

        explicitOrdering = Ordering.explicit(explicitOrder);
    }
}

From source file:XFactHD.thermalreactors.ThermalReactors.java

private static void initTabSorter() {
    List<Item> order = Arrays.asList(Item.getItemFromBlock(TRContent.blockOre),
            Item.getItemFromBlock(TRContent.blockBuilding), Item.getItemFromBlock(TRContent.blockConcrete),
            TRContent.itemSteamBucket, TRContent.itemMaterial, TRContent.itemFusionCell,
            TRContent.itemFuelRodUranium, TRContent.itemFuelRodMOX, TRContent.itemTRAugment,
            TRContent.itemRadHelmet, TRContent.itemRadChestplate, TRContent.itemRadPants,
            TRContent.itemRadBoots, Item.getItemFromBlock(TRContent.blockReactorComponent),
            Item.getItemFromBlock(TRContent.blockTurbineComponent), TRContent.itemTurbineBlade,
            /*Item.getItemFromBlock(TRContent.blockFusionComponent),*/ Item
                    .getItemFromBlock(TRContent.blockRFHandler));
    tabSorter = Ordering.explicit(order).onResultOf(new Function<ItemStack, Item>() {
        @Override/*w  w w .  ja  v a 2s  . com*/
        public Item apply(ItemStack input) {
            return input.getItem();
        }
    });
}

From source file:org.apache.aurora.scheduler.base.Tasks.java

/**
 * Get the latest active task or the latest inactive task if no active task exists.
 *
 * @param tasks a collection of tasks/*from   www . ja va2 s .  co m*/
 * @return the task that transitioned most recently.
 */
public static IScheduledTask getLatestActiveTask(Iterable<IScheduledTask> tasks) {
    Preconditions.checkArgument(Iterables.size(tasks) != 0);

    return Ordering.explicit(ORDERED_TASK_STATUSES).onResultOf(IScheduledTask::getStatus)
            .compound(LATEST_ACTIVITY).max(tasks);
}

From source file:org.sonar.server.setting.ws.SettingsFinder.java

/**
 * Return list of settings by component uuid, sorted from project to lowest module
 *///from  ww  w.  j  a  va  2 s.c om
public Multimap<String, Setting> loadComponentSettings(DbSession dbSession, Set<String> keys,
        ComponentDto component) {
    List<String> componentUuids = DOT_SPLITTER.splitToList(component.moduleUuidPath());
    List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, componentUuids);
    Set<Long> componentIds = componentDtos.stream().map(ComponentDto::getId).collect(Collectors.toSet());
    Map<Long, String> uuidsById = componentDtos.stream()
            .collect(Collectors.toMap(ComponentDto::getId, ComponentDto::uuid));
    List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession,
            keys, componentIds);
    List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession,
            getPropertySetKeys(properties), componentIds);

    Multimap<String, Setting> settingsByUuid = TreeMultimap.create(Ordering.explicit(componentUuids),
            Ordering.arbitrary());
    for (PropertyDto propertyDto : properties) {
        Long componentId = propertyDto.getResourceId();
        String componentUuid = uuidsById.get(componentId);
        String propertyKey = propertyDto.getKey();
        settingsByUuid.put(componentUuid, Setting.createFromDto(propertyDto,
                getPropertySets(propertyKey, propertySets, componentId), definitions.get(propertyKey)));
    }
    return settingsByUuid;
}