Java Code Examples for com.google.inject.Provider#get()

The following examples show how to use com.google.inject.Provider#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TSOForHBaseCompactorTestModule.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Provides
PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
    PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
        persistenceProcessorHandlers[i] = provider.get();
    }
    return persistenceProcessorHandlers;
}
 
Example 2
Source File: RenameLinkedMode.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public boolean start(IRenameElementContext renameElementContext, Provider<LinkedPositionGroup> provider, IProgressMonitor monitor) {
	if (renameElementContext == null)
		throw new IllegalArgumentException("RenameElementContext is null");
	this.linkedPositionGroup = provider.get();
	if (linkedPositionGroup == null || linkedPositionGroup.isEmpty())
		return false;
	this.editor = (XtextEditor) renameElementContext.getTriggeringEditor();
	this.focusEditingSupport = new FocusEditingSupport();
	ISourceViewer viewer = editor.getInternalSourceViewer();
	IDocument document = viewer.getDocument();
	originalSelection = viewer.getSelectedRange();
	currentPosition = linkedPositionGroup.getPositions()[0];
	originalName = getCurrentName();
	try {
		linkedModeModel = new LinkedModeModel();
		linkedModeModel.addGroup(linkedPositionGroup);
		linkedModeModel.forceInstall();
		linkedModeModel.addLinkingListener(new EditorSynchronizer());
		LinkedModeUI ui = new EditorLinkedModeUI(linkedModeModel, viewer);
		ui.setExitPolicy(new ExitPolicy(document));
		if (currentPosition.includes(originalSelection.x))
			ui.setExitPosition(viewer, originalSelection.x, 0, Integer.MAX_VALUE);
		ui.enter();
		if (currentPosition.includes(originalSelection.x)
				&& currentPosition.includes(originalSelection.x + originalSelection.y))
			viewer.setSelectedRange(originalSelection.x, originalSelection.y);
		if (viewer instanceof IEditingSupportRegistry) {
			IEditingSupportRegistry registry = (IEditingSupportRegistry) viewer;
			registry.register(focusEditingSupport);
		}
		openPopup();
		return true;
	} catch (BadLocationException e) {
		throw new WrappedException(e);
	}
}
 
Example 3
Source File: DocumentBasedDirtyResource.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.8
 * @nooverride This method is not intended to be re-implemented or extended by clients.
 * @noreference This method is not intended to be referenced by clients.
 */
@Override
public ResourceStorageLoadable getResourceStorageLoadable() {
	Provider<ResourceStorageLoadable> provider = this.storageAwareResourceInputStreamProvider;
	if (provider == null)
		return null;
	return provider.get();
}
 
Example 4
Source File: FocusFeedbackPart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the {@link Color} that is used to stroke focus feedback.
 *
 * @return The {@link Color} that is used to stroke focus feedback.
 */
@SuppressWarnings("serial")
protected Color getFocusStroke() {
	Provider<Color> focusFeedbackColorProvider = getViewer()
			.getAdapter(AdapterKey.get(new TypeToken<Provider<Color>>() {
			}, DefaultFocusFeedbackPartFactory.FOCUS_FEEDBACK_COLOR_PROVIDER));
	return focusFeedbackColorProvider == null
			? DefaultFocusFeedbackPartFactory.DEFAULT_FOCUS_FEEDBACK_COLOR
			: focusFeedbackColorProvider.get();
}
 
Example 5
Source File: CreationMenuOnClickHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the {@link Color} that is used to stroke hover feedback.
 *
 * @return The {@link Color} that is used to stroke hover feedback.
 */
@SuppressWarnings("serial")
protected Color getHighlightColor() {
	Provider<Color> hoverFeedbackColorProvider = getViewer()
			.getAdapter(AdapterKey.get(new TypeToken<Provider<Color>>() {
			}, DefaultHoverFeedbackPartFactory.HOVER_FEEDBACK_COLOR_PROVIDER));
	return hoverFeedbackColorProvider == null ? DefaultHoverFeedbackPartFactory.DEFAULT_HOVER_FEEDBACK_COLOR
			: hoverFeedbackColorProvider.get();
}
 
