Ejemplo n.º 1
0
 @Override
 public Point newLocation() {
   Preconditions.checkNotNull(wish);
   // [stas] just for fun
   return new Point(
       natural()
           .sortedCopy(
               ImmutableList.of(
                   wish.getX(),
                   0,
                   sizeRetriever.windowSize().getWidth()
                       - sizeRetriever.getComponentsSize().getWidth()))
           .get(1),
       Ordering.natural()
           .sortedCopy(
               Arrays.asList(
                   natural()
                           .min(
                               Lists.asList(
                                   sizeRetriever.windowSize().getHeight()
                                       - sizeRetriever.getMaxElementSize().getHeight(),
                                   Collections2.transform(
                                           lowest,
                                           new Function<Point, Integer>() {
                                             @Override
                                             public Integer apply(Point input) {
                                               return input.getY();
                                             }
                                           })
                                       .toArray(new Integer[] {})))
                       - (lowest.isEmpty() ? 0 : sizeRetriever.getMaxElementSize().getHeight()),
                   natural()
                           .max(
                               Lists.asList(
                                   Point.HIGHEST.getY(),
                                   Collections2.transform(
                                           highest,
                                           new Function<Point, Integer>() {
                                             @Override
                                             public Integer apply(Point input) {
                                               return input.getY();
                                             }
                                           })
                                       .toArray(new Integer[] {})))
                       + (highest.isEmpty() ? 0 : sizeRetriever.getMaxElementSize().getHeight()),
                   wish.getY()))
           .get(1));
 }
Ejemplo n.º 2
0
  /**
   * Returns a new {@code PermissionCache} initialized with permission assignments from the {@code
   * hbase.superuser} configuration key.
   */
  private PermissionCache<Permission> initGlobal(Configuration conf) throws IOException {
    UserProvider userProvider = UserProvider.instantiate(conf);
    User user = userProvider.getCurrent();
    if (user == null) {
      throw new IOException(
          "Unable to obtain the current user, "
              + "authorization checks for internal operations will not work correctly!");
    }
    PermissionCache<Permission> newCache = new PermissionCache<Permission>();
    String currentUser = user.getShortName();

    // the system user is always included
    List<String> superusers =
        Lists.asList(
            currentUser, conf.getStrings(AccessControlLists.SUPERUSER_CONF_KEY, new String[0]));
    if (superusers != null) {
      for (String name : superusers) {
        if (AccessControlLists.isGroupPrincipal(name)) {
          newCache.putGroup(
              AccessControlLists.getGroupName(name), new Permission(Permission.Action.values()));
        } else {
          newCache.putUser(name, new Permission(Permission.Action.values()));
        }
      }
    }
    return newCache;
  }
  @Test
  public void shouldMapListElements() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .field("nameParts[0]", "firstName")
        .field("nameParts[1]", "lastName")
        .register();

    BasicPerson bp = new BasicPerson();
    bp.setNameParts(Lists.asList("Jan", new String[] {"Kowalski"}));

    // when
    MapperFacade mapperFacade = mapperFactory.getMapperFacade();
    BasicPersonDto result = mapperFacade.map(bp, BasicPersonDto.class);

    // then
    assertThat(result.getFirstName()).isEqualTo("Jan");
    assertThat(result.getLastName()).isEqualTo("Kowalski");
    assertThat(result.getBirthDate()).isNull();
    assertThat(result.getCurrentAge()).isEqualTo(0);
    assertThat(result.getFullName()).isNull();
  }
Ejemplo n.º 4
0
 public static void add(Binder binder, Class<?> first, Class<?>... rest) {
   binder = binder.skipSources(DynamicFinders.class);
   for (Class<?> type : Lists.asList(first, rest)) {
     checkTypeAndAnnotations(binder, type);
     bind(binder, type);
   }
 }
Ejemplo n.º 5
0
 @Override
 public List<PartitionInfo> getPartitionInfo() {
   return Lists.asList(
           inMemoryDatabase, partitionedDatabase.getPartitions().toArray(new Database[] {}))
       .stream()
       .map(DatabaseManager::toPartitionInfo)
       .collect(Collectors.toList());
 }