Example 6
Source File: SelectionFeedbackPart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the primary selection {@link Color}.
 *
 * @return The primary selection {@link Color}.
 */
protected Color getSecondarySelectionColor() {
	@SuppressWarnings("serial")
	Provider<Color> connectedColorProvider = getViewer()
			.getAdapter(AdapterKey.get(new TypeToken<Provider<Color>>() {
			}, DefaultSelectionFeedbackPartFactory.SECONDARY_SELECTION_FEEDBACK_COLOR_PROVIDER));
	return connectedColorProvider == null
			? DefaultSelectionFeedbackPartFactory.DEFAULT_SECONDARY_SELECTION_FEEDBACK_COLOR
			: connectedColorProvider.get();
}
 
Example 7
Source File: AbstractSegmentHandlePart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the {@link Color} that is used to fill insertion handles.
 *
 * @return The {@link Color} that is used to fill insertion handles.
 */
protected Color getInsertFill() {
	@SuppressWarnings("serial")
	Provider<Color> connectedColorProvider = getViewer()
			.getAdapter(AdapterKey.get(new TypeToken<Provider<Color>>() {
			}, DefaultSelectionHandlePartFactory.INSERT_HANDLE_COLOR_PROVIDER));
	return connectedColorProvider == null
			? DefaultSelectionHandlePartFactory.DEFAULT_INSERT_HANDLE_COLOR
			: connectedColorProvider.get();
}
 
Example 8
Source File: TestAdminHttpJsonRequestFactory.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public TestAdminHttpJsonRequestFactory(
    Provider<TestAuthServiceClient> authServiceClientProvider,
    @Named("codenvy.admin.name") String adminName,
    @Named("codenvy.admin.password") String adminPassword) {
  super(authServiceClientProvider.get(), adminName, adminPassword);
}
 
Example 9
Source File: DataStoreModule.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton
DataStore provideDataStore(@LocalDataStore Provider<DataStore> localDataStoreProvider,
                           @SystemDataStore Provider<DataStore> systemDataStoreProvider,
                           DataCenterConfiguration dataCenterConfiguration) {
    // Provides the unannotated version of the DataStore
    // If this is the system data center, return the local DataStore implementation
    // Otherwise return a proxy that delegates to local or remote system DataStores
    if (dataCenterConfiguration.isSystemDataCenter()) {
        return localDataStoreProvider.get();
    } else {
        return new DataStoreProviderProxy(localDataStoreProvider, systemDataStoreProvider);
    }
}
 
Example 10
Source File: DefaultModule.java    From bromium with MIT License 5 votes vote down vote up
@CheckedProvides(IOProvider.class)
public RequestFilter getRequestFilter(@Named(COMMAND) String command,
                                      IOProvider<List<EventDetector>> eventDetectorListProvider,
                                      Provider<RecordingState> recordingStateProvider,
                                      Provider<ReplayingState> replayingStateProvider,
                                      Provider<List<ConditionsUpdater>> conditionsUpdaters) throws IOException {
    switch (command) {
        case RECORD:
            return new RecordRequestFilter(recordingStateProvider.get(), eventDetectorListProvider.get());
        case REPLAY:
            return new ReplayRequestFilter(replayingStateProvider.get(), conditionsUpdaters.get());
        default:
            throw new NoSuchCommandException();
    }
}
 
Example 11
Source File: PooledSolver.java    From opt4j with MIT License 5 votes vote down vote up
/**
 * Constructs a {@link PooledSolver}.
 * 
 * @param solverProvider
 *            a solver provider
 * @param instances
 *            the number of pooled instances
 */