Ejemplo n.º 6
0
 /**
  * Sets the roots for the file system.
  *
  * @throws InvalidPathException if any of the given roots is not a valid path for this builder's
  *     path type
  * @throws IllegalArgumentException if any of the given roots is a valid path for this builder's
  *     path type but is not a root path with no name elements
  */
 public Builder setRoots(String first, String... more) {
   List<String> roots = Lists.asList(first, more);
   for (String root : roots) {
     PathType.ParseResult parseResult = pathType.parsePath(root);
     checkArgument(parseResult.isRoot(), "invalid root: %s", root);
   }
   this.roots = ImmutableSet.copyOf(roots);
   return this;
 }
Ejemplo n.º 7
0
 private final String extractOperationName(final MappingHttpRequest httpRequest) {
   if (httpRequest.getParameters().containsKey(this.operationParam.toString())) {
     return httpRequest.getParameters().get(this.operationParam.toString());
   } else {
     for (final T param : this.altOperationParams) {
       if (httpRequest.getParameters().containsKey(param.toString())) {
         return httpRequest.getParameters().get(this.operationParam.toString());
       }
     }
   }
   LOG.error(
       "Failed to find operation parameter an "
           + Lists.asList(this.operationParam, this.altOperationParams.toArray()).toString()
           + " in HTTP request: "
           + httpRequest);
   return null;
 }
  @Test
  public void shouldCustomizeMapping() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .field("age", "currentAge")
        .byDefault()
        .customize(
            new CustomMapper<BasicPerson, BasicPersonDto>() {
              @Override
              public void mapAtoB(
                  BasicPerson basicPerson, BasicPersonDto basicPersonDto, MappingContext context) {
                Joiner joiner = Joiner.on(" ");
                String fullName =
                    joiner
                        .appendTo(
                            new StringBuilder(basicPerson.getName()).append(" "),
                            basicPerson.getNameParts())
                        .toString();

                basicPersonDto.setFullName(fullName);
              }
            })
        .register();

    BasicPerson bp = createBasicPerson("Jan", 20, Calendar.getInstance().getTime());
    bp.setNameParts(Lists.asList("von", new String[] {"Kowalski"}));

    // when
    MapperFacade mapperFacade = mapperFactory.getMapperFacade();
    BasicPersonDto result = mapperFacade.map(bp, BasicPersonDto.class);

    // then
    assertThat(result.getFullName()).isEqualTo("Jan von Kowalski");
    assertThat(result.getCurrentAge()).isEqualTo(bp.getAge());
    assertThat(result.getBirthDate()).isNotNull();
  }
Ejemplo n.º 9
0
  /**
   * Runs {@code adb} using the given arguments and under the configuration values passed to the
   * constructor.
   *
   * @param arguments the arguments to pass to the {@code adb} utility
   * @return a {@code Process} object representing the {@code adb} process
   */
  protected Process runAdb(String... arguments) {
    List<String> commandLine = Lists.asList(adbPath, arguments);
    ProcessBuilder processBuilder = newProcessBuilder(commandLine);

    // If ports are initialized add them to the environment.
    Map<String, String> environment = processBuilder.environment();

    if (adbServerPort != null) {
      environment.put("ANDROID_ADB_SERVER_PORT", adbServerPort.toString());
    }
    if (emulatorConsolePort != null) {
      environment.put("ANDROID_EMULATOR_CONSOLE_PORT", emulatorConsolePort.toString());
    }
    if (emulatorAdbPort != null) {
      environment.put("ANDROID_EMULATOR_ADB_PORT", emulatorAdbPort.toString());
    }

    try {
      return callProcessBuilderStart(processBuilder);
    } catch (IOException exception) {
      throw new AdbException("An IOException occurred when starting ADB.", exception);
    }
  }
 @Override
 public List<Integer> getVariablePositions() {
   return Lists.asList(sourceLocation, targetLocation, new Integer[0]);
 }