@Inject
public PooledSolver(@Constant(value = "solver", namespace = PooledSolver.class) Provider<Solver> solverProvider,
		@Constant(value = "instances", namespace = PooledSolver.class) int instances) {
	for (int i = 0; i < instances; i++) {
		Solver solver = solverProvider.get();
		solvers.add(solver);
		queue.add(solver);
	}
}
 
Example 12
Source File: AbstractArchiveOptimalityTester.java    From opt4j with MIT License 5 votes vote down vote up
/**
 * Initializes the {@link Archive} with NUMBER_OF_INDIVIDUALS different
 * {@link Individual}s.
 * <p>
 * Therefore. three {@link Objective}s are added:
 * <ul>
 * <li>the first dimension is incremented</li>
 * <li>the second dimension is decremented</li>
 * <li>the third dimension is set randomly with a static seed.</li>
 * </ul>
 * 
 * @param injector
 *            the injector
 * @param archive
 *            the archive under test
 */
private void fillArchive(Injector injector, Archive archive) {
	Random r = new Random(100);
	Provider<Individual> individuals = injector.getProvider(Individual.class);

	first = null;
	last = null;
	randMin = null;
	int smallestRand = Integer.MAX_VALUE;
	for (int i = 0; i < NUMBER_OF_INDIVUDUALS; i++) {
		Individual individual = individuals.get();
		Objectives o = new Objectives();
		o.add(o1, i);
		o.add(o2, -i);
		int randomValue = r.nextInt(Integer.MAX_VALUE);
		o.add(o3, randomValue);
		individual.setObjectives(o);
		archive.update(individual);

		if (i == 0) {
			first = individual;
		}
		if (i == NUMBER_OF_INDIVUDUALS - 1) {
			last = individual;
		}
		if (randomValue < smallestRand) {
			randMin = individual;
			smallestRand = randomValue;
		}
	}
}
 
Example 13
Source File: LinStorScope.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public <T> Provider<T> scope(final Key<T> key, final Provider<T> unscoped)
{
    return new Provider<T>()
    {
        @SuppressWarnings("unchecked")
        @Override
        public T get()
        {
            Map<Key<?>, Object> scopedObjects = getScopedObjectMap(key);

            T current = null;
            if (scopedObjects != null)
            {
                current = (T) scopedObjects.get(key);
                if (current == null && !scopedObjects.containsKey(key))
                {
                    current = unscoped.get();

                    // don't remember proxies; these exist only to serve circular dependencies
                    if (!Scopes.isCircularProxy(current))
                    {
                        scopedObjects.put(key, current);
                    }
                }
            }
            return current;
        }
    };
}
 
Example 14
Source File: DefaultHoverIntentHandlePartFactory.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates hover handle parts for a handle geometry that is an
 * {@link IShape} but not a {@link Rectangle}.
 *
 * @param target
 *            The target {@link IVisualPart} for which handles are to be
 *            created.
 * @param contextMap
 *            A map in which the state-less context {@link IBehavior}) may
 *            place additional context information for the creation process.
 *            It may either directly contain additional information needed
 *            by the {@link IHandlePartFactory}, or may be passed back by
 *            the {@link IHandlePartFactory} to the calling context
 *            {@link IBehavior} to query such kind of information (in which
 *            case it will allow the context {@link IBehavior} to identify
 *            the creation context).
 * @param segmentsProvider
 *            A provider for the segments of the handle geometry for which
 *            handles are to be created.
 * @return A list of {@link IHandlePart}s that can be used to manipulate the
 *         given targets.
 */
protected List<IHandlePart<? extends Node>> createHoverHandlePartsForPolygonalOutline(
		IVisualPart<? extends Node> target, Map<Object, Object> contextMap,
		Provider<BezierCurve[]> segmentsProvider) {
	List<IHandlePart<? extends Node>> handleParts = new ArrayList<>();
	BezierCurve[] segments = segmentsProvider.get();
	for (int i = 0; i < segments.length; i++) {
		CircleSegmentHandlePart part = injector
				.getInstance(CircleSegmentHandlePart.class);
		part.setSegmentsProvider(segmentsProvider);
		part.setSegmentIndex(i);
		part.setSegmentParameter(0);
		handleParts.add(part);
	}
	return handleParts;
}
 