Ejemplo n.º 11
0
 /**
  * Sets the attribute views the file system should support. By default, the following views may
  * be specified:
  *
  * <table>
  *   <tr>
  *     <td><b>Name</b></td>
  *     <td><b>View Interface</b></td>
  *     <td><b>Attributes Interface</b></td>
  *   </tr>
  *   <tr>
  *     <td>{@code "basic"}</td>
  *     <td>{@link java.nio.file.attribute.BasicFileAttributeView BasicFileAttributeView}</td>
  *     <td>{@link java.nio.file.attribute.BasicFileAttributes BasicFileAttributes}</td>
  *   </tr>
  *   <tr>
  *     <td>{@code "owner"}</td>
  *     <td>{@link java.nio.file.attribute.FileOwnerAttributeView FileOwnerAttributeView}</td>
  *     <td>--</td>
  *   </tr>
  *   <tr>
  *     <td>{@code "posix"}</td>
  *     <td>{@link java.nio.file.attribute.PosixFileAttributeView PosixFileAttributeView}</td>
  *     <td>{@link java.nio.file.attribute.PosixFileAttributes PosixFileAttributes}</td>
  *   </tr>
  *   <tr>
  *     <td>{@code "unix"}</td>
  *     <td>--</td>
  *     <td>--</td>
  *   </tr>
  *   <tr>
  *     <td>{@code "dos"}</td>
  *     <td>{@link java.nio.file.attribute.DosFileAttributeView DosFileAttributeView}</td>
  *     <td>{@link java.nio.file.attribute.DosFileAttributes DosFileAttributes}</td>
  *   </tr>
  *   <tr>
  *     <td>{@code "acl"}</td>
  *     <td>{@link java.nio.file.attribute.AclFileAttributeView AclFileAttributeView}</td>
  *     <td>--</td>
  *   </tr>
  *   <tr>
  *     <td>{@code "user"}</td>
  *     <td>{@link java.nio.file.attribute.UserDefinedFileAttributeView UserDefinedFileAttributeView}</td>
  *     <td>--</td>
  *   </tr>
  * </table>
  *
  * <p>If any other views should be supported, attribute providers for those views must be
  * {@linkplain #addAttributeProvider(AttributeProvider) added}.
  */
 public Builder setAttributeViews(String first, String... more) {
   this.attributeViews = ImmutableSet.copyOf(Lists.asList(first, more));
   return this;
 }
Ejemplo n.º 12
0
 /**
  * Returns the normalizations that will be applied to the canonical form of filenames in the
  * file system. The canonical form is used to determine the equality of two filenames when
  * performing a file lookup.
  */
 public Builder setNameCanonicalNormalization(
     PathNormalization first, PathNormalization... more) {
   this.nameCanonicalNormalization = checkNormalizations(Lists.asList(first, more));
   return this;
 }
Ejemplo n.º 13
0
 public static QualifiedName of(String first, String... rest) {
   requireNonNull(first, "first is null");
   return new QualifiedName(ImmutableList.copyOf(Lists.asList(first, rest)));
 }
Ejemplo n.º 14
0
 public void insert(DbSession session, SnapshotDto item, SnapshotDto... others) {
   insert(session, Lists.asList(item, others));
 }
Ejemplo n.º 15
0
 public void insert(DbSession session, MeasureDto item, MeasureDto... others) {
   insert(session, Lists.asList(item, others));
 }
Ejemplo n.º 16
0
 /**
  * Creates parsing expression - "exclusive till". Equivalent of expression {@code
  * zeroOrMore(nextNot(firstOf(e, rest)), anyToken())}. Do not overuse this method.
  *
  * @param e1 first sub-expression
  * @param rest rest of sub-expressions
  * @throws IllegalArgumentException if any of given arguments is not a parsing expression
  */
 public Object exclusiveTill(Object e1, Object... rest) {
   return exclusiveTill(new FirstOfExpression(convertToExpressions(Lists.asList(e1, rest))));
 }
Ejemplo n.º 17
0
 /**
  * Generates the URI from the base server URI plus any extra path elements as specified.
  *
  * @param request The HTTP servlet request
  * @param pathElems The path elements
  * @return The generated URI
  */
 public static String generateCallbackUri(HttpServletRequest request, String... pathElems) {
   Iterable<String> parts = Lists.asList(getBaseUriFromRequest(request), pathElems);
   return Joiner.on('/').join(parts);
 }