Example 15
Source File: DefaultHoverIntentHandlePartFactory.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public List<IHandlePart<? extends Node>> createHandleParts(
		List<? extends IVisualPart<? extends Node>> targets,
		Map<Object, Object> contextMap) {
	// check that we have targets
	if (targets == null || targets.isEmpty()) {
		throw new IllegalArgumentException(
				"Part factory is called without targets.");
	}
	// check that only one part is hovered at a time
	if (targets.size() > 1) {
		throw new IllegalStateException(
				"Cannot create hover handles for more than one target.");
	}

	final IVisualPart<? extends Node> target = targets.get(0);

	// handle geometry is in target visual local coordinate space.
	@SuppressWarnings("serial")
	final Provider<? extends IGeometry> hoverHandlesGeometryInTargetLocalProvider = target
			.getAdapter(AdapterKey
					.get(new TypeToken<Provider<? extends IGeometry>>() {
					}, HOVER_INTENT_HANDLES_GEOMETRY_PROVIDER));

	// generate handles from selection handles geometry
	IGeometry hoverHandlesGeometry = (hoverHandlesGeometryInTargetLocalProvider != null)
			? hoverHandlesGeometryInTargetLocalProvider.get() : null;
	if (hoverHandlesGeometry == null) {
		return Collections.emptyList();
	}

	// we will need a provider that returns the geometry in scene
	// coordinates
	final Provider<? extends IGeometry> hoverHandlesGeometryInSceneProvider = new Provider<IGeometry>() {
		@Override
		public IGeometry get() {
			return NodeUtils.localToScene(target.getVisual(),
					hoverHandlesGeometryInTargetLocalProvider.get());
		}
	};

	// the handle parts are located based on the segments of the handle
	// geometry
	Provider<BezierCurve[]> hoverHandlesSegmentsInSceneProvider = new Provider<BezierCurve[]>() {
		@Override
		public BezierCurve[] get() {
			IGeometry handleGeometry = hoverHandlesGeometryInSceneProvider
					.get();
			if (handleGeometry instanceof IShape) {
				List<BezierCurve> segments = new ArrayList<>();
				for (ICurve os : ((IShape) handleGeometry)
						.getOutlineSegments()) {
					segments.addAll(Arrays.asList(os.toBezier()));
				}
				return segments.toArray(new BezierCurve[] {});
			} else if (handleGeometry instanceof ICurve) {
				return ((ICurve) handleGeometry).toBezier();
			} else {
				throw new IllegalStateException(
						"Unable to determine handle position: Expected IShape or ICurve but got: "
								+ handleGeometry);
			}
		}
	};

	if (hoverHandlesGeometry instanceof ICurve) {
		// create curve handles
		return createHoverHandlePartsForCurve(target, contextMap,
				hoverHandlesSegmentsInSceneProvider);
	} else if (hoverHandlesGeometry instanceof IShape) {
		if (hoverHandlesGeometry instanceof Rectangle) {
			// create box handles
			return createHoverHandlePartsForRectangularOutline(target,
					contextMap, hoverHandlesSegmentsInSceneProvider);
		} else {
			// create segment handles (based on outline)
			return createHoverHandlePartsForPolygonalOutline(target,
					contextMap, hoverHandlesSegmentsInSceneProvider);
		}
	} else {
		throw new IllegalStateException(
				"Unable to generate handles for this handle geometry. Expected ICurve or IShape, but got: "
						+ hoverHandlesGeometry);
	}
}
 
Example 16
Source File: ClosureClient.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public <T> T useProvider(Provider<T> provider) {
	return provider.get();
}
 
Example 17
Source File: ClosureClient.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public <T> T useProvider(Provider<T> provider) {
	return provider.get();
}
 
Example 18
Source File: DefaultSelectionHandlePartFactory.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates handle parts for a single selection of which the handle geometry
 * is a {@link Rectangle}.
 *
 * @param target
 *            The target {@link IVisualPart} for which handles are to be
 *            created.
 * @param contextMap
 *            A map in which the state-less context {@link IBehavior}) may
 *            place additional context information for the creation process.
 *            It may either directly contain additional information needed
 *            by the {@link IHandlePartFactory}, or may be passed back by
 *            the {@link IHandlePartFactory} to the calling context
 *            {@link IBehavior} to query such kind of information (in which
 *            case it will allow the context {@link IBehavior} to identify
 *            the creation context).
 * @param segmentsProvider
 *            A provider for the segments of the handle geometry for which
 *            handles are to be created.
 * @return A list of {@link IHandlePart}s that can be used to manipulate the
 *         given targets.
 */
protected List<IHandlePart<? extends Node>> createSingleSelectionHandlePartsForRectangularOutline(
		IVisualPart<? extends Node> target, Map<Object, Object> contextMap,
		Provider<BezierCurve[]> segmentsProvider) {
	List<IHandlePart<? extends Node>> hps = new ArrayList<>();
	BezierCurve[] segments = segmentsProvider.get();
	for (int i = 0; i < segments.length; i++) {
		SquareSegmentHandlePart part = injector
				.getInstance(SquareSegmentHandlePart.class);
		part.setSegmentsProvider(segmentsProvider);
		part.setSegmentIndex(i);
		part.setSegmentParameter(0);
		hps.add(part);
	}
	return hps;
}
 
Example 19
Source File: DefaultSelectionHandlePartFactory.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates handle parts for a single selection.
 *
 * @param target
 *            The target {@link IVisualPart} for which handles are to be
 *            created.
 * @param contextMap
 *            A map in which the state-less context {@link IBehavior}) may
 *            place additional context information for the creation process.
 *            It may either directly contain additional information needed
 *            by the {@link IHandlePartFactory}, or may be passed back by
 *            the {@link IHandlePartFactory} to the calling context
 *            {@link IBehavior} to query such kind of information (in which
 *            case it will allow the context {@link IBehavior} to identify
 *            the creation context).
 * @return A list of {@link IHandlePart}s that can be used to manipulate the
 *         given targets.
 */
@SuppressWarnings("serial")
protected List<IHandlePart<? extends Node>> createSingleSelectionHandleParts(
		final IVisualPart<? extends Node> target,
		Map<Object, Object> contextMap) {
	// determine handle geometry (in target visual local coordinates)
	final Provider<? extends IGeometry> selectionHandlesGeometryInTargetLocalProvider = target
			.getAdapter(AdapterKey
					.get(new TypeToken<Provider<? extends IGeometry>>() {
					}, SELECTION_HANDLES_GEOMETRY_PROVIDER));
	IGeometry selectionHandlesGeometry = (selectionHandlesGeometryInTargetLocalProvider != null)
			? selectionHandlesGeometryInTargetLocalProvider.get() : null;
	if (selectionHandlesGeometry == null) {
		return Collections.emptyList();
	}

	// create provider that returns the geometry in scene coordinates
	final Provider<IGeometry> selectionHandlesGeometryInSceneProvider = new Provider<IGeometry>() {
		@Override
		public IGeometry get() {
			return NodeUtils.localToScene(target.getVisual(),
					selectionHandlesGeometryInTargetLocalProvider.get());
		}
	};
	Provider<BezierCurve[]> selectionHandlesSegmentsInSceneProvider = createSegmentsProvider(
			selectionHandlesGeometryInSceneProvider);

	if (selectionHandlesGeometry instanceof ICurve) {
		// create curve handles
		return createSingleSelectionHandlePartsForCurve(target, contextMap,
				selectionHandlesSegmentsInSceneProvider);
	} else if (selectionHandlesGeometry instanceof IShape) {
		if (selectionHandlesGeometry instanceof Rectangle) {
			// create box handles
			return createSingleSelectionHandlePartsForRectangularOutline(
					target, contextMap,
					selectionHandlesSegmentsInSceneProvider);
		} else {
			// create segment handles (based on outline)
			return createSingleSelectionHandlePartsForPolygonalOutline(
					target, contextMap,
					selectionHandlesSegmentsInSceneProvider);
		}
	} else {
		throw new IllegalStateException(
				"Unable to generate handles for this handle geometry. Expected ICurve or IShape, but got: "
						+ selectionHandlesGeometry);
	}
}
 
Example 20
Source File: DefaultSelectionHandlePartFactory.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates handle parts for a multi selection.
 *
 * @param targets
 *            The target {@link IVisualPart}s for which handles are to be
 *            created.
 * @param contextMap
 *            A map in which the state-less context {@link IBehavior}) may
 *            place additional context information for the creation process.
 *            It may either directly contain additional information needed
 *            by the {@link IHandlePartFactory}, or may be passed back by
 *            the {@link IHandlePartFactory} to the calling context
 *            {@link IBehavior} to query such kind of information (in which
 *            case it will allow the context {@link IBehavior} to identify
 *            the creation context).
 * @return A list of {@link IHandlePart}s that can be used to manipulate the
 *         given targets.
 */
protected List<IHandlePart<? extends Node>> createMultiSelectionHandleParts(
		final List<? extends IVisualPart<? extends Node>> targets,
		Map<Object, Object> contextMap) {
	// determine handle geometry provider
	@SuppressWarnings("serial")
	Provider<? extends IGeometry> multiSelectionHandlesGeometryInSceneProvider = targets
			.get(0).getRoot().getAdapter(AdapterKey
					.get(new TypeToken<Provider<? extends IGeometry>>() {
					}, MULTI_SELECTION_HANDLES_GEOMETRY_PROVIDER));

	if (multiSelectionHandlesGeometryInSceneProvider == null) {
		// generate default handle geometry provider that unions the
		// ResizableTransformable bounds of all targets
		multiSelectionHandlesGeometryInSceneProvider = new Provider<IGeometry>() {
			@Override
			public IGeometry get() {
				Rectangle bounds = null;
				for (IVisualPart<? extends Node> part : targets) {
					ResizableTransformableBoundsProvider boundsProvider = new ResizableTransformableBoundsProvider();
					boundsProvider.setAdaptable(part);
					IGeometry boundsInLocal = boundsProvider.get();
					// transform to scene
					if (boundsInLocal != null) {
						Rectangle boundsInScene = FX2Geometry
								.toRectangle(part.getVisual()
										.localToScene(Geometry2FX
												.toFXBounds(boundsInLocal
														.getBounds())));
						if (bounds == null) {
							bounds = boundsInScene;
						} else {
							bounds.union(boundsInScene);
						}
					}
				}
				return bounds;
			}
		};
	}

	// per default, handle parts are created for the 4 corners of the
	// multi selection bounds
	Provider<BezierCurve[]> segmentsProvider = createSegmentsProvider(
			multiSelectionHandlesGeometryInSceneProvider);

	// check if provider is OK
	int segments = segmentsProvider.get().length;
	if (segments != 0 && segments != 4) {
		throw new IllegalStateException(
				"The multi selection handle geometry provider is expected to return bounds around the selection. However, instead of 4 segments, the provider provides "
						+ segments + " segments.");
	}

	// create a handle for each start point of the segments
	List<IHandlePart<? extends Node>> handleParts = new ArrayList<>();
	for (int i = 0; i < segments; i++) {
		SquareSegmentHandlePart part = injector
				.getInstance(SquareSegmentHandlePart.class);
		part.setSegmentsProvider(segmentsProvider);
		part.setSegmentIndex(i);
		part.setSegmentParameter(0);
		handleParts.add(part);
	}
	return handleParts;
}